Skip to content

Commit

Permalink
[Refactor][Localization] Better handling for StatusEffect.NONE with…
Browse files Browse the repository at this point in the history
… i18n (pagefaultgames#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)
  • Loading branch information
flx-sta authored Sep 24, 2024
1 parent 254ffcf commit 9af8941
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 78 deletions.
16 changes: 16 additions & 0 deletions src/data/status-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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);
}
Expand Down
8 changes: 1 addition & 7 deletions src/locales/de/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "None",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "None"
},
"poison": {
"name": "Gift",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/en/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "None",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "None"
},
"poison": {
"name": "Poison",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/es/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "Ninguno",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "Ninguno"
},
"poison": {
"name": "Envenenamiento",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/fr/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "Aucun",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "Aucun"
},
"poison": {
"name": "Empoisonnement",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/it/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"none": {
"name": "None",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "None"
}
}
8 changes: 1 addition & 7 deletions src/locales/ja/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "なし",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "なし"
},
"poison": {
"name": "どく",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/ko/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "없음",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "없음"
},
"poison": {
"name": "",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/pt_BR/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "Nenhum",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": "Nenhum"
},
"poison": {
"name": "Envenenamento",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/zh_CN/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": ""
},
"poison": {
"name": "中毒",
Expand Down
8 changes: 1 addition & 7 deletions src/locales/zh_TW/status-effect.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"none": {
"name": "",
"description": "",
"obtain": "",
"obtainSource": "",
"activation": "",
"overlap": "",
"heal": ""
"name": ""
},
"poison": {
"name": "中毒",
Expand Down
17 changes: 9 additions & 8 deletions src/test/localization/status-effect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
});
});

Expand Down

0 comments on commit 9af8941

Please sign in to comment.