1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Merge pull request #416 from Astavie/master

Add decimal separator option in translation files
This commit is contained in:
tobspr
2020-07-07 19:40:27 +02:00
committed by GitHub
30 changed files with 101 additions and 9 deletions

View File

@@ -413,10 +413,10 @@ function roundSmart(n) {
/**
* Formats a big number
* @param {number} num
* @param {string=} divider THe divider for numbers like 50,000 (divider=',')
* @param {string=} separator The decimal separator for numbers like 50.1 (separator='.')
* @returns {string}
*/
export function formatBigNumber(num, divider = ".") {
export function formatBigNumber(num, separator = T.global.decimalSeparator) {
const sign = num < 0 ? "-" : "";
num = Math.abs(num);
@@ -445,7 +445,10 @@ export function formatBigNumber(num, divider = ".") {
}
}
const leadingDigitsRounded = round1Digit(leadingDigits);
const leadingDigitsNoTrailingDecimal = leadingDigitsRounded.toString().replace(".0", "");
const leadingDigitsNoTrailingDecimal = leadingDigitsRounded
.toString()
.replace(".0", "")
.replace(".", separator);
return sign + leadingDigitsNoTrailingDecimal + suffix;
}
}
@@ -453,7 +456,7 @@ export function formatBigNumber(num, divider = ".") {
/**
* Formats a big number, but does not add any suffix and instead uses its full representation
* @param {number} num
* @param {string=} divider THe divider for numbers like 50,000 (divider=',')
* @param {string=} divider The divider for numbers like 50,000 (divider=',')
* @returns {string}
*/
export function formatBigNumberFull(num, divider = T.global.thousandsDivider) {
@@ -954,10 +957,13 @@ export function capitalizeFirstLetter(str) {
* Formats a number like 2.5 to "2.5 items / s"
* @param {number} speed
* @param {boolean=} double
* @param {string=} separator The decimal separator for numbers like 50.1 (separator='.')
*/
export function formatItemsPerSecond(speed, double = false) {
export function formatItemsPerSecond(speed, double = false, separator = T.global.decimalSeparator) {
return speed === 1.0
? T.ingame.buildingPlacement.infoTexts.oneItemPerSecond
: T.ingame.buildingPlacement.infoTexts.itemsPerSecond.replace("<x>", "" + round2Digits(speed)) +
(double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "");
: T.ingame.buildingPlacement.infoTexts.itemsPerSecond.replace(
"<x>",
round2Digits(speed).toString().replace(".", separator)
) + (double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "");
}