diff --git a/packages/bot/src/core/discord/localizationObject.ts b/packages/bot/src/core/discord/localizationObject.ts index a89f9cd0a..5faffa7d2 100644 --- a/packages/bot/src/core/discord/localizationObject.ts +++ b/packages/bot/src/core/discord/localizationObject.ts @@ -1,5 +1,5 @@ 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'; const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u; @@ -9,7 +9,7 @@ export function localizationObject( literals?: string[], strict = false, ) { - return SUPPORTED_LOCALES.reduce>>( + return SUPPORTED_DISCORD_LOCALES.reduce>>( (localizations, locale) => { const { translate } = translator(locale); const translation = translate(path, literals); diff --git a/packages/bot/src/core/localization/strings/constants.ts b/packages/bot/src/core/localization/strings/constants.ts index 7b0b977a4..15078968d 100644 --- a/packages/bot/src/core/localization/strings/constants.ts +++ b/packages/bot/src/core/localization/strings/constants.ts @@ -1,10 +1,6 @@ +import { LOCALE_FILES } from '@blitzkit/core'; import { Locale } from 'discord.js'; -export const SUPPORTED_LOCALES: Locale[] = [ - Locale.EnglishUS, - Locale.SpanishES, - Locale.Croatian, - Locale.Russian, - Locale.Ukrainian, - Locale.ChineseCN, -]; +export const SUPPORTED_DISCORD_LOCALES = Object.values( + LOCALE_FILES, +) as Locale[]; diff --git a/packages/bot/src/core/localization/strings/index.ts b/packages/bot/src/core/localization/strings/index.ts index 133f3a5ca..c47c97d59 100644 --- a/packages/bot/src/core/localization/strings/index.ts +++ b/packages/bot/src/core/localization/strings/index.ts @@ -1,5 +1,5 @@ import { Locale } from 'discord.js'; -import { SUPPORTED_LOCALES } from './constants'; +import { SUPPORTED_DISCORD_LOCALES } from './constants'; export type TranslationFragmentTree = { [key: string]: TranslationFragment; @@ -8,7 +8,7 @@ export type TranslationFragmentTree = { }; export type TranslationFragment = string | TranslationFragmentTree; -export const translations = SUPPORTED_LOCALES.reduce< +export const translations = SUPPORTED_DISCORD_LOCALES.reduce< Partial> >( (table, locale) => ({ diff --git a/packages/bot/src/core/localization/translator.ts b/packages/bot/src/core/localization/translator.ts index 2428b75b2..d6099197e 100644 --- a/packages/bot/src/core/localization/translator.ts +++ b/packages/bot/src/core/localization/translator.ts @@ -1,10 +1,11 @@ import { Locale } from 'discord.js'; import { translations } from './strings'; -import { SUPPORTED_LOCALES } from './strings/constants'; +import { SUPPORTED_DISCORD_LOCALES } from './strings/constants'; export function translator(localeRaw: Locale) { const locale = - localeRaw !== Locale.EnglishUS && SUPPORTED_LOCALES.includes(localeRaw) + localeRaw !== Locale.EnglishUS && + SUPPORTED_DISCORD_LOCALES.includes(localeRaw) ? localeRaw : Locale.EnglishUS; const strings = translations[locale]!; diff --git a/packages/core/src/blitzkit/index.ts b/packages/core/src/blitzkit/index.ts index 983def4d7..3f3cf0daa 100644 --- a/packages/core/src/blitzkit/index.ts +++ b/packages/core/src/blitzkit/index.ts @@ -46,4 +46,5 @@ export * from './votes'; export * from './createDefaultProvisions'; export * from './metaSortTank'; export * from './romanize'; +export * from './supportedLocales'; export * from './youtubers'; diff --git a/packages/core/src/blitzkit/supportedLocales.ts b/packages/core/src/blitzkit/supportedLocales.ts new file mode 100644 index 000000000..457066ffe --- /dev/null +++ b/packages/core/src/blitzkit/supportedLocales.ts @@ -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', + }; diff --git a/packages/website/astro.config.mjs b/packages/website/astro.config.mjs index 31cecc7e0..5536116ff 100644 --- a/packages/website/astro.config.mjs +++ b/packages/website/astro.config.mjs @@ -2,9 +2,15 @@ import react from '@astrojs/react'; import sitemap from '@astrojs/sitemap'; +import { SUPPORTED_LOCALES } from '@blitzkit/core'; import { defineConfig } from 'astro/config'; export default defineConfig({ + i18n: { + defaultLocale: 'en', + locales: SUPPORTED_LOCALES, + }, + devToolbar: { enabled: false }, output: 'static', site: 'https://blitzkit.app',