mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: started implementation of translations
This commit is contained in:
1 parent
2ba9f0f4c8
commit
ac60a436f1
6 files changed
+75
-118
No files matched your search
@@ -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>,
|
||||
);
|
||||
Reference in new issue
Block a user