From 9af89414b9d360049eab1c1f5aca19b3727bcd01 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:15:18 -0700 Subject: [PATCH] [Refactor][Localization] Better handling for `StatusEffect.NONE` with i18n (#4405) * remove: `StatusEffect.NONE` from displaying any messages even thougn this case will never occur, by code definition it should be covered * remove: obsolete `statusEffect:none.` translation keys * fix: status-effect test * chore: undo overrides commit (whops) --- src/data/status-effect.ts | 16 ++++++++++++++++ src/locales/de/status-effect.json | 8 +------- src/locales/en/status-effect.json | 8 +------- src/locales/es/status-effect.json | 8 +------- src/locales/fr/status-effect.json | 8 +------- src/locales/it/status-effect.json | 8 +------- src/locales/ja/status-effect.json | 8 +------- src/locales/ko/status-effect.json | 8 +------- src/locales/pt_BR/status-effect.json | 8 +------- src/locales/zh_CN/status-effect.json | 8 +------- src/locales/zh_TW/status-effect.json | 8 +------- src/test/localization/status-effect.test.ts | 17 +++++++++-------- 12 files changed, 35 insertions(+), 78 deletions(-) diff --git a/src/data/status-effect.ts b/src/data/status-effect.ts index 4381db5c2c60..ffe32a02aeb9 100644 --- a/src/data/status-effect.ts +++ b/src/data/status-effect.ts @@ -44,6 +44,10 @@ function getStatusEffectMessageKey(statusEffect: StatusEffect | undefined): stri } export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined, pokemonNameWithAffix: string, sourceText?: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } + if (!sourceText) { const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.obtain`as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); @@ -53,21 +57,33 @@ export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined } export function getStatusEffectActivationText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.activation` as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); } export function getStatusEffectOverlapText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.overlap` as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); } export function getStatusEffectHealText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.heal` as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); } export function getStatusEffectDescriptor(statusEffect: StatusEffect): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.description` as ParseKeys; return i18next.t(i18nKey); } diff --git a/src/locales/de/status-effect.json b/src/locales/de/status-effect.json index c30d432fe79a..bec1bf14b3f4 100644 --- a/src/locales/de/status-effect.json +++ b/src/locales/de/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "None", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "None" }, "poison": { "name": "Gift", diff --git a/src/locales/en/status-effect.json b/src/locales/en/status-effect.json index fdbacfdb9bef..644680477612 100644 --- a/src/locales/en/status-effect.json +++ b/src/locales/en/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "None", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "None" }, "poison": { "name": "Poison", diff --git a/src/locales/es/status-effect.json b/src/locales/es/status-effect.json index 66534d11983f..9673a6a495b0 100644 --- a/src/locales/es/status-effect.json +++ b/src/locales/es/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "Ninguno", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "Ninguno" }, "poison": { "name": "Envenenamiento", diff --git a/src/locales/fr/status-effect.json b/src/locales/fr/status-effect.json index bfb7121f522a..13bcf59ef00a 100644 --- a/src/locales/fr/status-effect.json +++ b/src/locales/fr/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "Aucun", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "Aucun" }, "poison": { "name": "Empoisonnement", diff --git a/src/locales/it/status-effect.json b/src/locales/it/status-effect.json index 6270bbb10a59..bbf96f2ec821 100644 --- a/src/locales/it/status-effect.json +++ b/src/locales/it/status-effect.json @@ -1,11 +1,5 @@ { "none": { - "name": "None", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "None" } } \ No newline at end of file diff --git a/src/locales/ja/status-effect.json b/src/locales/ja/status-effect.json index 8dafbbdcba77..14e8932a400e 100644 --- a/src/locales/ja/status-effect.json +++ b/src/locales/ja/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "なし", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "なし" }, "poison": { "name": "どく", diff --git a/src/locales/ko/status-effect.json b/src/locales/ko/status-effect.json index d65243a8a241..489e67caaacf 100644 --- a/src/locales/ko/status-effect.json +++ b/src/locales/ko/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "없음", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "없음" }, "poison": { "name": "독", diff --git a/src/locales/pt_BR/status-effect.json b/src/locales/pt_BR/status-effect.json index 9b33b9fa8f79..f36841280434 100644 --- a/src/locales/pt_BR/status-effect.json +++ b/src/locales/pt_BR/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "Nenhum", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "Nenhum" }, "poison": { "name": "Envenenamento", diff --git a/src/locales/zh_CN/status-effect.json b/src/locales/zh_CN/status-effect.json index f7fb90921074..c9d7073021cc 100644 --- a/src/locales/zh_CN/status-effect.json +++ b/src/locales/zh_CN/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "无", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "无" }, "poison": { "name": "中毒", diff --git a/src/locales/zh_TW/status-effect.json b/src/locales/zh_TW/status-effect.json index 5f634a0bddf3..29908593eef0 100644 --- a/src/locales/zh_TW/status-effect.json +++ b/src/locales/zh_TW/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "無", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "無" }, "poison": { "name": "中毒", diff --git a/src/test/localization/status-effect.test.ts b/src/test/localization/status-effect.test.ts index 9dcab5aeb5f3..72b4dbd30991 100644 --- a/src/test/localization/status-effect.test.ts +++ b/src/test/localization/status-effect.test.ts @@ -18,44 +18,45 @@ describe("status-effect", () => { mockI18next(); const text = getStatusEffectObtainText(statusEffect, pokemonName); - expect(text).toBe("statusEffect:none.obtain"); + console.log("text:", text); + expect(text).toBe(""); const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); - expect(emptySourceText).toBe("statusEffect:none.obtain"); + expect(emptySourceText).toBe(""); }); it("should return the source-obtain text", () => { mockI18next(); const text = getStatusEffectObtainText(statusEffect, pokemonName, sourceText); - expect(text).toBe("statusEffect:none.obtainSource"); + expect(text).toBe(""); const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); - expect(emptySourceText).not.toBe("statusEffect:none.obtainSource"); + expect(emptySourceText).toBe(""); }); it("should return the activation text", () => { mockI18next(); const text = getStatusEffectActivationText(statusEffect, pokemonName); - expect(text).toBe("statusEffect:none.activation"); + expect(text).toBe(""); }); it("should return the overlap text", () => { mockI18next(); const text = getStatusEffectOverlapText(statusEffect, pokemonName); - expect(text).toBe("statusEffect:none.overlap"); + expect(text).toBe(""); }); it("should return the heal text", () => { mockI18next(); const text = getStatusEffectHealText(statusEffect, pokemonName); - expect(text).toBe("statusEffect:none.heal"); + expect(text).toBe(""); }); it("should return the descriptor", () => { mockI18next(); const text = getStatusEffectDescriptor(statusEffect); - expect(text).toBe("statusEffect:none.description"); + expect(text).toBe(""); }); });