mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: set up locales
This commit is contained in:
1 parent
3bbc083b2a
commit
60ab845326
7 files changed
+28
-14
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import { Locale } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import { SUPPORTED_LOCALES } from '../localization/strings/constants';
|
import { SUPPORTED_DISCORD_LOCALES } from '../localization/strings/constants';
|
||||||
import { translator } from '../localization/translator';
|
import { translator } from '../localization/translator';
|
||||||
|
|
||||||
const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
|
const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
|
||||||
@@ -9,7 +9,7 @@ export function localizationObject(
|
|||||||
literals?: string[],
|
literals?: string[],
|
||||||
strict = false,
|
strict = false,
|
||||||
) {
|
) {
|
||||||
return SUPPORTED_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
return SUPPORTED_DISCORD_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
||||||
(localizations, locale) => {
|
(localizations, locale) => {
|
||||||
const { translate } = translator(locale);
|
const { translate } = translator(locale);
|
||||||
const translation = translate(path, literals);
|
const translation = translate(path, literals);
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
|
import { LOCALE_FILES } from '@blitzkit/core';
|
||||||
import { Locale } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
|
|
||||||
export const SUPPORTED_LOCALES: Locale[] = [
|
export const SUPPORTED_DISCORD_LOCALES = Object.values(
|
||||||
Locale.EnglishUS,
|
LOCALE_FILES,
|
||||||
Locale.SpanishES,
|
) as Locale[];
|
||||||
Locale.Croatian,
|
|
||||||
Locale.Russian,
|
|
||||||
Locale.Ukrainian,
|
|
||||||
Locale.ChineseCN,
|
|
||||||
];
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Locale } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import { SUPPORTED_LOCALES } from './constants';
|
import { SUPPORTED_DISCORD_LOCALES } from './constants';
|
||||||
|
|
||||||
export type TranslationFragmentTree = {
|
export type TranslationFragmentTree = {
|
||||||
[key: string]: TranslationFragment;
|
[key: string]: TranslationFragment;
|
||||||
@@ -8,7 +8,7 @@ export type TranslationFragmentTree = {
|
|||||||
};
|
};
|
||||||
export type TranslationFragment = string | TranslationFragmentTree;
|
export type TranslationFragment = string | TranslationFragmentTree;
|
||||||
|
|
||||||
export const translations = SUPPORTED_LOCALES.reduce<
|
export const translations = SUPPORTED_DISCORD_LOCALES.reduce<
|
||||||
Partial<Record<Locale, TranslationFragment>>
|
Partial<Record<Locale, TranslationFragment>>
|
||||||
>(
|
>(
|
||||||
(table, locale) => ({
|
(table, locale) => ({
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { Locale } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import { translations } from './strings';
|
import { translations } from './strings';
|
||||||
import { SUPPORTED_LOCALES } from './strings/constants';
|
import { SUPPORTED_DISCORD_LOCALES } from './strings/constants';
|
||||||
|
|
||||||
export function translator(localeRaw: Locale) {
|
export function translator(localeRaw: Locale) {
|
||||||
const locale =
|
const locale =
|
||||||
localeRaw !== Locale.EnglishUS && SUPPORTED_LOCALES.includes(localeRaw)
|
localeRaw !== Locale.EnglishUS &&
|
||||||
|
SUPPORTED_DISCORD_LOCALES.includes(localeRaw)
|
||||||
? localeRaw
|
? localeRaw
|
||||||
: Locale.EnglishUS;
|
: Locale.EnglishUS;
|
||||||
const strings = translations[locale]!;
|
const strings = translations[locale]!;
|
||||||
|
|||||||
@@ -46,4 +46,5 @@ export * from './votes';
|
|||||||
export * from './createDefaultProvisions';
|
export * from './createDefaultProvisions';
|
||||||
export * from './metaSortTank';
|
export * from './metaSortTank';
|
||||||
export * from './romanize';
|
export * from './romanize';
|
||||||
|
export * from './supportedLocales';
|
||||||
export * from './youtubers';
|
export * from './youtubers';
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export const SUPPORTED_LOCALES = ['en', 'es', 'hr', 'ru', 'uk', 'cn'];
|
||||||
|
export const LOCALE_FILES: Record<(typeof SUPPORTED_LOCALES)[number], string> =
|
||||||
|
{
|
||||||
|
en: 'en-US',
|
||||||
|
es: 'es-ES',
|
||||||
|
hr: 'hr',
|
||||||
|
ru: 'ru',
|
||||||
|
uk: 'uk',
|
||||||
|
cn: 'zh-CN',
|
||||||
|
};
|
||||||
@@ -2,9 +2,15 @@
|
|||||||
|
|
||||||
import react from '@astrojs/react';
|
import react from '@astrojs/react';
|
||||||
import sitemap from '@astrojs/sitemap';
|
import sitemap from '@astrojs/sitemap';
|
||||||
|
import { SUPPORTED_LOCALES } from '@blitzkit/core';
|
||||||
import { defineConfig } from 'astro/config';
|
import { defineConfig } from 'astro/config';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
i18n: {
|
||||||
|
defaultLocale: 'en',
|
||||||
|
locales: SUPPORTED_LOCALES,
|
||||||
|
},
|
||||||
|
|
||||||
devToolbar: { enabled: false },
|
devToolbar: { enabled: false },
|
||||||
output: 'static',
|
output: 'static',
|
||||||
site: 'https://blitzkit.app',
|
site: 'https://blitzkit.app',
|
||||||
|
|||||||
Reference in new issue
Block a user