2024-05-23 16:03:10 +01:00
|
|
|
import i18next from "i18next";
|
|
|
|
import LanguageDetector from "i18next-browser-languagedetector";
|
|
|
|
|
|
|
|
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";
|
|
|
|
import { ptBrConfig } from "#app/locales/pt_BR/config.js";
|
|
|
|
import { zhCnConfig } from "#app/locales/zh_CN/config.js";
|
|
|
|
import { zhTWConfig } from "#app/locales/zh_TW/config.js";
|
2024-05-23 13:01:22 +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,
|
2024-05-17 15:43:11 +01:00
|
|
|
}
|
|
|
|
export interface PokemonInfoTranslationEntries {
|
|
|
|
Stat: SimpleTranslationEntries,
|
|
|
|
Type: SimpleTranslationEntries,
|
2024-05-16 05:32:45 +01:00
|
|
|
}
|
|
|
|
|
2024-05-17 11:09:08 +01:00
|
|
|
export interface BerryTranslationEntry {
|
|
|
|
name: string,
|
|
|
|
effect: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BerryTranslationEntries {
|
|
|
|
[key: string]: BerryTranslationEntry
|
|
|
|
}
|
|
|
|
|
2024-05-27 12:14:37 +01:00
|
|
|
export interface DialogueTranslationEntry {
|
|
|
|
[key: number]: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DialogueTranslationCategory {
|
|
|
|
encounter: DialogueTranslationEntry;
|
|
|
|
victory: DialogueTranslationEntry;
|
|
|
|
defeat?: DialogueTranslationEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DialogueTranslationTrainerClass {
|
|
|
|
[key: string]: DialogueTranslationCategory;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DialogueTranslationEntries {
|
|
|
|
[key: string]: DialogueTranslationTrainerClass;
|
|
|
|
}
|
|
|
|
|
2024-04-19 19:55:01 +01:00
|
|
|
export interface Localizable {
|
|
|
|
localize(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initI18n(): void {
|
2024-05-16 10:05:25 +01:00
|
|
|
// Prevent reinitialization
|
|
|
|
if (isInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isInitialized = true;
|
2024-05-23 16:03:10 +01:00
|
|
|
let lang = "";
|
2024-04-19 19:55:01 +01:00
|
|
|
|
2024-05-23 16:03:10 +01:00
|
|
|
if (localStorage.getItem("prLang")) {
|
|
|
|
lang = localStorage.getItem("prLang");
|
|
|
|
}
|
2024-04-12 04:47:03 +01:00
|
|
|
|
2024-05-16 10:05:25 +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-05-21 04:26:53 +01:00
|
|
|
nonExplicitSupportedLngs: true,
|
2024-05-23 16:03:10 +01:00
|
|
|
fallbackLng: "en",
|
|
|
|
supportedLngs: ["en", "es", "fr", "it", "de", "zh", "pt"],
|
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-05-24 00:45:04 +01:00
|
|
|
},
|
2024-05-23 13:01:22 +01:00
|
|
|
zh_TW: {
|
|
|
|
...zhTWConfig
|
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.
|
2024-05-23 16:03:10 +01:00
|
|
|
declare module "i18next" {
|
2024-04-12 04:47:03 +01:00
|
|
|
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;
|
2024-05-17 15:43:11 +01:00
|
|
|
pokemonInfo: PokemonInfoTranslationEntries;
|
2024-05-06 19:25:17 +01:00
|
|
|
commandUiHandler: SimpleTranslationEntries;
|
|
|
|
fightUiHandler: SimpleTranslationEntries;
|
2024-05-16 10:05:25 +01:00
|
|
|
titles: SimpleTranslationEntries;
|
|
|
|
trainerClasses: SimpleTranslationEntries;
|
|
|
|
trainerNames: SimpleTranslationEntries;
|
2024-05-06 19:25:17 +01:00
|
|
|
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-05-17 11:21:35 +01:00
|
|
|
battleMessageUiHandler: SimpleTranslationEntries;
|
2024-05-17 11:09:08 +01:00
|
|
|
berry: BerryTranslationEntries;
|
2024-05-27 12:58:20 +01:00
|
|
|
gameStatsUiHandler: SimpleTranslationEntries;
|
|
|
|
voucher: SimpleTranslationEntries;
|
2024-05-25 21:57:22 +01:00
|
|
|
biome: SimpleTranslationEntries;
|
2024-05-27 23:28:53 +01:00
|
|
|
pokemonInfoContainer: SimpleTranslationEntries;
|
2024-05-27 12:14:37 +01:00
|
|
|
PGMdialogue: DialogueTranslationEntries;
|
|
|
|
PGMbattleSpecDialogue: SimpleTranslationEntries;
|
|
|
|
PGMmiscDialogue: SimpleTranslationEntries;
|
|
|
|
PGMdoubleBattleDialogue: DialogueTranslationEntries;
|
|
|
|
PGFdialogue: DialogueTranslationEntries;
|
|
|
|
PGFbattleSpecDialogue: SimpleTranslationEntries;
|
|
|
|
PGFmiscDialogue: SimpleTranslationEntries;
|
|
|
|
PGFdoubleBattleDialogue: DialogueTranslationEntries;
|
2024-04-12 04:47:03 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default i18next;
|
2024-05-16 10:05:25 +01:00
|
|
|
|
|
|
|
export function getIsInitialized(): boolean {
|
|
|
|
return isInitialized;
|
|
|
|
}
|
|
|
|
|
2024-05-17 11:21:35 +01:00
|
|
|
let isInitialized = false;
|