Skip to content

Commit

Permalink
When the language is changed the game will complety reload (same as F5).
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CodeTappert committed May 27, 2024
1 parent 6059f0e commit 063de81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
24 changes: 10 additions & 14 deletions src/loading-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down
3 changes: 2 additions & 1 deletion src/system/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 063de81

Please sign in to comment.