Skip to content

Commit

Permalink
LibUnicode: Canonicalize the subtag "primary" and "tertiary" to "levelN"
Browse files Browse the repository at this point in the history
  • Loading branch information
trflynn89 authored and linusg committed Sep 1, 2021
1 parent 409f39b commit 2d90144
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Tests/LibUnicode/TestUnicodeLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ TEST_CASE(canonicalize_unicode_locale_id)
test("EN-U-KA-YES"sv, "en-u-ka-yes"sv);
test("en-u-1k-names"sv, "en-u-1k-names"sv);
test("EN-U-1K-NAMES"sv, "en-u-1k-names"sv);
test("en-u-ks-primary"sv, "en-u-ks-level1"sv);
test("EN-U-KS-PRIMARY"sv, "en-u-ks-level1"sv);
test("en-u-ka-primary"sv, "en-u-ka-primary"sv);
test("EN-U-KA-PRIMARY"sv, "en-u-ka-primary"sv);

test("en-t-en"sv, "en-t-en"sv);
test("EN-T-EN"sv, "en-t-en"sv);
Expand All @@ -327,6 +331,8 @@ TEST_CASE(canonicalize_unicode_locale_id)
test("EN-T-M0-NAMES"sv, "en-t-m0-prprname"sv);
test("en-t-k1-names"sv, "en-t-k1-names"sv);
test("EN-T-K1-NAMES"sv, "en-t-k1-names"sv);
test("en-t-k1-primary"sv, "en-t-k1-primary"sv);
test("EN-T-K1-PRIMARY"sv, "en-t-k1-primary"sv);

test("en-0-aaa"sv, "en-0-aaa"sv);
test("EN-0-AAA"sv, "en-0-aaa"sv);
Expand Down
12 changes: 10 additions & 2 deletions Userland/Libraries/LibUnicode/Locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,18 @@ static void perform_hard_coded_key_value_substitutions(String& key, String& valu
//
// There doesn't seem to be a counterpart in the JSON export. Since there aren't many such
// aliases, until an XML parser is implemented, those aliases are implemented here.
if (key.is_one_of("kb"sv, "kc"sv, "kh"sv, "kk"sv, "kn"sv) && (value == "yes"sv))
if (key.is_one_of("kb"sv, "kc"sv, "kh"sv, "kk"sv, "kn"sv) && (value == "yes"sv)) {
value = "true"sv;
else if ((key == "m0"sv) && (value == "names"sv))
} else if (key == "ks"sv) {
if (value == "primary"sv)
value = "level1"sv;
else if (value == "tertiary"sv)
value = "level3"sv;
// Note: There are also aliases for "secondary", "quaternary", "quarternary", and "identical",
// but those are semantically incorrect values (they are too long), so they can be skipped.
} else if ((key == "m0"sv) && (value == "names"sv)) {
value = "prprname"sv;
}
}

static void transform_unicode_locale_id_to_canonical_syntax(LocaleID& locale_id)
Expand Down

0 comments on commit 2d90144

Please sign in to comment.