feat: started implementation of translations

This commit is contained in:
TrèsAbhi committed 2024-03-04 10:33:02 -06:00
1 parent 2ba9f0f4c8
commit ac60a436f1
6 files changed
+75 -118

No files matched your search

+18 -9
View File
@@ -1,6 +1,7 @@
const LANGUAGES = ['en-US', 'es-ES', 'ja-JP'] as const;
import { Locale } from 'discord.js';
const LOCALES: Locale[number][] = ['en-US', 'es-ES'];
export type Language = (typeof LANGUAGES)[number];
export type TranslationFragmentTree = {
[key: string]: TranslationFragment;
} & {
@@ -8,10 +9,18 @@ export type TranslationFragmentTree = {
};
export type TranslationFragment = string | TranslationFragmentTree;
export const translations = LANGUAGES.reduce(
(table, language) => ({
...table,
[language]: import(`../../lang/${language}.json`),
}),
{},
) as Record<Language, Promise<TranslationFragment>>;
export const translations = Promise.all(
LOCALES.map(async (locale) => ({
locale,
translations: await import(`../../lang/${locale}.json`),
})),
).then(
(translations) =>
translations.reduce(
(table, { locale, translations }) => ({
...table,
[locale]: translations,
}),
{},
) as Record<Locale[number], TranslationFragment>,
);