[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 {
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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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("");
});
});