2024-04-12 04:47:03 +01:00
|
|
|
import i18next from 'i18next';
|
2024-04-30 16:07:15 +01:00
|
|
|
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
|
|
|
2024-05-06 19:25:17 +01:00
|
|
|
import { deConfig } from '#app/locales/de/config.js';
|
|
|
|
import { enConfig } from '#app/locales/en/config.js';
|
|
|
|
import { esConfig } from '#app/locales/es/config.js';
|
|
|
|
import { frConfig } from '#app/locales/fr/config.js';
|
|
|
|
import { itConfig } from '#app/locales/it/config.js';
|
2024-05-13 17:18:24 +01:00
|
|
|
import { ptBrConfig } from '#app/locales/pt_BR/config.js';
|
2024-05-09 05:11:04 +01:00
|
|
|
import { zhCnConfig } from '#app/locales/zh_CN/config.js';
|
2024-05-06 17:02:45 +01:00
|
|
|
|
2024-04-22 00:53:24 +01:00
|
|
|
export interface SimpleTranslationEntries {
|
|
|
|
[key: string]: string
|
|
|
|
}
|
|
|
|
|
2024-04-18 13:40:42 +01:00
|
|
|
export interface MoveTranslationEntry {
|
|
|
|
name: string,
|
|
|
|
effect: string
|
|
|
|
}
|
|
|
|
|
2024-04-22 00:53:24 +01:00
|
|
|
export interface MoveTranslationEntries {
|
2024-04-18 13:40:42 +01:00
|
|
|
[key: string]: MoveTranslationEntry
|
|
|
|
}
|
|
|
|
|
2024-04-25 02:10:09 +01:00
|
|
|
export interface AbilityTranslationEntry {
|
|
|
|
name: string,
|
|
|
|
description: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AbilityTranslationEntries {
|
|
|
|
[key: string]: AbilityTranslationEntry
|
|
|
|
}
|
|
|
|
|
2024-05-16 05:32:45 +01:00
|
|
|
export interface ModifierTypeTranslationEntry {
|
|
|
|
name?: string,
|
|
|
|
description?: string,
|
|
|
|
extra?: SimpleTranslationEntries
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ModifierTypeTranslationEntries {
|
|
|
|
ModifierType: { [key: string]: ModifierTypeTranslationEntry },
|
|
|
|
AttackTypeBoosterItem: SimpleTranslationEntries,
|
|
|
|
TempBattleStatBoosterItem: SimpleTranslationEntries,
|
|
|
|
BaseStatBoosterItem: SimpleTranslationEntries,
|
|
|
|
EvolutionItem: SimpleTranslationEntries,
|
|
|
|
FormChangeItem: SimpleTranslationEntries,
|
|
|
|
TeraType: SimpleTranslationEntries,
|
|
|
|
}
|
|
|
|
|
2024-04-19 19:55:01 +01:00
|
|
|
export interface Localizable {
|
|
|
|
localize(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initI18n(): void {
|
2024-04-30 16:07:15 +01:00
|
|
|
let lang = '';
|
2024-04-19 19:55:01 +01:00
|
|
|
|
|
|
|
if (localStorage.getItem('prLang'))
|
|
|
|
lang = localStorage.getItem('prLang');
|
2024-04-12 04:47:03 +01:00
|
|
|
|
2024-04-19 19:55:01 +01:00
|
|
|
/**
|
|
|
|
* i18next is a localization library for maintaining and using translation resources.
|
2024-04-25 23:54:56 +01:00
|
|
|
*
|
2024-04-19 19:55:01 +01:00
|
|
|
* Q: How do I add a new language?
|
|
|
|
* A: To add a new language, create a new folder in the locales directory with the language code.
|
|
|
|
* Each language folder should contain a file for each namespace (ex. menu.ts) with the translations.
|
2024-04-30 16:07:15 +01:00
|
|
|
* Don't forget to declare new language in `supportedLngs` i18next initializer
|
2024-04-25 23:54:56 +01:00
|
|
|
*
|
2024-04-19 19:55:01 +01:00
|
|
|
* Q: How do I add a new namespace?
|
|
|
|
* A: To add a new namespace, create a new file in each language folder with the translations.
|
|
|
|
* Then update the `resources` field in the init() call and the CustomTypeOptions interface.
|
2024-04-30 16:07:15 +01:00
|
|
|
*
|
2024-04-25 22:24:53 +01:00
|
|
|
* Q: How do I make a language selectable in the settings?
|
|
|
|
* A: In src/system/settings.ts, add a new case to the Setting.Language switch statement.
|
2024-04-19 19:55:01 +01:00
|
|
|
*/
|
|
|
|
|
2024-04-30 16:07:15 +01:00
|
|
|
i18next.use(LanguageDetector).init({
|
|
|
|
lng: lang,
|
2024-04-19 19:55:01 +01:00
|
|
|
fallbackLng: 'en',
|
2024-05-13 17:18:24 +01:00
|
|
|
supportedLngs: ['en', 'es', 'fr', 'it', 'de', 'zh_CN','pt_BR'],
|
2024-04-19 19:55:01 +01:00
|
|
|
debug: true,
|
|
|
|
interpolation: {
|
|
|
|
escapeValue: false,
|
2024-04-12 04:47:03 +01:00
|
|
|
},
|
2024-04-19 19:55:01 +01:00
|
|
|
resources: {
|
|
|
|
en: {
|
2024-05-06 19:25:17 +01:00
|
|
|
...enConfig
|
2024-04-19 19:55:01 +01:00
|
|
|
},
|
2024-04-23 16:53:56 +01:00
|
|
|
es: {
|
2024-05-06 19:25:17 +01:00
|
|
|
...esConfig
|
2024-04-19 19:55:01 +01:00
|
|
|
},
|
|
|
|
fr: {
|
2024-05-06 19:25:17 +01:00
|
|
|
...frConfig
|
2024-04-24 05:36:07 +01:00
|
|
|
},
|
|
|
|
it: {
|
2024-05-06 19:25:17 +01:00
|
|
|
...itConfig
|
2024-04-24 05:36:07 +01:00
|
|
|
},
|
2024-04-25 22:24:53 +01:00
|
|
|
de: {
|
2024-05-06 19:25:17 +01:00
|
|
|
...deConfig
|
2024-05-09 04:59:49 +01:00
|
|
|
},
|
2024-05-13 17:18:24 +01:00
|
|
|
pt_BR: {
|
|
|
|
...ptBrConfig
|
|
|
|
},
|
2024-05-09 05:11:04 +01:00
|
|
|
zh_CN: {
|
|
|
|
...zhCnConfig
|
2024-04-25 22:24:53 +01:00
|
|
|
}
|
2024-04-16 19:29:32 +01:00
|
|
|
},
|
2024-04-19 19:55:01 +01:00
|
|
|
});
|
|
|
|
}
|
2024-04-12 04:47:03 +01:00
|
|
|
|
|
|
|
// Module declared to make referencing keys in the localization files type-safe.
|
|
|
|
declare module 'i18next' {
|
|
|
|
interface CustomTypeOptions {
|
|
|
|
resources: {
|
2024-05-06 19:25:17 +01:00
|
|
|
menu: SimpleTranslationEntries;
|
|
|
|
menuUiHandler: SimpleTranslationEntries;
|
|
|
|
move: MoveTranslationEntries;
|
2024-05-14 00:12:28 +01:00
|
|
|
battle: SimpleTranslationEntries;
|
|
|
|
abilityTriggers: SimpleTranslationEntries;
|
2024-05-06 19:25:17 +01:00
|
|
|
ability: AbilityTranslationEntries;
|
|
|
|
pokeball: SimpleTranslationEntries;
|
|
|
|
pokemon: SimpleTranslationEntries;
|
|
|
|
pokemonStat: SimpleTranslationEntries;
|
|
|
|
commandUiHandler: SimpleTranslationEntries;
|
|
|
|
fightUiHandler: SimpleTranslationEntries;
|
|
|
|
tutorial: SimpleTranslationEntries;
|
|
|
|
starterSelectUiHandler: SimpleTranslationEntries;
|
2024-05-16 09:37:40 +01:00
|
|
|
splashMessages: SimpleTranslationEntries;
|
2024-05-12 03:22:45 +01:00
|
|
|
nature: SimpleTranslationEntries;
|
2024-05-12 03:04:09 +01:00
|
|
|
growth: SimpleTranslationEntries;
|
2024-05-16 09:31:50 +01:00
|
|
|
egg: SimpleTranslationEntries;
|
2024-05-15 18:31:18 +01:00
|
|
|
weather: SimpleTranslationEntries;
|
2024-05-16 05:32:45 +01:00
|
|
|
modifierType: ModifierTypeTranslationEntries;
|
2024-04-12 04:47:03 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default i18next;
|