diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-09-06 15:33:56 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-06 23:49:56 +0100 |
commit | 4ad2159812014fafb94eb7978432a9df6f5cec90 (patch) | |
tree | 1f97ddaad8c06edd3242744622e9c067232114c6 /Meta/Lagom | |
parent | 3f64a14e0628051935c83a59da5e049a82610138 (diff) | |
download | serenity-4ad2159812014fafb94eb7978432a9df6f5cec90.zip |
LibUnicode: Remove Unicode locale variants from CLDR path names
There's only a couple of cases like this, but there are some locale
paths in the CLDR that contain variants. For example, there isn't a
en-US path, but there is a en-US-POSIX path. This interferes with the
operation to search for locales by name. The algorithm is such that
searching for en-US will not result in en-US-POSIX being found. To
resolve this, we should remove variants from the locale name.
Diffstat (limited to 'Meta/Lagom')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp index 8ce12799de..8587989366 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp @@ -410,11 +410,30 @@ static void parse_all_locales(String core_path, String locale_names_path, String parse_core_aliases(core_supplemental_path.string(), locale_data); parse_likely_subtags(core_supplemental_path.string(), locale_data); + auto remove_variants_from_path = [](String path) -> Optional<String> { + auto parsed_locale = parse_language(LexicalPath::basename(path)); + if (!parsed_locale.has_value()) + return {}; + + StringBuilder builder; + builder.append(parsed_locale->language); + if (!parsed_locale->script.is_empty()) + builder.appendff("-{}", parsed_locale->script); + if (!parsed_locale->region.is_empty()) + builder.appendff("-{}", parsed_locale->region); + + return builder.build(); + }; + while (locale_names_iterator.has_next()) { auto locale_path = locale_names_iterator.next_full_path(); VERIFY(Core::File::is_directory(locale_path)); - auto& locale = locale_data.locales.ensure(LexicalPath::basename(locale_path)); + auto language = remove_variants_from_path(locale_path); + if (!language.has_value()) + continue; + + auto& locale = locale_data.locales.ensure(*language); parse_identity(locale_path, locale_data, locale); parse_locale_languages(locale_path, locale); parse_locale_territories(locale_path, locale); @@ -425,7 +444,11 @@ static void parse_all_locales(String core_path, String locale_names_path, String auto misc_path = misc_iterator.next_full_path(); VERIFY(Core::File::is_directory(misc_path)); - auto& locale = locale_data.locales.ensure(LexicalPath::basename(misc_path)); + auto language = remove_variants_from_path(misc_path); + if (!language.has_value()) + continue; + + auto& locale = locale_data.locales.ensure(*language); parse_locale_list_patters(misc_path, locale_data, locale); } @@ -433,7 +456,11 @@ static void parse_all_locales(String core_path, String locale_names_path, String auto numbers_path = numbers_iterator.next_full_path(); VERIFY(Core::File::is_directory(numbers_path)); - auto& locale = locale_data.locales.ensure(LexicalPath::basename(numbers_path)); + auto language = remove_variants_from_path(numbers_path); + if (!language.has_value()) + continue; + + auto& locale = locale_data.locales.ensure(*language); parse_locale_currencies(numbers_path, locale_data, locale); } } |