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
This commit is contained in:
Gerhard Schlager 2015-06-25 23:33:50 +02:00
parent fc090b4568
commit d08693edce
31 changed files with 183 additions and 4 deletions

View File

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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 "

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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:

View File

@ -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"

View File

@ -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"

View File

@ -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");
});