From d08693edce25a45c2451cccc6666248cc630b4f9 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 25 Jun 2015 23:33:50 +0200 Subject: [PATCH] FEATURE: Make abbreviated numbers (k, M) localizable - Make the decimal separator and thousands delimiter localizable - Add translations for all languages, otherwise this will look very ugly --- app/assets/javascripts/discourse/lib/formatter.js | 8 ++++++-- config/locales/client.ar.yml | 6 ++++++ config/locales/client.bs_BA.yml | 6 ++++++ config/locales/client.cs.yml | 6 ++++++ config/locales/client.da.yml | 6 ++++++ config/locales/client.de.yml | 6 ++++++ config/locales/client.en.yml | 6 ++++++ config/locales/client.es.yml | 6 ++++++ config/locales/client.fa_IR.yml | 6 ++++++ config/locales/client.fi.yml | 6 ++++++ config/locales/client.fr.yml | 6 ++++++ config/locales/client.he.yml | 6 ++++++ config/locales/client.id.yml | 6 ++++++ config/locales/client.it.yml | 6 ++++++ config/locales/client.ja.yml | 6 ++++++ config/locales/client.ko.yml | 6 ++++++ config/locales/client.nb_NO.yml | 6 ++++++ config/locales/client.nl.yml | 6 ++++++ config/locales/client.pl_PL.yml | 6 ++++++ config/locales/client.pt.yml | 6 ++++++ config/locales/client.pt_BR.yml | 6 ++++++ config/locales/client.ro.yml | 6 ++++++ config/locales/client.ru.yml | 6 ++++++ config/locales/client.sq.yml | 6 ++++++ config/locales/client.sv.yml | 6 ++++++ config/locales/client.te.yml | 6 ++++++ config/locales/client.tr_TR.yml | 6 ++++++ config/locales/client.uk.yml | 6 ++++++ config/locales/client.zh_CN.yml | 6 ++++++ config/locales/client.zh_TW.yml | 6 ++++++ test/javascripts/lib/formatter-test.js.es6 | 5 +++-- 31 files changed, 183 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/formatter.js b/app/assets/javascripts/discourse/lib/formatter.js index 2b80eb08724..1b3db5baadc 100644 --- a/app/assets/javascripts/discourse/lib/formatter.js +++ b/app/assets/javascripts/discourse/lib/formatter.js @@ -258,14 +258,18 @@ relativeAge = function(date, options) { }; var number = function(val) { + var formattedNumber; + val = parseInt(val, 10); if (isNaN(val)) val = 0; if (val > 999999) { - return (val / 1000000).toFixed(1) + "M"; + formattedNumber = I18n.toNumber(val / 1000000, {precision: 1}); + return I18n.t("number.short.millions", {number: formattedNumber}); } if (val > 999) { - return (val / 1000).toFixed(1) + "K"; + formattedNumber = I18n.toNumber(val / 1000, {precision: 1}); + return I18n.t("number.short.thousands", {number: formattedNumber}); } return val.toString(); }; diff --git a/config/locales/client.ar.yml b/config/locales/client.ar.yml index 3e27e047435..12e345eae40 100644 --- a/config/locales/client.ar.yml +++ b/config/locales/client.ar.yml @@ -8,6 +8,9 @@ ar: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -23,6 +26,9 @@ ar: kb: كيلو بايت mb: ميجا tb: تيرا + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.bs_BA.yml b/config/locales/client.bs_BA.yml index 7b75d5a1260..1065a71d9ac 100644 --- a/config/locales/client.bs_BA.yml +++ b/config/locales/client.bs_BA.yml @@ -8,6 +8,9 @@ bs_BA: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -16,6 +19,9 @@ bs_BA: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.cs.yml b/config/locales/client.cs.yml index d4e65745dcc..9ddffd596c3 100644 --- a/config/locales/client.cs.yml +++ b/config/locales/client.cs.yml @@ -8,6 +8,9 @@ cs: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -20,6 +23,9 @@ cs: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.da.yml b/config/locales/client.da.yml index 280bbc44979..503c46b1e5d 100644 --- a/config/locales/client.da.yml +++ b/config/locales/client.da.yml @@ -8,6 +8,9 @@ da: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ da: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index a97bf4eade5..7cb1a869d5a 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -8,6 +8,9 @@ de: js: number: + format: + separator: "," + delimiter: "." human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ de: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "HH:mm" long_no_year: "DD. MMM HH:mm" diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index fd52411facb..21b634a75ac 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -18,6 +18,9 @@ en: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -29,6 +32,9 @@ en: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.es.yml b/config/locales/client.es.yml index 9ba731e84f5..7f0007e6f77 100644 --- a/config/locales/client.es.yml +++ b/config/locales/client.es.yml @@ -8,6 +8,9 @@ es: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ es: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.fa_IR.yml b/config/locales/client.fa_IR.yml index c412b10cf74..eff0ede16a2 100644 --- a/config/locales/client.fa_IR.yml +++ b/config/locales/client.fa_IR.yml @@ -8,6 +8,9 @@ fa_IR: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ fa_IR: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.fi.yml b/config/locales/client.fi.yml index b3d244cf19f..6f55c437046 100644 --- a/config/locales/client.fi.yml +++ b/config/locales/client.fi.yml @@ -8,6 +8,9 @@ fi: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ fi: kb: Kt mb: Mt tb: Tt + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "H:mm" long_no_year: "D. MMMM[ta] H:mm" diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml index 1bbcfbc5c3a..2d27a296f06 100644 --- a/config/locales/client.fr.yml +++ b/config/locales/client.fr.yml @@ -8,6 +8,9 @@ fr: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ fr: kb: Ko mb: Mo tb: To + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "H:mm" long_no_year: "DD MMM H:mm" diff --git a/config/locales/client.he.yml b/config/locales/client.he.yml index cd333a1e3bf..ecb0035beba 100644 --- a/config/locales/client.he.yml +++ b/config/locales/client.he.yml @@ -8,6 +8,9 @@ he: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ he: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.id.yml b/config/locales/client.id.yml index 349e5d8df37..b54ec61d02b 100644 --- a/config/locales/client.id.yml +++ b/config/locales/client.id.yml @@ -8,6 +8,9 @@ id: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ id: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "j:mm a" long_no_year: "BBB H j:mm a" diff --git a/config/locales/client.it.yml b/config/locales/client.it.yml index 62b313e3385..7d9c512967d 100644 --- a/config/locales/client.it.yml +++ b/config/locales/client.it.yml @@ -8,6 +8,9 @@ it: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ it: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "D MMM h:mm a" diff --git a/config/locales/client.ja.yml b/config/locales/client.ja.yml index aac93a7c3a2..6946937e68f 100644 --- a/config/locales/client.ja.yml +++ b/config/locales/client.ja.yml @@ -8,6 +8,9 @@ ja: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ ja: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.ko.yml b/config/locales/client.ko.yml index 57795b86647..11a80a9e11e 100644 --- a/config/locales/client.ko.yml +++ b/config/locales/client.ko.yml @@ -8,6 +8,9 @@ ko: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ ko: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "a h:mm" long_no_year: "MMM D a h:mm " diff --git a/config/locales/client.nb_NO.yml b/config/locales/client.nb_NO.yml index 85201bee403..c0e38b97b08 100644 --- a/config/locales/client.nb_NO.yml +++ b/config/locales/client.nb_NO.yml @@ -8,6 +8,9 @@ nb_NO: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ nb_NO: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "D MMM h:mm a" diff --git a/config/locales/client.nl.yml b/config/locales/client.nl.yml index 6672c4410a1..da9ac99a115 100644 --- a/config/locales/client.nl.yml +++ b/config/locales/client.nl.yml @@ -8,6 +8,9 @@ nl: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ nl: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.pl_PL.yml b/config/locales/client.pl_PL.yml index 6712552ec1b..2091f10ad60 100644 --- a/config/locales/client.pl_PL.yml +++ b/config/locales/client.pl_PL.yml @@ -8,6 +8,9 @@ pl_PL: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -20,6 +23,9 @@ pl_PL: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "H:mm" long_no_year: "D MMM H:mm" diff --git a/config/locales/client.pt.yml b/config/locales/client.pt.yml index 785e03d6d7a..dce4e8f9441 100644 --- a/config/locales/client.pt.yml +++ b/config/locales/client.pt.yml @@ -8,6 +8,9 @@ pt: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ pt: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "hh:mm" long_no_year: "DD MMM hh:mm" diff --git a/config/locales/client.pt_BR.yml b/config/locales/client.pt_BR.yml index 5afff3516dc..1face4d87c6 100644 --- a/config/locales/client.pt_BR.yml +++ b/config/locales/client.pt_BR.yml @@ -8,6 +8,9 @@ pt_BR: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ pt_BR: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.ro.yml b/config/locales/client.ro.yml index d0725a61de0..e081d645ec8 100644 --- a/config/locales/client.ro.yml +++ b/config/locales/client.ro.yml @@ -8,6 +8,9 @@ ro: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -20,6 +23,9 @@ ro: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "HH:mm" long_no_year: "DD MMM HH:mm" diff --git a/config/locales/client.ru.yml b/config/locales/client.ru.yml index 10a1b83c7be..0de7fca99a2 100644 --- a/config/locales/client.ru.yml +++ b/config/locales/client.ru.yml @@ -8,6 +8,9 @@ ru: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -21,6 +24,9 @@ ru: kb: КБ mb: МБ tb: ТБ + short: + thousands: "{{number}}тыс." + millions: "{{number}}млн" dates: time: "HH:mm" long_no_year: "D MMM HH:mm" diff --git a/config/locales/client.sq.yml b/config/locales/client.sq.yml index 6c5b418cbc1..ebb45125fa1 100644 --- a/config/locales/client.sq.yml +++ b/config/locales/client.sq.yml @@ -8,6 +8,9 @@ sq: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ sq: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.sv.yml b/config/locales/client.sv.yml index 5505456261d..457d588325c 100644 --- a/config/locales/client.sv.yml +++ b/config/locales/client.sv.yml @@ -8,6 +8,9 @@ sv: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ sv: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.te.yml b/config/locales/client.te.yml index 9df92b323b1..9a58660e771 100644 --- a/config/locales/client.te.yml +++ b/config/locales/client.te.yml @@ -8,6 +8,9 @@ te: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -19,6 +22,9 @@ te: kb: కేబీ mb: యంబీ tb: టీబీ + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "MMM D h:mm a" diff --git a/config/locales/client.tr_TR.yml b/config/locales/client.tr_TR.yml index 29f41d018cb..73a12b93592 100644 --- a/config/locales/client.tr_TR.yml +++ b/config/locales/client.tr_TR.yml @@ -8,6 +8,9 @@ tr_TR: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ tr_TR: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm a" long_no_year: "D MMM h:mm a" diff --git a/config/locales/client.uk.yml b/config/locales/client.uk.yml index 304aa41feab..5a50f99bbda 100644 --- a/config/locales/client.uk.yml +++ b/config/locales/client.uk.yml @@ -8,6 +8,9 @@ uk: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -20,6 +23,9 @@ uk: kb: КБ mb: МБ tb: ТБ + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "HH:mm" tiny: diff --git a/config/locales/client.zh_CN.yml b/config/locales/client.zh_CN.yml index 1918bfdbd90..a11e6155aa4 100644 --- a/config/locales/client.zh_CN.yml +++ b/config/locales/client.zh_CN.yml @@ -8,6 +8,9 @@ zh_CN: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ zh_CN: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "ah:mm" long_no_year: "MMMDoah:mm" diff --git a/config/locales/client.zh_TW.yml b/config/locales/client.zh_TW.yml index 679a2135e53..1b408dfbb30 100644 --- a/config/locales/client.zh_TW.yml +++ b/config/locales/client.zh_TW.yml @@ -8,6 +8,9 @@ zh_TW: js: number: + format: + separator: "." + delimiter: "," human: storage_units: format: '%n %u' @@ -18,6 +21,9 @@ zh_TW: kb: KB mb: MB tb: TB + short: + thousands: "{{number}}k" + millions: "{{number}}M" dates: time: "h:mm" long_no_year: "MMM D h:mm a" diff --git a/test/javascripts/lib/formatter-test.js.es6 b/test/javascripts/lib/formatter-test.js.es6 index b0c00623720..20a966f6161 100644 --- a/test/javascripts/lib/formatter-test.js.es6 +++ b/test/javascripts/lib/formatter-test.js.es6 @@ -203,6 +203,7 @@ test("breakUp", function(){ test("number", function() { equal(Discourse.Formatter.number(123), "123", "it returns a string version of the number"); equal(Discourse.Formatter.number("123"), "123", "it works with a string command"); - equal(Discourse.Formatter.number(NaN), "0", "it reeturns 0 for NaN"); - equal(Discourse.Formatter.number(3333), "3.3K", "it abbreviates thousands"); + equal(Discourse.Formatter.number(NaN), "0", "it returns 0 for NaN"); + equal(Discourse.Formatter.number(3333), "3.3k", "it abbreviates thousands"); + equal(Discourse.Formatter.number(2499999), "2.5M", "it abbreviates millions"); });