From 76b37b11ca198f2f627788e731e4dd0c0c3ddd63 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 17 Mar 2025 16:12:04 -0400 Subject: [PATCH 1/2] Localize formatting helpers --- webview-ui/src/i18n/locales/ca/common.json | 8 ++++- webview-ui/src/i18n/locales/de/common.json | 8 ++++- webview-ui/src/i18n/locales/en/common.json | 8 ++++- webview-ui/src/i18n/locales/es/common.json | 8 ++++- webview-ui/src/i18n/locales/fr/common.json | 8 ++++- webview-ui/src/i18n/locales/hi/common.json | 8 ++++- webview-ui/src/i18n/locales/it/common.json | 8 ++++- webview-ui/src/i18n/locales/ja/common.json | 8 ++++- webview-ui/src/i18n/locales/ko/common.json | 8 ++++- webview-ui/src/i18n/locales/pl/common.json | 8 ++++- webview-ui/src/i18n/locales/pt-BR/common.json | 8 ++++- webview-ui/src/i18n/locales/tr/common.json | 8 ++++- webview-ui/src/i18n/locales/vi/common.json | 8 ++++- webview-ui/src/i18n/locales/zh-CN/common.json | 8 ++++- webview-ui/src/i18n/locales/zh-TW/common.json | 8 ++++- webview-ui/src/utils/format.ts | 36 +++++++++++-------- 16 files changed, 127 insertions(+), 29 deletions(-) diff --git a/webview-ui/src/i18n/locales/ca/common.json b/webview-ui/src/i18n/locales/ca/common.json index 0967ef424bc..bdbe1d188a3 100644 --- a/webview-ui/src/i18n/locales/ca/common.json +++ b/webview-ui/src/i18n/locales/ca/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "mil", + "million_suffix": "M", + "billion_suffix": "MM" + } +} diff --git a/webview-ui/src/i18n/locales/de/common.json b/webview-ui/src/i18n/locales/de/common.json index 0967ef424bc..ba8ee29b2df 100644 --- a/webview-ui/src/i18n/locales/de/common.json +++ b/webview-ui/src/i18n/locales/de/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "Tsd.", + "million_suffix": "Mio.", + "billion_suffix": "Mrd." + } +} diff --git a/webview-ui/src/i18n/locales/en/common.json b/webview-ui/src/i18n/locales/en/common.json index 0967ef424bc..2a10002acb4 100644 --- a/webview-ui/src/i18n/locales/en/common.json +++ b/webview-ui/src/i18n/locales/en/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "k", + "million_suffix": "m", + "billion_suffix": "b" + } +} diff --git a/webview-ui/src/i18n/locales/es/common.json b/webview-ui/src/i18n/locales/es/common.json index 0967ef424bc..f0ed1318575 100644 --- a/webview-ui/src/i18n/locales/es/common.json +++ b/webview-ui/src/i18n/locales/es/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "k", + "million_suffix": "M", + "billion_suffix": "MM" + } +} diff --git a/webview-ui/src/i18n/locales/fr/common.json b/webview-ui/src/i18n/locales/fr/common.json index 0967ef424bc..e55e852b3ff 100644 --- a/webview-ui/src/i18n/locales/fr/common.json +++ b/webview-ui/src/i18n/locales/fr/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "k", + "million_suffix": "M", + "billion_suffix": "Md" + } +} diff --git a/webview-ui/src/i18n/locales/hi/common.json b/webview-ui/src/i18n/locales/hi/common.json index 0967ef424bc..b1a651ba2e5 100644 --- a/webview-ui/src/i18n/locales/hi/common.json +++ b/webview-ui/src/i18n/locales/hi/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "ह", + "million_suffix": "लाख", + "billion_suffix": "अरब" + } +} diff --git a/webview-ui/src/i18n/locales/it/common.json b/webview-ui/src/i18n/locales/it/common.json index 0967ef424bc..369ddf7e7e9 100644 --- a/webview-ui/src/i18n/locales/it/common.json +++ b/webview-ui/src/i18n/locales/it/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "k", + "million_suffix": "Mln", + "billion_suffix": "Mrd" + } +} diff --git a/webview-ui/src/i18n/locales/ja/common.json b/webview-ui/src/i18n/locales/ja/common.json index 0967ef424bc..b76d0c03a93 100644 --- a/webview-ui/src/i18n/locales/ja/common.json +++ b/webview-ui/src/i18n/locales/ja/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "k", + "million_suffix": "M", + "billion_suffix": "B" + } +} diff --git a/webview-ui/src/i18n/locales/ko/common.json b/webview-ui/src/i18n/locales/ko/common.json index 0967ef424bc..4ee4c67efd1 100644 --- a/webview-ui/src/i18n/locales/ko/common.json +++ b/webview-ui/src/i18n/locales/ko/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "천", + "million_suffix": "백만", + "billion_suffix": "십억" + } +} diff --git a/webview-ui/src/i18n/locales/pl/common.json b/webview-ui/src/i18n/locales/pl/common.json index 0967ef424bc..e020754bf2d 100644 --- a/webview-ui/src/i18n/locales/pl/common.json +++ b/webview-ui/src/i18n/locales/pl/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "tys.", + "million_suffix": "mln", + "billion_suffix": "mld" + } +} diff --git a/webview-ui/src/i18n/locales/pt-BR/common.json b/webview-ui/src/i18n/locales/pt-BR/common.json index 0967ef424bc..a003f6ee918 100644 --- a/webview-ui/src/i18n/locales/pt-BR/common.json +++ b/webview-ui/src/i18n/locales/pt-BR/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "mil", + "million_suffix": "mi", + "billion_suffix": "bi" + } +} diff --git a/webview-ui/src/i18n/locales/tr/common.json b/webview-ui/src/i18n/locales/tr/common.json index 0967ef424bc..9bd908ea143 100644 --- a/webview-ui/src/i18n/locales/tr/common.json +++ b/webview-ui/src/i18n/locales/tr/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "B", + "million_suffix": "Mn", + "billion_suffix": "Mr" + } +} diff --git a/webview-ui/src/i18n/locales/vi/common.json b/webview-ui/src/i18n/locales/vi/common.json index 0967ef424bc..dc5650760a1 100644 --- a/webview-ui/src/i18n/locales/vi/common.json +++ b/webview-ui/src/i18n/locales/vi/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "k", + "million_suffix": "tr", + "billion_suffix": "tỷ" + } +} diff --git a/webview-ui/src/i18n/locales/zh-CN/common.json b/webview-ui/src/i18n/locales/zh-CN/common.json index 0967ef424bc..a1d34b00598 100644 --- a/webview-ui/src/i18n/locales/zh-CN/common.json +++ b/webview-ui/src/i18n/locales/zh-CN/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "千", + "million_suffix": "百万", + "billion_suffix": "十亿" + } +} diff --git a/webview-ui/src/i18n/locales/zh-TW/common.json b/webview-ui/src/i18n/locales/zh-TW/common.json index 0967ef424bc..40f2534e471 100644 --- a/webview-ui/src/i18n/locales/zh-TW/common.json +++ b/webview-ui/src/i18n/locales/zh-TW/common.json @@ -1 +1,7 @@ -{} +{ + "number_format": { + "thousand_suffix": "千", + "million_suffix": "百萬", + "billion_suffix": "十億" + } +} diff --git a/webview-ui/src/utils/format.ts b/webview-ui/src/utils/format.ts index 12e99962051..7f8d5d266c9 100644 --- a/webview-ui/src/utils/format.ts +++ b/webview-ui/src/utils/format.ts @@ -1,27 +1,35 @@ +import i18next from "i18next" + export function formatLargeNumber(num: number): string { if (num >= 1e9) { - return (num / 1e9).toFixed(1) + "b" + return (num / 1e9).toFixed(1) + i18next.t("common:number_format.billion_suffix") } if (num >= 1e6) { - return (num / 1e6).toFixed(1) + "m" + return (num / 1e6).toFixed(1) + i18next.t("common:number_format.million_suffix") } if (num >= 1e3) { - return (num / 1e3).toFixed(1) + "k" + return (num / 1e3).toFixed(1) + i18next.t("common:number_format.thousand_suffix") } return num.toString() } export const formatDate = (timestamp: number) => { const date = new Date(timestamp) - return date - .toLocaleString("en-US", { - month: "long", - day: "numeric", - hour: "numeric", - minute: "2-digit", - hour12: true, - }) - .replace(", ", " ") - .replace(" at", ",") - .toUpperCase() + const locale = i18next.language || "en" + + // Get date format style from translations or use default transformations + const dateStr = date.toLocaleString(locale, { + month: "long", + day: "numeric", + hour: "numeric", + minute: "2-digit", + hour12: true, + }) + + // Apply transformations based on locale or use default + if (locale === "en") { + return dateStr.replace(", ", " ").replace(" at", ",").toUpperCase() + } + + return dateStr.toUpperCase() } From a8ef2e1347d7d4ca6d935d0915b424764f149182 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 17 Mar 2025 16:28:55 -0400 Subject: [PATCH 2/2] Update webview-ui/src/i18n/locales/it/common.json Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- webview-ui/src/i18n/locales/it/common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webview-ui/src/i18n/locales/it/common.json b/webview-ui/src/i18n/locales/it/common.json index 369ddf7e7e9..c010b119567 100644 --- a/webview-ui/src/i18n/locales/it/common.json +++ b/webview-ui/src/i18n/locales/it/common.json @@ -2,6 +2,6 @@ "number_format": { "thousand_suffix": "k", "million_suffix": "Mln", - "billion_suffix": "Mrd" + "billion_suffix": "Mld" } }