LibJS: Extend Intl.DisplayNames.of to support script tags

This commit is contained in:
Timothy Flynn 2021-08-26 08:30:12 -04:00 committed by Linus Groh
parent 0f02def3c2
commit a029e3d38a
Notes: sideshowbarker 2024-07-18 05:13:48 +09:00
2 changed files with 16 additions and 0 deletions

View file

@ -83,6 +83,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
result = Unicode::get_locale_territory_mapping(display_names->locale(), code.as_string().string());
break;
case DisplayNames::Type::Script:
result = Unicode::get_locale_script_mapping(display_names->locale(), code.as_string().string());
break;
case DisplayNames::Type::Currency:
break;

View file

@ -58,4 +58,19 @@ describe("correct behavior", () => {
expect(es419.of("AA")).toBe("AA");
expect(zhHant.of("AA")).toBe("AA");
});
test("option type script", () => {
const en = new Intl.DisplayNames("en", { type: "script" });
expect(en.of("Latn")).toBe("Latin");
const es419 = new Intl.DisplayNames("es-419", { type: "script" });
expect(es419.of("Latn")).toBe("latín");
const zhHant = new Intl.DisplayNames(["zh-Hant"], { type: "script" });
expect(zhHant.of("Latn")).toBe("拉丁文");
expect(en.of("Aaaa")).toBe("Aaaa");
expect(es419.of("Aaaa")).toBe("Aaaa");
expect(zhHant.of("Aaaa")).toBe("Aaaa");
});
});