mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-04 15:32:18 +02:00
One object with key/label for languages, i18next
This commit is contained in:
parent
5faf048f25
commit
d75c43218a
@ -79,6 +79,24 @@ async function initFonts(language: string | undefined) {
|
||||
}
|
||||
}
|
||||
|
||||
type LanguageType = {
|
||||
[key:string]: string
|
||||
};
|
||||
|
||||
export const languages: LanguageType = {
|
||||
"en": "English",
|
||||
"es": "Español",
|
||||
"it": "Italiano",
|
||||
"fr": "Français",
|
||||
"de": "Deutsch",
|
||||
"pt-BR": "Português (BR)",
|
||||
"zh-CN": "简体中文",
|
||||
"zh-TW": "繁體中文",
|
||||
"ko": "한국어",
|
||||
"ja": "日本語",
|
||||
// "ca-ES": "Català",
|
||||
};
|
||||
|
||||
export async function initI18n(): Promise<void> {
|
||||
// Prevent reinitialization
|
||||
if (isInitialized) {
|
||||
@ -92,7 +110,7 @@ export async function initI18n(): Promise<void> {
|
||||
* 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
|
||||
* Don't forgot declare new language in `languages` const with language code as key and language label as value.
|
||||
*
|
||||
* 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.
|
||||
@ -109,7 +127,9 @@ export async function initI18n(): Promise<void> {
|
||||
await i18next.init({
|
||||
nonExplicitSupportedLngs: true,
|
||||
fallbackLng: "en",
|
||||
supportedLngs: ["en", "es", "fr", "it", "de", "zh", "pt", "ko", "ja", "ca"],
|
||||
supportedLngs: Object.keys(languages).map((langKey)=>langKey.split("-")[0]).filter((lang,i,a) => {
|
||||
return (a.findIndex((t) => t === lang) === i);
|
||||
}),
|
||||
defaultNS: "menu",
|
||||
ns: Object.keys(enConfig),
|
||||
detection: {
|
||||
|
@ -8,7 +8,7 @@ import SettingsUiHandler from "#app/ui/settings/settings-ui-handler";
|
||||
import { EaseType } from "#enums/ease-type";
|
||||
import { MoneyFormat } from "#enums/money-format";
|
||||
import { PlayerGender } from "#enums/player-gender";
|
||||
import { getIsInitialized, initI18n } from "#app/plugins/i18n.js";
|
||||
import { getIsInitialized, initI18n, languages } from "#app/plugins/i18n.js";
|
||||
|
||||
function getTranslation(key: string): string {
|
||||
if (!getIsInitialized()) {
|
||||
@ -79,66 +79,8 @@ export interface Setting {
|
||||
isHidden?: () => boolean
|
||||
}
|
||||
|
||||
type LanguageType = {
|
||||
key: string;
|
||||
label: string;
|
||||
handler?: () => {};
|
||||
value?: string;
|
||||
};
|
||||
|
||||
const languages: Array<LanguageType> = [
|
||||
{
|
||||
key: "en",
|
||||
label: "English",
|
||||
},
|
||||
{
|
||||
key: "es",
|
||||
label: "Español",
|
||||
},
|
||||
{
|
||||
key: "it",
|
||||
label: "Italiano",
|
||||
},
|
||||
{
|
||||
key: "fr",
|
||||
label: "Français",
|
||||
},
|
||||
{
|
||||
key: "de",
|
||||
label: "Deutsch",
|
||||
},
|
||||
{
|
||||
key: "pt-BR",
|
||||
label: "Português (BR)",
|
||||
},
|
||||
{
|
||||
key: "zh-CN",
|
||||
label: "简体中文",
|
||||
},
|
||||
{
|
||||
key: "zh-TW",
|
||||
label: "繁體中文",
|
||||
},
|
||||
{
|
||||
key: "ko",
|
||||
label: "한국어",
|
||||
},
|
||||
{
|
||||
key: "ko-KR",
|
||||
label: "한국어",
|
||||
},
|
||||
{
|
||||
key: "ja",
|
||||
label: "日本語",
|
||||
},
|
||||
// {
|
||||
// key:"ca-ES",
|
||||
// label: "Català",
|
||||
// },
|
||||
];
|
||||
|
||||
// default is English
|
||||
const currentLanguage = languages.find((locale) => i18next.resolvedLanguage! === locale.key)?.label ?? "English";
|
||||
export const currentLanguage = languages[i18next.resolvedLanguage!] ?? "English";
|
||||
|
||||
/**
|
||||
* Setting Keys for existing settings
|
||||
@ -828,18 +770,24 @@ export function setSetting(scene: BattleScene, setting: string, value: integer):
|
||||
}
|
||||
};
|
||||
scene.ui.setOverlayMode(Mode.OPTION_SELECT, {
|
||||
options: [...languages.filter((locale,i,a) => {
|
||||
// Remove language active and sames labels
|
||||
if (currentLanguage !== locale.label && a.findIndex((t) => t.label === locale.label) === i) {
|
||||
locale.handler = () => changeLocaleHandler(locale.key);
|
||||
return locale;
|
||||
}
|
||||
}),
|
||||
{
|
||||
label: i18next.t("settings:back"),
|
||||
handler: () => cancelHandler(),
|
||||
}],
|
||||
maxOptions: 7
|
||||
options: [
|
||||
...Object.values(languages)
|
||||
.map((lang, index) => {
|
||||
return {
|
||||
label: lang,
|
||||
handler: () => changeLocaleHandler(Object.keys(languages)[index]),
|
||||
};
|
||||
})
|
||||
.filter((lang) => {
|
||||
// Remove language active
|
||||
return currentLanguage !== lang.label;
|
||||
}),
|
||||
{
|
||||
label: i18next.t("settings:back"),
|
||||
handler: () => cancelHandler(),
|
||||
},
|
||||
],
|
||||
maxOptions: 7,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user