[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)
This commit is contained in:
flx-sta 2024-09-24 14:15:18 -07:00 committed by GitHub
parent 254ffcf6d6
commit 9af89414b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 35 additions and 78 deletions

View File

@ -44,6 +44,10 @@ function getStatusEffectMessageKey(statusEffect: StatusEffect | undefined): stri
} }
export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined, pokemonNameWithAffix: string, sourceText?: string): string { export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined, pokemonNameWithAffix: string, sourceText?: string): string {
if (statusEffect === StatusEffect.NONE) {
return "";
}
if (!sourceText) { if (!sourceText) {
const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.obtain`as ParseKeys; const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.obtain`as ParseKeys;
return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix });
@ -53,21 +57,33 @@ export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined
} }
export function getStatusEffectActivationText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { export function getStatusEffectActivationText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string {
if (statusEffect === StatusEffect.NONE) {
return "";
}
const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.activation` as ParseKeys; const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.activation` as ParseKeys;
return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix });
} }
export function getStatusEffectOverlapText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { export function getStatusEffectOverlapText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string {
if (statusEffect === StatusEffect.NONE) {
return "";
}
const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.overlap` as ParseKeys; const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.overlap` as ParseKeys;
return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix });
} }
export function getStatusEffectHealText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { export function getStatusEffectHealText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string {
if (statusEffect === StatusEffect.NONE) {
return "";
}
const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.heal` as ParseKeys; const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.heal` as ParseKeys;
return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix });
} }
export function getStatusEffectDescriptor(statusEffect: StatusEffect): string { export function getStatusEffectDescriptor(statusEffect: StatusEffect): string {
if (statusEffect === StatusEffect.NONE) {
return "";
}
const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.description` as ParseKeys; const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.description` as ParseKeys;
return i18next.t(i18nKey); return i18next.t(i18nKey);
} }

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "None", "name": "None"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "Gift", "name": "Gift",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "None", "name": "None"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "Poison", "name": "Poison",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "Ninguno", "name": "Ninguno"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "Envenenamiento", "name": "Envenenamiento",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "Aucun", "name": "Aucun"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "Empoisonnement", "name": "Empoisonnement",

View File

@ -1,11 +1,5 @@
{ {
"none": { "none": {
"name": "None", "name": "None"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
} }
} }

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "なし", "name": "なし"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "どく", "name": "どく",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "없음", "name": "없음"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "독", "name": "독",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "Nenhum", "name": "Nenhum"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "Envenenamento", "name": "Envenenamento",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "无", "name": "无"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "中毒", "name": "中毒",

View File

@ -1,12 +1,6 @@
{ {
"none": { "none": {
"name": "無", "name": "無"
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
}, },
"poison": { "poison": {
"name": "中毒", "name": "中毒",

View File

@ -18,44 +18,45 @@ describe("status-effect", () => {
mockI18next(); mockI18next();
const text = getStatusEffectObtainText(statusEffect, pokemonName); const text = getStatusEffectObtainText(statusEffect, pokemonName);
expect(text).toBe("statusEffect:none.obtain"); console.log("text:", text);
expect(text).toBe("");
const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, "");
expect(emptySourceText).toBe("statusEffect:none.obtain"); expect(emptySourceText).toBe("");
}); });
it("should return the source-obtain text", () => { it("should return the source-obtain text", () => {
mockI18next(); mockI18next();
const text = getStatusEffectObtainText(statusEffect, pokemonName, sourceText); const text = getStatusEffectObtainText(statusEffect, pokemonName, sourceText);
expect(text).toBe("statusEffect:none.obtainSource"); expect(text).toBe("");
const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, "");
expect(emptySourceText).not.toBe("statusEffect:none.obtainSource"); expect(emptySourceText).toBe("");
}); });
it("should return the activation text", () => { it("should return the activation text", () => {
mockI18next(); mockI18next();
const text = getStatusEffectActivationText(statusEffect, pokemonName); const text = getStatusEffectActivationText(statusEffect, pokemonName);
expect(text).toBe("statusEffect:none.activation"); expect(text).toBe("");
}); });
it("should return the overlap text", () => { it("should return the overlap text", () => {
mockI18next(); mockI18next();
const text = getStatusEffectOverlapText(statusEffect, pokemonName); const text = getStatusEffectOverlapText(statusEffect, pokemonName);
expect(text).toBe("statusEffect:none.overlap"); expect(text).toBe("");
}); });
it("should return the heal text", () => { it("should return the heal text", () => {
mockI18next(); mockI18next();
const text = getStatusEffectHealText(statusEffect, pokemonName); const text = getStatusEffectHealText(statusEffect, pokemonName);
expect(text).toBe("statusEffect:none.heal"); expect(text).toBe("");
}); });
it("should return the descriptor", () => { it("should return the descriptor", () => {
mockI18next(); mockI18next();
const text = getStatusEffectDescriptor(statusEffect); const text = getStatusEffectDescriptor(statusEffect);
expect(text).toBe("statusEffect:none.description"); expect(text).toBe("");
}); });
}); });