From 287d43f4be45871495aa4ea771f417c32c1f3786 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 28 Nov 2021 09:25:15 -0500 Subject: [PATCH] LibUnicode: Hard-code an alias from the Gregorian calendar to Gregory This alias exists because the name "Gregorian" is too long to be used in a locale identifier, i.e. "en-u-ca-gregorian" is invalid. Aliases for calendars are defined here: https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-bcp47/bcp47/calendar.json However, CLDR version 40 neglected to actually include the cldr-bcp47 package in its release, so we don't have access to this data. So for now hard-code this alias so that JavaScript can actually access it. See: https://unicode-org.atlassian.net/browse/CLDR-15158 --- .../LibUnicode/GenerateUnicodeDateTimeFormat.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index c15c6f8f1eb..8966be7b55f 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp @@ -47,7 +47,12 @@ struct Locale { struct UnicodeLocaleData { UniqueStringStorage unique_strings; HashMap locales; + Vector calendars; + Vector calendar_aliases { + // FIXME: Aliases should come from BCP47. See: https://unicode-org.atlassian.net/browse/CLDR-15158 + { "gregorian"sv, "gregory"sv }, + }; }; static void parse_date_time_pattern(CalendarPattern& format, String pattern, UnicodeLocaleData& locale_data) @@ -167,7 +172,7 @@ static void generate_unicode_locale_header(Core::File& file, UnicodeLocaleData& namespace Unicode { )~~~"); - generate_enum(generator, format_identifier, "Calendar"sv, {}, locale_data.calendars); + generate_enum(generator, format_identifier, "Calendar"sv, {}, locale_data.calendars, locale_data.calendar_aliases); generator.append(R"~~~( namespace Detail { @@ -286,17 +291,19 @@ static constexpr Array @name@ { {)~~~"); generate_mapping(generator, locale_data.locales, "CalendarData"sv, "s_calendars"sv, "s_calendars_{}", [&](auto const& name, auto const& value) { append_calendars(name, value.calendars); }); - auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values) { + auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, auto const& aliases) { HashValueMap hashes; hashes.ensure_capacity(values.size()); for (auto const& value : values) hashes.set(value.hash(), format_identifier(enum_title, value)); + for (auto const& alias : aliases) + hashes.set(alias.alias.hash(), format_identifier(enum_title, alias.alias)); generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes)); }; - append_from_string("Calendar"sv, "calendar"sv, locale_data.calendars); + append_from_string("Calendar"sv, "calendar"sv, locale_data.calendars, locale_data.calendar_aliases); generator.append(R"~~~( static CalendarData const* find_calendar_data(StringView locale, StringView calendar)