Skip to content

Commit

Permalink
Use Number() instead of parseInt, so we can handle floats in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence committed Mar 30, 2017
1 parent 11d89da commit 4e96e61
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ module.exports = (function() {
args.unshift(count);

// some template engines pass all values as strings -> so we try to convert them to numbers
if (typeof plural === 'number' || parseInt(plural, 10) + '' === plural) {
if (typeof plural === 'number' || Number(plural) + '' === plural) {
count = plural;
}

Expand All @@ -335,7 +335,7 @@ module.exports = (function() {
}
} else {
// called like __n('cat', 3)
if (typeof plural === 'number' || parseInt(plural, 10) + '' === plural) {
if (typeof plural === 'number' || Number(plural) + '' === plural) {
count = plural;

// we add same string as default
Expand All @@ -355,7 +355,7 @@ module.exports = (function() {
if (count === null) count = namedValues.count;

// enforce number
count = parseInt(count, 10);
count = Number(count);

// find the correct plural rule for given locale
if (typeof msg === 'object') {
Expand Down Expand Up @@ -535,7 +535,7 @@ module.exports = (function() {

// replace the counter
if (typeof count === 'number') {
msg = vsprintf(msg, [parseInt(count, 10)]);
msg = vsprintf(msg, [count]);
}

// if the msg string contains {{Mustache}} patterns we render it as a mini tempalate
Expand Down

0 comments on commit 4e96e61

Please sign in to comment.