Juan-Lucas 1b1578d266
command-ui: add i18n for command ui handler and add i18n for fr (#258)
* command-ui: add i18n for command ui handler and add i18n for fr

* Add missing Spanish file

* Add additional missing localization references

---------

Co-authored-by: Flashfyre <flashfireex@gmail.com>
2024-04-24 00:36:07 -04:00

111 lines
3.2 KiB
TypeScript

import i18next from 'i18next';
import { menu as enMenu } from '../locales/en/menu';
import { menu as esMenu } from '../locales/es/menu';
import { menu as itMenu } from '../locales/it/menu';
import { menu as frMenu } from '../locales/fr/menu';
import { move as enMove } from '../locales/en/move';
import { move as esMove } from '../locales/es/move';
import { move as frMove } from '../locales/fr/move';
import { pokeball as enPokeball } from '../locales/en/pokeball';
import { pokeball as esPokeball } from '../locales/es/pokeball';
import { pokeball as frPokeball } from '../locales/fr/pokeball';
import { pokemon as enPokemon } from '../locales/en/pokemon';
import { pokemon as esPokemon } from '../locales/es/pokemon';
import { pokemon as frPokemon } from '../locales/fr/pokemon';
import { commandUiHandler as enCommandUiHandler } from '../locales/en/command-ui-handler';
import { commandUiHandler as esCommandUiHandler } from '../locales/es/command-ui-handler';
import { commandUiHandler as frCommandUiHandler } from '../locales/fr/command-ui-handler';
export interface SimpleTranslationEntries {
[key: string]: string
}
export interface MoveTranslationEntry {
name: string,
effect: string
}
export interface MoveTranslationEntries {
[key: string]: MoveTranslationEntry
}
export interface Localizable {
localize(): void;
}
const DEFAULT_LANGUAGE_OVERRIDE = '';
export function initI18n(): void {
let lang = 'en';
if (localStorage.getItem('prLang'))
lang = localStorage.getItem('prLang');
/**
* 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.
*
* 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.
*/
i18next.init({
lng: DEFAULT_LANGUAGE_OVERRIDE ? DEFAULT_LANGUAGE_OVERRIDE : lang,
fallbackLng: 'en',
debug: true,
interpolation: {
escapeValue: false,
},
resources: {
en: {
menu: enMenu,
move: enMove,
pokeball: enPokeball,
pokemon: enPokemon,
commandUiHandler: enCommandUiHandler,
},
es: {
menu: esMenu,
move: esMove,
pokeball: esPokeball,
pokemon: esPokemon,
commandUiHandler: esCommandUiHandler,
},
fr: {
menu: frMenu,
move: frMove,
pokeball: frPokeball,
pokemon: frPokemon,
commandUiHandler: frCommandUiHandler,
},
it: {
menu: itMenu,
},
},
});
}
// Module declared to make referencing keys in the localization files type-safe.
declare module 'i18next' {
interface CustomTypeOptions {
resources: {
menu: typeof enMenu;
move: typeof enMove;
pokeball: typeof enPokeball;
pokemon: typeof enPokemon;
commandUiHandler: typeof enCommandUiHandler;
};
}
}
export default i18next;