pokerogue/src/plugins/i18n.ts

162 lines
4.4 KiB
TypeScript
Raw Normal View History

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';
export interface SimpleTranslationEntries {
[key: string]: string
}
2024-04-18 13:40:42 +01:00
export interface MoveTranslationEntry {
name: string,
effect: string
}
export interface MoveTranslationEntries {
2024-04-18 13:40:42 +01:00
[key: string]: MoveTranslationEntry
}
export interface AbilityTranslationEntry {
name: string,
description: string
}
export interface AbilityTranslationEntries {
[key: string]: AbilityTranslationEntry
}
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,
}
export interface BerryTranslationEntry {
name: string,
effect: string
}
export interface BerryTranslationEntries {
[key: string]: BerryTranslationEntry
}
export interface Localizable {
localize(): void;
}
export function initI18n(): void {
Issue #745 localized trainer names trainer classes and titles (#752) * Issue #745 - Added the option to localize titles, trainer names (for important trainers like elite 4, champs etc) and trainer classes. - Also i already did the whole localization for german (sorry thats the only language is speak other then english...) - Also renamed the trainer Type "student" to school_kid (because there apparently really is a trainer class called student since the gen 9 dlc) - And i changed it so it makes sure that i18 only gets initalized once (it may be needed to initalize it before the loading phase so the elite 4 titles etc can be localized) * Issue #745 - Removed stuff that wasnt meant for this branch * Translation of French trainers.ts * Translation of French trainers.ts * Translation of French trainers.ts * Fixed spelling on german translation * Fixed name of Hex Maniac * ADded missing "," that were lost in the merge * For Trainer Classes that have a female and male variant the correct name is now choosen. (If a language has both). Also added a safety net that if the female version does not exist it uses the one without the suffix * Reverting override.ts * Added ptBR trainers.ts (thanks to zé ricardo on discord) * Updates Pokefan to reflect the correct english spelling (in all languages that still have the english defaults) * Updated Rich_kid trainer typ to named correctly as "Rich Boy" in english and all non yet localized languages * Added that the title will get made lower case so the rival is correctly set * Reverted a formatting change that i didnt make intentionally --------- Co-authored-by: Lugiad <adrien.grivel@hotmail.fr>
2024-05-16 10:05:25 +01:00
// Prevent reinitialization
if (isInitialized) {
return;
}
isInitialized = true;
let lang = '';
if (localStorage.getItem('prLang'))
lang = localStorage.getItem('prLang');
Issue #745 localized trainer names trainer classes and titles (#752) * Issue #745 - Added the option to localize titles, trainer names (for important trainers like elite 4, champs etc) and trainer classes. - Also i already did the whole localization for german (sorry thats the only language is speak other then english...) - Also renamed the trainer Type "student" to school_kid (because there apparently really is a trainer class called student since the gen 9 dlc) - And i changed it so it makes sure that i18 only gets initalized once (it may be needed to initalize it before the loading phase so the elite 4 titles etc can be localized) * Issue #745 - Removed stuff that wasnt meant for this branch * Translation of French trainers.ts * Translation of French trainers.ts * Translation of French trainers.ts * Fixed spelling on german translation * Fixed name of Hex Maniac * ADded missing "," that were lost in the merge * For Trainer Classes that have a female and male variant the correct name is now choosen. (If a language has both). Also added a safety net that if the female version does not exist it uses the one without the suffix * Reverting override.ts * Added ptBR trainers.ts (thanks to zé ricardo on discord) * Updates Pokefan to reflect the correct english spelling (in all languages that still have the english defaults) * Updated Rich_kid trainer typ to named correctly as "Rich Boy" in english and all non yet localized languages * Added that the title will get made lower case so the rival is correctly set * Reverted a formatting change that i didnt make intentionally --------- Co-authored-by: Lugiad <adrien.grivel@hotmail.fr>
2024-05-16 10:05:25 +01:00
/**
* i18next is a localization library for maintaining and using translation resources.
*
* 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.
* Don't forget to declare new language in `supportedLngs` i18next initializer
*
* 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.
*
* 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.
*/
i18next.use(LanguageDetector).init({
lng: lang,
fallbackLng: 'en',
supportedLngs: ['en', 'es', 'fr', 'it', 'de', 'zh_CN','pt_BR'],
debug: true,
interpolation: {
escapeValue: false,
},
resources: {
en: {
...enConfig
},
es: {
...esConfig
},
fr: {
...frConfig
},
it: {
...itConfig
},
de: {
...deConfig
},
pt_BR: {
...ptBrConfig
},
zh_CN: {
...zhCnConfig
}
},
});
}
// Module declared to make referencing keys in the localization files type-safe.
declare module 'i18next' {
interface CustomTypeOptions {
resources: {
menu: SimpleTranslationEntries;
menuUiHandler: SimpleTranslationEntries;
move: MoveTranslationEntries;
battle: SimpleTranslationEntries;
abilityTriggers: SimpleTranslationEntries;
ability: AbilityTranslationEntries;
pokeball: SimpleTranslationEntries;
pokemon: SimpleTranslationEntries;
pokemonStat: SimpleTranslationEntries;
commandUiHandler: SimpleTranslationEntries;
fightUiHandler: SimpleTranslationEntries;
Issue #745 localized trainer names trainer classes and titles (#752) * Issue #745 - Added the option to localize titles, trainer names (for important trainers like elite 4, champs etc) and trainer classes. - Also i already did the whole localization for german (sorry thats the only language is speak other then english...) - Also renamed the trainer Type "student" to school_kid (because there apparently really is a trainer class called student since the gen 9 dlc) - And i changed it so it makes sure that i18 only gets initalized once (it may be needed to initalize it before the loading phase so the elite 4 titles etc can be localized) * Issue #745 - Removed stuff that wasnt meant for this branch * Translation of French trainers.ts * Translation of French trainers.ts * Translation of French trainers.ts * Fixed spelling on german translation * Fixed name of Hex Maniac * ADded missing "," that were lost in the merge * For Trainer Classes that have a female and male variant the correct name is now choosen. (If a language has both). Also added a safety net that if the female version does not exist it uses the one without the suffix * Reverting override.ts * Added ptBR trainers.ts (thanks to zé ricardo on discord) * Updates Pokefan to reflect the correct english spelling (in all languages that still have the english defaults) * Updated Rich_kid trainer typ to named correctly as "Rich Boy" in english and all non yet localized languages * Added that the title will get made lower case so the rival is correctly set * Reverted a formatting change that i didnt make intentionally --------- Co-authored-by: Lugiad <adrien.grivel@hotmail.fr>
2024-05-16 10:05:25 +01:00
titles: SimpleTranslationEntries;
trainerClasses: SimpleTranslationEntries;
trainerNames: SimpleTranslationEntries;
tutorial: SimpleTranslationEntries;
starterSelectUiHandler: SimpleTranslationEntries;
splashMessages: SimpleTranslationEntries;
nature: SimpleTranslationEntries;
growth: SimpleTranslationEntries;
egg: SimpleTranslationEntries;
weather: SimpleTranslationEntries;
modifierType: ModifierTypeTranslationEntries;
berry: BerryTranslationEntries;
};
}
}
export default i18next;
Issue #745 localized trainer names trainer classes and titles (#752) * Issue #745 - Added the option to localize titles, trainer names (for important trainers like elite 4, champs etc) and trainer classes. - Also i already did the whole localization for german (sorry thats the only language is speak other then english...) - Also renamed the trainer Type "student" to school_kid (because there apparently really is a trainer class called student since the gen 9 dlc) - And i changed it so it makes sure that i18 only gets initalized once (it may be needed to initalize it before the loading phase so the elite 4 titles etc can be localized) * Issue #745 - Removed stuff that wasnt meant for this branch * Translation of French trainers.ts * Translation of French trainers.ts * Translation of French trainers.ts * Fixed spelling on german translation * Fixed name of Hex Maniac * ADded missing "," that were lost in the merge * For Trainer Classes that have a female and male variant the correct name is now choosen. (If a language has both). Also added a safety net that if the female version does not exist it uses the one without the suffix * Reverting override.ts * Added ptBR trainers.ts (thanks to zé ricardo on discord) * Updates Pokefan to reflect the correct english spelling (in all languages that still have the english defaults) * Updated Rich_kid trainer typ to named correctly as "Rich Boy" in english and all non yet localized languages * Added that the title will get made lower case so the rival is correctly set * Reverted a formatting change that i didnt make intentionally --------- Co-authored-by: Lugiad <adrien.grivel@hotmail.fr>
2024-05-16 10:05:25 +01:00
export function getIsInitialized(): boolean {
return isInitialized;
}
let isInitialized = false;