mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:27:35 +00:00
LibJS+LibUnicode: Generate all styles of currency localizations
Currently, LibUnicode is only parsing and generating the "long" style of currency display names. However, the CLDR contains "short" and "narrow" forms as well that need to be handled. Parse these, and update LibJS to actually respect the "style" option provided by the user for displaying currencies with Intl.DisplayNames. Note: There are some discrepencies between the engines on how style is handled. In particular, running: new Intl.DisplayNames('en', {type:'currency', style:'narrow'}).of('usd') Gives: SpiderMoney: "USD" V8: "US Dollar" LibJS: "$" And running: new Intl.DisplayNames('en', {type:'currency', style:'short'}).of('usd') Gives: SpiderMonkey: "$" V8: "US Dollar" LibJS: "$" My best guess is V8 isn't handling style, and just returning the long form (which is what LibJS did before this commit). And SpiderMoney can handle some styles, but if they don't have a value for the requested style, they fall back to the canonicalized code passed into of().
This commit is contained in:
parent
6cfd63e5bd
commit
39e031c4dd
5 changed files with 98 additions and 24 deletions
|
@ -74,18 +74,48 @@ describe("correct behavior", () => {
|
|||
expect(zhHant.of("Aaaa")).toBe("Aaaa");
|
||||
});
|
||||
|
||||
test("option type currency", () => {
|
||||
const en = new Intl.DisplayNames("en", { type: "currency" });
|
||||
test("option type currency, style long", () => {
|
||||
const en = new Intl.DisplayNames("en", { type: "currency", style: "long" });
|
||||
expect(en.of("USD")).toBe("US Dollar");
|
||||
|
||||
const es419 = new Intl.DisplayNames("es-419", { type: "currency" });
|
||||
const es419 = new Intl.DisplayNames("es-419", { type: "currency", style: "long" });
|
||||
expect(es419.of("USD")).toBe("dólar estadounidense");
|
||||
|
||||
const zhHant = new Intl.DisplayNames(["zh-Hant"], { type: "currency" });
|
||||
const zhHant = new Intl.DisplayNames(["zh-Hant"], { type: "currency", style: "long" });
|
||||
expect(zhHant.of("USD")).toBe("美元");
|
||||
|
||||
expect(en.of("AAA")).toBe("AAA");
|
||||
expect(es419.of("AAA")).toBe("AAA");
|
||||
expect(zhHant.of("AAA")).toBe("AAA");
|
||||
});
|
||||
|
||||
test("option type currency, style short", () => {
|
||||
const en = new Intl.DisplayNames("en", { type: "currency", style: "short" });
|
||||
expect(en.of("USD")).toBe("$");
|
||||
|
||||
const es419 = new Intl.DisplayNames("es-419", { type: "currency", style: "short" });
|
||||
expect(es419.of("USD")).toBe("USD");
|
||||
|
||||
const zhHant = new Intl.DisplayNames(["zh-Hant"], { type: "currency", style: "short" });
|
||||
expect(zhHant.of("USD")).toBe("US$");
|
||||
|
||||
expect(en.of("AAA")).toBe("AAA");
|
||||
expect(es419.of("AAA")).toBe("AAA");
|
||||
expect(zhHant.of("AAA")).toBe("AAA");
|
||||
});
|
||||
|
||||
test("option type currency, style narrow", () => {
|
||||
const en = new Intl.DisplayNames("en", { type: "currency", style: "narrow" });
|
||||
expect(en.of("USD")).toBe("$");
|
||||
|
||||
const es419 = new Intl.DisplayNames("es-419", { type: "currency", style: "narrow" });
|
||||
expect(es419.of("USD")).toBe("$");
|
||||
|
||||
const zhHant = new Intl.DisplayNames(["zh-Hant"], { type: "currency", style: "narrow" });
|
||||
expect(zhHant.of("USD")).toBe("$");
|
||||
|
||||
expect(en.of("AAA")).toBe("AAA");
|
||||
expect(es419.of("AAA")).toBe("AAA");
|
||||
expect(zhHant.of("AAA")).toBe("AAA");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue