mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:47:35 +00:00
LibJS: Allow specifying keyword values not directly defined for a locale
For example, consider the locales "en-u-nu-fullwide" or "en-u-nu-arab". The CLDR only declares the "latn" numbering system for the "en" locale, thus ResolveLocale would change the locale to "en-u-nu-latn". This patch allows using non-latn numbering systems digits.
This commit is contained in:
parent
b24b9c0a65
commit
aafcdc4c72
6 changed files with 42 additions and 12 deletions
|
@ -207,6 +207,21 @@ describe("style=decimal", () => {
|
|||
expect(en.format(12000000)).toBe("12 million");
|
||||
expect(en.format(12900000)).toBe("13 million");
|
||||
|
||||
const enFullwide = new Intl.NumberFormat("en", {
|
||||
notation: "compact",
|
||||
compactDisplay: "long",
|
||||
numberingSystem: "fullwide",
|
||||
});
|
||||
expect(enFullwide.format(1)).toBe("1");
|
||||
expect(enFullwide.format(1200)).toBe("1.2 thousand");
|
||||
expect(enFullwide.format(1290)).toBe("1.3 thousand");
|
||||
expect(enFullwide.format(12000)).toBe("12 thousand");
|
||||
expect(enFullwide.format(12900)).toBe("13 thousand");
|
||||
expect(enFullwide.format(1200000)).toBe("1.2 million");
|
||||
expect(enFullwide.format(1290000)).toBe("1.3 million");
|
||||
expect(enFullwide.format(12000000)).toBe("12 million");
|
||||
expect(enFullwide.format(12900000)).toBe("13 million");
|
||||
|
||||
const ar = new Intl.NumberFormat("ar", { notation: "compact", compactDisplay: "long" });
|
||||
expect(ar.format(1)).toBe("\u0661");
|
||||
expect(ar.format(1200)).toBe("\u0661\u066b\u0662 ألف");
|
||||
|
@ -579,6 +594,19 @@ describe("style=percent", () => {
|
|||
expect(en.format(0.123)).toBe("12%");
|
||||
expect(en.format(0.1234)).toBe("12%");
|
||||
|
||||
const enFullwide = new Intl.NumberFormat("en", {
|
||||
style: "percent",
|
||||
notation: "compact",
|
||||
numberingSystem: "fullwide",
|
||||
});
|
||||
expect(enFullwide.format(0.01)).toBe("1%");
|
||||
expect(enFullwide.format(0.012)).toBe("1.2%");
|
||||
expect(enFullwide.format(0.0123)).toBe("1.2%");
|
||||
expect(enFullwide.format(0.0129)).toBe("1.3%");
|
||||
expect(enFullwide.format(0.12)).toBe("12%");
|
||||
expect(enFullwide.format(0.123)).toBe("12%");
|
||||
expect(enFullwide.format(0.1234)).toBe("12%");
|
||||
|
||||
const ar = new Intl.NumberFormat("ar", { style: "percent", notation: "compact" });
|
||||
expect(ar.format(0.01)).toBe("\u0661\u066a\u061c");
|
||||
expect(ar.format(0.012)).toBe("\u0661\u066b\u0662\u066a\u061c");
|
||||
|
|
|
@ -36,12 +36,12 @@ describe("correct behavior", () => {
|
|||
});
|
||||
|
||||
test("numberingSystem option limited to known 'nu' values", () => {
|
||||
["latn", "arab"].forEach(numberingSystem => {
|
||||
["latn", "foo"].forEach(numberingSystem => {
|
||||
const en = Intl.NumberFormat("en", { numberingSystem: numberingSystem });
|
||||
expect(en.resolvedOptions().numberingSystem).toBe("latn");
|
||||
});
|
||||
|
||||
["latn", "arab"].forEach(numberingSystem => {
|
||||
["latn", "foo"].forEach(numberingSystem => {
|
||||
const en = Intl.NumberFormat(`en-u-nu-${numberingSystem}`);
|
||||
expect(en.resolvedOptions().numberingSystem).toBe("latn");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue