Skip to content

Commit

Permalink
LibUnicode: Remove Unicode locale variants from CLDR path names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trflynn89 authored and linusg committed Sep 6, 2021
1 parent 3f64a14 commit 4ad2159
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -425,15 +444,23 @@ 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);
}

while (numbers_iterator.has_next()) {
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);
}
}
Expand Down

0 comments on commit 4ad2159

Please sign in to comment.