From a8205ae8199237a669e87624bca04d4f91bd2e3b Mon Sep 17 00:00:00 2001 From: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com> Date: Tue, 4 Jun 2024 22:11:02 +0200 Subject: [PATCH] =?UTF-8?q?[Bug]=20Handle=20if=20the=20browser=20gives=20a?= =?UTF-8?q?=20long=20form=20of=20a=20language=20(like=20"de-DE")=20?= =?UTF-8?q?=E2=80=A6=20(#1795)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Handle if the browser gives a long form of a language (like "de-DE") for cases where we only have the short form "de". * Changed it so that now resolved Language is now used anywhere. This is basically what i orignally did manually but provided from i18next directly --- src/loading-scene.ts | 2 +- src/ui/fight-ui-handler.ts | 4 ++-- src/ui/pokemon-info-container.ts | 2 +- src/ui/starter-select-ui-handler.ts | 6 +++--- src/ui/summary-ui-handler.ts | 6 +++--- src/ui/text.ts | 2 +- src/utils.ts | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/loading-scene.ts b/src/loading-scene.ts index 0b15358c4bc..7c108a3c30e 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -213,7 +213,7 @@ export class LoadingScene extends SceneBase { this.loadAtlas("types", ""); // Get current lang and load the types atlas for it. English will only load types while all other languages will load types and types_ - const lang = i18next.language; + const lang = i18next.resolvedLanguage; if (lang !== "en") { if (Utils.verifyLang(lang)) { this.loadAtlas(`types_${lang}`, ""); diff --git a/src/ui/fight-ui-handler.ts b/src/ui/fight-ui-handler.ts index 22a0acb14ae..acbf66b7075 100644 --- a/src/ui/fight-ui-handler.ts +++ b/src/ui/fight-ui-handler.ts @@ -35,7 +35,7 @@ export default class FightUiHandler extends UiHandler { this.movesContainer = this.scene.add.container(18, -38.7); ui.add(this.movesContainer); - this.typeIcon = this.scene.add.sprite((this.scene.game.canvas.width / 6) - 57, -36,`types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}` , "unknown"); + this.typeIcon = this.scene.add.sprite((this.scene.game.canvas.width / 6) - 57, -36,`types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}` , "unknown"); this.typeIcon.setVisible(false); ui.add(this.typeIcon); @@ -168,7 +168,7 @@ export default class FightUiHandler extends UiHandler { if (hasMove) { const pokemonMove = moveset[cursor]; - this.typeIcon.setTexture(`types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}`, Type[pokemonMove.getMove().type].toLowerCase()).setScale(0.8); + this.typeIcon.setTexture(`types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`, Type[pokemonMove.getMove().type].toLowerCase()).setScale(0.8); this.moveCategoryIcon.setTexture("categories", MoveCategory[pokemonMove.getMove().category].toLowerCase()).setScale(1.0); const power = pokemonMove.getMove().power; diff --git a/src/ui/pokemon-info-container.ts b/src/ui/pokemon-info-container.ts index cf4c94e1164..b731b0d22b4 100644 --- a/src/ui/pokemon-info-container.ts +++ b/src/ui/pokemon-info-container.ts @@ -73,7 +73,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { } setup(): void { - const currentLanguage = i18next.language; + const currentLanguage = i18next.resolvedLanguage; const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage.includes(lang)); const textSettings = languageSettings[langSettingKey]; const infoBg = addWindow(this.scene, 0, 0, this.infoWindowWidth, 132); diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 3faec4bfcc6..abba4a081df 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -251,7 +251,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { setup() { const ui = this.getUi(); - const currentLanguage = i18next.language; + const currentLanguage = i18next.resolvedLanguage; const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage.includes(lang)); const textSettings = languageSettings[langSettingKey]; @@ -518,11 +518,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.starterSelectContainer.add(this.pokemonSprite); - this.type1Icon = this.scene.add.sprite(8, 98, `types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}`); this.type1Icon.setScale(0.5); + this.type1Icon = this.scene.add.sprite(8, 98, `types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`); this.type1Icon.setScale(0.5); this.type1Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type1Icon); - this.type2Icon = this.scene.add.sprite(26, 98, `types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}`); this.type2Icon.setScale(0.5); + this.type2Icon = this.scene.add.sprite(26, 98, `types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`); this.type2Icon.setScale(0.5); this.type2Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type2Icon); diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 32f5bffeb1b..1133e7a755c 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -695,7 +695,7 @@ export default class SummaryUiHandler extends UiHandler { const getTypeIcon = (index: integer, type: Type, tera: boolean = false) => { const xCoord = 39 + 34 * index; const typeIcon = !tera - ? this.scene.add.sprite(xCoord, 42, `types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}`, Type[type].toLowerCase()) : this.scene.add.sprite(xCoord, 42, "type_tera"); + ? this.scene.add.sprite(xCoord, 42, `types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`, Type[type].toLowerCase()) : this.scene.add.sprite(xCoord, 42, "type_tera"); if (tera) { typeIcon.setScale(0.5); const typeRgb = getTypeRgb(type); @@ -897,7 +897,7 @@ export default class SummaryUiHandler extends UiHandler { if (this.summaryUiMode === SummaryUiMode.LEARN_MOVE) { this.extraMoveRowContainer.setVisible(true); - const newMoveTypeIcon = this.scene.add.sprite(0, 0, `types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}`, Type[this.newMove.type].toLowerCase()); + const newMoveTypeIcon = this.scene.add.sprite(0, 0, `types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`, Type[this.newMove.type].toLowerCase()); newMoveTypeIcon.setOrigin(0, 1); this.extraMoveRowContainer.add(newMoveTypeIcon); @@ -920,7 +920,7 @@ export default class SummaryUiHandler extends UiHandler { this.moveRowsContainer.add(moveRowContainer); if (move) { - const typeIcon = this.scene.add.sprite(0, 0, `types${Utils.verifyLang(i18next.language) ? `_${i18next.language}` : ""}`, Type[move.getMove().type].toLowerCase()); typeIcon.setOrigin(0, 1); + const typeIcon = this.scene.add.sprite(0, 0, `types${Utils.verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`, Type[move.getMove().type].toLowerCase()); typeIcon.setOrigin(0, 1); moveRowContainer.add(typeIcon); } diff --git a/src/ui/text.ts b/src/ui/text.ts index 4e76386aae7..56e1b492dfa 100644 --- a/src/ui/text.ts +++ b/src/ui/text.ts @@ -98,7 +98,7 @@ export function addTextInputObject(scene: Phaser.Scene, x: number, y: number, wi } function getTextStyleOptions(style: TextStyle, uiTheme: UiTheme, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): [ Phaser.Types.GameObjects.Text.TextStyle | InputText.IConfig, string, number, number ] { - const lang = i18next.language; + const lang = i18next.resolvedLanguage; let shadowXpos = 4; let shadowYpos = 5; diff --git a/src/utils.ts b/src/utils.ts index adfe0b0df20..6d965369ca3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -396,7 +396,7 @@ English itself counts as not available export function verifyLang(lang?: string): boolean { //IMPORTANT - ONLY ADD YOUR LANG HERE IF YOU'VE ALREADY ADDED ALL THE NECESSARY IMAGES if (!lang) { - lang = i18next.language; + lang = i18next.resolvedLanguage; } switch (lang) {