Skip to content

Commit cd40ddd

Browse files
committed
Arabic translation enhancement: Hide unit count with dual forms.
1 parent 4373d00 commit cd40ddd

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

humanize-duration.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@
186186
),
187187
{
188188
delimiter: " ﻭ ",
189-
_digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
189+
hideUnitInDualForm: true,
190+
_digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"],
190191
}
191192
),
192193
bg: language(
@@ -1655,10 +1656,21 @@
16551656
/** @type {undefined | DigitReplacements} */
16561657
var digitReplacements;
16571658
if ("digitReplacements" in options) {
1658-
digitReplacements = options.digitReplacements;
1659+
digitReplacements = options.digitReplacements;
16591660
} else if ("_digitReplacements" in language) {
1660-
digitReplacements = language._digitReplacements;
1661+
digitReplacements = language._digitReplacements;
16611662
}
1663+
1664+
/** @type {boolean} */
1665+
var hideUnitInDualForm = false;
1666+
if (options.language === "ar") {
1667+
if ("arabic_hideUnitInDualForm" in options) {
1668+
hideUnitInDualForm = options.arabic_hideUnitInDualForm;
1669+
} else if ("hideUnitInDualForm" in language) {
1670+
hideUnitInDualForm = language.hideUnitInDualForm;
1671+
}
1672+
}
1673+
16621674

16631675
/** @type {string} */
16641676
var formattedCount;
@@ -1668,20 +1680,24 @@
16681680
: Math.floor(unitCount * Math.pow(10, maxDecimalPoints)) /
16691681
Math.pow(10, maxDecimalPoints);
16701682
var countStr = normalizedUnitCount.toString();
1671-
if (digitReplacements) {
1672-
formattedCount = "";
1673-
for (var i = 0; i < countStr.length; i++) {
1674-
var char = countStr[i];
1675-
if (char === ".") {
1676-
formattedCount += decimal;
1677-
} else {
1678-
// @ts-ignore because `char` should always be 0-9 at this point.
1679-
formattedCount += digitReplacements[char];
1680-
}
1681-
}
1682-
} else {
1683-
formattedCount = countStr.replace(".", decimal);
1684-
}
1683+
if (!hideUnitInDualForm || unitCount !== 2) {
1684+
if (digitReplacements) {
1685+
formattedCount = "";
1686+
for (var i = 0; i < countStr.length; i++) {
1687+
var char = countStr[i];
1688+
if (char === ".") {
1689+
formattedCount += decimal;
1690+
} else {
1691+
// @ts-ignore because `char` should always be 0-9 at this point.
1692+
formattedCount += digitReplacements[char];
1693+
}
1694+
}
1695+
} else {
1696+
formattedCount = countStr.replace(".", decimal);
1697+
}
1698+
} else {
1699+
formattedCount = "";
1700+
}
16851701

16861702
var languageWord = language[unitName];
16871703
var word;

0 commit comments

Comments
 (0)