From 18ef10c644e9e5abf1c63eef7e24078a56469ace Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:39:58 -0700 Subject: [PATCH 1/3] fix: i18n money formatter --- src/plugins/i18n.ts | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/plugins/i18n.ts b/src/plugins/i18n.ts index 5f7be4768a34..bcc1b7a7870e 100644 --- a/src/plugins/i18n.ts +++ b/src/plugins/i18n.ts @@ -100,6 +100,22 @@ async function initFonts(language: string | undefined) { } } +/** + * I18n money formatter with. (useful for BBCode coloring of text)\ + * *If you don't want the BBCode tag applied, just use 'number' formatter* + * @example Input: `{{myMoneyValue, money}}` + * Output: `@[MONEY]{₽100,000,000}` + * @param amount the money amount + * @returns a money formatted string + */ +function i18nMoneyFormatter(amount: any): string { + if (typeof amount !== "number") { + console.warn(`i18nMoneyFormatter: value "${amount}" is not a number!`); + } + + return `@[MONEY]{${i18next.t("common:money", { amount })}}`; +} + //#region Exports /** @@ -249,24 +265,10 @@ export async function initI18n(): Promise { postProcess: ["korean-postposition"], }); - // Input: {{myMoneyValue, money}} - // Output: @[MONEY]{₽100,000,000} (useful for BBCode coloring of text) - // If you don't want the BBCode tag applied, just use 'number' formatter - i18next.services.formatter?.add("money", (value, lng, options) => { - const numberFormattedString = Intl.NumberFormat(lng, options).format(value); - switch (lng) { - case "ja": - return `@[MONEY]{${numberFormattedString}}円`; - case "de": - case "es": - case "fr": - case "it": - return `@[MONEY]{${numberFormattedString} ₽}`; - default: - // English and other languages that use same format - return `@[MONEY]{₽${numberFormattedString}}`; - } - }); + + if (i18next.services.formatter) { + i18next.services.formatter.add("money", i18nMoneyFormatter); + } await initFonts(localStorage.getItem("prLang") ?? undefined); } From a9ec1d29e5660d6fc396006d7fca571a08a41b01 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:48:05 -0700 Subject: [PATCH 2/3] fix wrongful console.warn on i18n money formatter --- src/plugins/i18n.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/i18n.ts b/src/plugins/i18n.ts index bcc1b7a7870e..496031cdefb8 100644 --- a/src/plugins/i18n.ts +++ b/src/plugins/i18n.ts @@ -109,7 +109,7 @@ async function initFonts(language: string | undefined) { * @returns a money formatted string */ function i18nMoneyFormatter(amount: any): string { - if (typeof amount !== "number") { + if (isNaN(Number(amount))) { console.warn(`i18nMoneyFormatter: value "${amount}" is not a number!`); } From e653923b713a8c8f5f5a262622f0ac2e0b1e4f64 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:40:39 -0700 Subject: [PATCH 3/3] update locales submodule update reference to `56eeb809eb5a2de40cfc5bc6128a78bef14deea9` (from `3ccef8472dd7cc7c362538489954cb8fdad27e5f`) --- public/locales | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/locales b/public/locales index 3ccef8472dd7..56eeb809eb5a 160000 --- a/public/locales +++ b/public/locales @@ -1 +1 @@ -Subproject commit 3ccef8472dd7cc7c362538489954cb8fdad27e5f +Subproject commit 56eeb809eb5a2de40cfc5bc6128a78bef14deea9