[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:
parent
254ffcf6d6
commit
9af89414b9
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "None",
|
"name": "None"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "Gift",
|
"name": "Gift",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "None",
|
"name": "None"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "Poison",
|
"name": "Poison",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "Ninguno",
|
"name": "Ninguno"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "Envenenamiento",
|
"name": "Envenenamiento",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "Aucun",
|
"name": "Aucun"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "Empoisonnement",
|
"name": "Empoisonnement",
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "None",
|
"name": "None"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "なし",
|
"name": "なし"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "どく",
|
"name": "どく",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "없음",
|
"name": "없음"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "독",
|
"name": "독",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "Nenhum",
|
"name": "Nenhum"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "Envenenamento",
|
"name": "Envenenamento",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "无",
|
"name": "无"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "中毒",
|
"name": "中毒",
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"none": {
|
"none": {
|
||||||
"name": "無",
|
"name": "無"
|
||||||
"description": "",
|
|
||||||
"obtain": "",
|
|
||||||
"obtainSource": "",
|
|
||||||
"activation": "",
|
|
||||||
"overlap": "",
|
|
||||||
"heal": ""
|
|
||||||
},
|
},
|
||||||
"poison": {
|
"poison": {
|
||||||
"name": "中毒",
|
"name": "中毒",
|
||||||
|
|
|
@ -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("");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue