mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibJS: Extend Intl.DisplayNames.of to support language tags
This commit is contained in:
parent
ab7a1dd89e
commit
ca77a7c573
Notes:
sideshowbarker
2024-07-18 05:13:56 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/ca77a7c5731 Pull-request: https://github.com/SerenityOS/serenity/pull/9622 Reviewed-by: https://github.com/linusg
2 changed files with 16 additions and 0 deletions
|
@ -77,6 +77,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
|
|||
|
||||
switch (display_names->type()) {
|
||||
case DisplayNames::Type::Language:
|
||||
result = Unicode::get_locale_language_mapping(display_names->locale(), code.as_string().string());
|
||||
break;
|
||||
case DisplayNames::Type::Region:
|
||||
result = Unicode::get_locale_territory_mapping(display_names->locale(), code.as_string().string());
|
||||
|
|
|
@ -29,6 +29,21 @@ describe("correct behavior", () => {
|
|||
expect(Intl.DisplayNames.prototype.of).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("option type language", () => {
|
||||
const en = new Intl.DisplayNames("en", { type: "language" });
|
||||
expect(en.of("en")).toBe("English");
|
||||
|
||||
const es419 = new Intl.DisplayNames("es-419", { type: "language" });
|
||||
expect(es419.of("en")).toBe("inglés");
|
||||
|
||||
const zhHant = new Intl.DisplayNames(["zh-Hant"], { type: "language" });
|
||||
expect(zhHant.of("en")).toBe("英文");
|
||||
|
||||
expect(en.of("zz")).toBe("zz");
|
||||
expect(es419.of("zz")).toBe("zz");
|
||||
expect(zhHant.of("zz")).toBe("zz");
|
||||
});
|
||||
|
||||
test("option type region", () => {
|
||||
const en = new Intl.DisplayNames("en", { type: "region" });
|
||||
expect(en.of("US")).toBe("United States");
|
||||
|
|
Loading…
Reference in a new issue