diff --git a/composables/i18n.ts b/composables/i18n.ts index 0e8f6e15..c78abc83 100644 --- a/composables/i18n.ts +++ b/composables/i18n.ts @@ -8,18 +8,18 @@ export const formattedNumber = (num: number, useFormatter: Intl.NumberFormat = f } export const useHumanReadableNumber = () => { - const { t, n, locale } = useI18n() + const { n, locale } = useI18n() const fn = (num: number) => { - if (num < 10000) - return n(num, 'smallCounting', locale.value) - - // show 1 decimal: we cannot use toFixed(1), it is a string - if (num < 1000000) - return `${n(Math.floor(num / 100) / 10, 'kiloCounting', locale.value)}${t('common.kiloSuffix')}` - - // show 2 decimals: we cannot use toFixed(2), it is a string - return `${n(Math.floor(num / 10000) / 100, 'millionCounting', locale.value)}${t('common.megaSuffix')}` + return n( + num, + num < 10000 + ? 'smallCounting' + : num < 1000000 + ? 'kiloCounting' + : 'millionCounting', + locale.value, + ) } return { diff --git a/config/i18n.ts b/config/i18n.ts index aa1f184f..1a944abd 100644 --- a/config/i18n.ts +++ b/config/i18n.ts @@ -107,11 +107,13 @@ const numberFormats = Object.values(locales).reduce((acc, data) => { maximumFractionDigits: 0, }, kiloCounting: { - style: 'decimal', + notation: 'compact', + compactDisplay: 'short', maximumFractionDigits: 1, }, millionCounting: { - style: 'decimal', + notation: 'compact', + compactDisplay: 'short', maximumFractionDigits: 2, }, } diff --git a/locales/ar-EG.json b/locales/ar-EG.json index fc2c2df2..ff7d25be 100644 --- a/locales/ar-EG.json +++ b/locales/ar-EG.json @@ -85,8 +85,6 @@ "end_of_list": "نهاية القائمة", "error": "حدث خطأ", "in": "في", - "kiloSuffix": "ألف", - "megaSuffix": "مليون", "not_found": "404 غير معثور عليه", "offline_desc": "يبدو أنك غير متصل بالإنترنت. يرجى التحقق من اتصالك." }, diff --git a/locales/cs-CZ.json b/locales/cs-CZ.json index 8b22bee0..d5466e87 100644 --- a/locales/cs-CZ.json +++ b/locales/cs-CZ.json @@ -64,8 +64,6 @@ "common": { "end_of_list": "Konec seznamu", "error": "CHYBA", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "404 Nenalezeno!", "offline_desc": "Zdá se, že jste offline. Zkontrolujte připojení k internetu." }, diff --git a/locales/de-DE.json b/locales/de-DE.json index aa5a9c5b..e8ac86b7 100644 --- a/locales/de-DE.json +++ b/locales/de-DE.json @@ -64,8 +64,6 @@ "common": { "end_of_list": "Ende der Liste", "error": "FEHLER", - "kiloSuffix": "T", - "megaSuffix": "M", "not_found": "404 Nicht Gefunden", "offline_desc": "Anscheinend bist du offline. Bitte überprüfe deine Netzwerkverbindung." }, diff --git a/locales/en-GB.json b/locales/en-GB.json index 79be69d8..a591236e 100644 --- a/locales/en-GB.json +++ b/locales/en-GB.json @@ -85,8 +85,6 @@ "end_of_list": "End of the list", "error": "ERROR", "in": "in", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "404 Not Found", "offline_desc": "Seems like you are offline. Please check your network connection." }, diff --git a/locales/en-US.json b/locales/en-US.json index 3d1f45f2..a5113666 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -85,8 +85,6 @@ "end_of_list": "End of the list", "error": "ERROR", "in": "in", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "404 Not Found", "offline_desc": "Seems like you are offline. Please check your network connection." }, diff --git a/locales/es-ES.json b/locales/es-ES.json index d42d53ac..7c410531 100644 --- a/locales/es-ES.json +++ b/locales/es-ES.json @@ -83,8 +83,6 @@ "end_of_list": "Fin", "error": "ERROR", "in": "en", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "404 No Encontrado", "offline_desc": "Al parecer estás fuera de línea. Por favor, comprueba tu conexión a la red." }, diff --git a/locales/fr-FR.json b/locales/fr-FR.json index ccf81249..1f5c1bb1 100644 --- a/locales/fr-FR.json +++ b/locales/fr-FR.json @@ -82,8 +82,6 @@ "end_of_list": "Fin de liste", "error": "ERREUR", "in": "sur", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "404 Introuvable", "offline_desc": "Il semble que vous soyez hors-ligne. Vérifiez votre connexion internet." }, diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 71166b0e..cd738354 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -85,8 +85,6 @@ "end_of_list": "列表到底啦", "error": "错误", "in": "在", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "无法找到相关内容", "offline_desc": "您目前已离线,请检查网络连接。" }, diff --git a/locales/zh-TW.json b/locales/zh-TW.json index a1193ffa..e32b0a9a 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -85,8 +85,6 @@ "end_of_list": "列表到底啦", "error": "錯誤", "in": "在", - "kiloSuffix": "K", - "megaSuffix": "M", "not_found": "無法找到相關內容", "offline_desc": "您目前已離線,請檢查網絡連接。" },