When the language is changed the game will complety reload (same as F5). (#1438)

Also now only the current language type image is loaded. If it doesnt exist for a language it will load the english one as a fallback

Tested with all lanugages
This commit is contained in:
Jannik Tappert 2024-05-27 17:12:29 +02:00 committed by GitHub
parent 6059f0ee33
commit 8a6f87cfea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 15 deletions

View File

@ -206,23 +206,19 @@ export class LoadingScene extends SceneBase {
this.loadAtlas("items", "");
this.loadAtlas("types", "");
(i18next.options.supportedLngs as Array<any>).forEach(lang => {
switch (lang) {
case "pt":
lang = "pt_BR";
break;
case "zh":
lang = "zh_CN";
break;
}
// Get current lang and load the types atlas for it. English will only load types while all other languages will load types and types_<lang>
const lang = i18next.language;
if (lang !== "en") {
if (Utils.verifyLang(lang)) {
if (lang === "zh_CN") {
// Load also the traditional Chinese since it doesn't have a separate language code in supportedLngs
this.loadAtlas("types_zh_TW", "");
}
this.loadAtlas(`types_${lang}`, "");
} else {
// Fallback to English
this.loadAtlas("types", "");
}
});
} else {
this.loadAtlas("types", "");
}
this.loadAtlas("statuses", "");
this.loadAtlas("categories", "");

View File

@ -186,7 +186,8 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer)
i18next.changeLanguage(locale);
localStorage.setItem("prLang", locale);
cancelHandler();
scene.reset(true, false, true);
// Reload the whole game to apply the new locale since also some constants are translated
window.location.reload();
return true;
} catch (error) {
console.error("Error changing locale:", error);