From 7b95b41da31d9bf464ada868ce7ce1a6cea8e016 Mon Sep 17 00:00:00 2001 From: Lugiad <2070109+Adri1@users.noreply.github.com> Date: Mon, 23 Jun 2025 01:11:16 +0200 Subject: [PATCH] [i18n] Large Numbers Abbreviations Translation (#6021) * Large Number Abbreviations opended for transaltion * Large Number Abbreviations opended for transaltion * Apply Biome --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/utils/common.ts | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index 4bf51730148..753d6ebb865 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -201,19 +201,19 @@ export function formatLargeNumber(count: number, threshold: number): string { let suffix = ""; switch (Math.ceil(ret.length / 3) - 1) { case 1: - suffix = "K"; + suffix = i18next.t("common:abrThousand"); break; case 2: - suffix = "M"; + suffix = i18next.t("common:abrMillion"); break; case 3: - suffix = "B"; + suffix = i18next.t("common:abrBillion"); break; case 4: - suffix = "T"; + suffix = i18next.t("common:abrTrillion"); break; case 5: - suffix = "q"; + suffix = i18next.t("common:abrQuadrillion"); break; default: return "?"; @@ -227,15 +227,31 @@ export function formatLargeNumber(count: number, threshold: number): string { } // Abbreviations from 10^0 to 10^33 -const AbbreviationsLargeNumber: string[] = ["", "K", "M", "B", "t", "q", "Q", "s", "S", "o", "n", "d"]; +function getAbbreviationsLargeNumber(): string[] { + return [ + "", + i18next.t("common:abrThousand"), + i18next.t("common:abrMillion"), + i18next.t("common:abrBillion"), + i18next.t("common:abrTrillion"), + i18next.t("common:abrQuadrillion"), + i18next.t("common:abrQuintillion"), + i18next.t("common:abrSextillion"), + i18next.t("common:abrSeptillion"), + i18next.t("common:abrOctillion"), + i18next.t("common:abrNonillion"), + i18next.t("common:abrDecillion"), + ]; +} export function formatFancyLargeNumber(number: number, rounded = 3): string { + const abbreviations = getAbbreviationsLargeNumber(); let exponent: number; if (number < 1000) { exponent = 0; } else { - const maxExp = AbbreviationsLargeNumber.length - 1; + const maxExp = abbreviations.length - 1; exponent = Math.floor(Math.log(number) / Math.log(1000)); exponent = Math.min(exponent, maxExp); @@ -243,7 +259,7 @@ export function formatFancyLargeNumber(number: number, rounded = 3): string { number /= Math.pow(1000, exponent); } - return `${(exponent === 0) || number % 1 === 0 ? number : number.toFixed(rounded)}${AbbreviationsLargeNumber[exponent]}`; + return `${exponent === 0 || number % 1 === 0 ? number : number.toFixed(rounded)}${abbreviations[exponent]}`; } export function formatMoney(format: MoneyFormat, amount: number) {