Skip to content

Commit

Permalink
Localize the format of numbers in translated strings (close #7993)
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Sep 15, 2020
1 parent 007cc1d commit f28d41b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/core/localizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,19 @@ export function coreLocalizer() {
}
}
if (typeof result === 'string') {
for (let k in replacements) {
const token = `{${k}}`;
for (let key in replacements) {
let value = replacements[key];
if (typeof value === 'number' && value.toLocaleString) {
// format numbers for the locale
value = value.toLocaleString(locale, {
style: 'decimal',
useGrouping: true,
minimumFractionDigits: 0
});
}
const token = `{${key}}`;
const regex = new RegExp(token, 'g');
result = result.replace(regex, replacements[k]);
result = result.replace(regex, value);
}
}
}
Expand Down

0 comments on commit f28d41b

Please sign in to comment.