Merge pull request #1752 from RooVetGit/i18n_format

Localize formatting helpers
This commit is contained in:
Matt Rubens 2025-03-17 16:29:04 -04:00 committed by GitHub
commit 56ff9ea77b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 127 additions and 29 deletions

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "mil",
"million_suffix": "M",
"billion_suffix": "MM"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "Tsd.",
"million_suffix": "Mio.",
"billion_suffix": "Mrd."
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "k",
"million_suffix": "m",
"billion_suffix": "b"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "k",
"million_suffix": "M",
"billion_suffix": "MM"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "k",
"million_suffix": "M",
"billion_suffix": "Md"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "ह",
"million_suffix": "लाख",
"billion_suffix": "अरब"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "k",
"million_suffix": "Mln",
"billion_suffix": "Mld"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "k",
"million_suffix": "M",
"billion_suffix": "B"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "천",
"million_suffix": "백만",
"billion_suffix": "십억"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "tys.",
"million_suffix": "mln",
"billion_suffix": "mld"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "mil",
"million_suffix": "mi",
"billion_suffix": "bi"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "B",
"million_suffix": "Mn",
"billion_suffix": "Mr"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "k",
"million_suffix": "tr",
"billion_suffix": "tỷ"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "千",
"million_suffix": "百万",
"billion_suffix": "十亿"
}
}

View file

@ -1 +1,7 @@
{}
{
"number_format": {
"thousand_suffix": "千",
"million_suffix": "百萬",
"billion_suffix": "十億"
}
}

View file

@ -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()
}