GenerateNumberFormatData.cpp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. /*
  2. * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
  7. #include <AK/AllOf.h>
  8. #include <AK/Array.h>
  9. #include <AK/ByteString.h>
  10. #include <AK/CharacterTypes.h>
  11. #include <AK/Find.h>
  12. #include <AK/Format.h>
  13. #include <AK/HashFunctions.h>
  14. #include <AK/HashMap.h>
  15. #include <AK/JsonObject.h>
  16. #include <AK/JsonParser.h>
  17. #include <AK/JsonValue.h>
  18. #include <AK/LexicalPath.h>
  19. #include <AK/QuickSort.h>
  20. #include <AK/SourceGenerator.h>
  21. #include <AK/StringBuilder.h>
  22. #include <AK/Traits.h>
  23. #include <AK/Utf8View.h>
  24. #include <LibCore/ArgsParser.h>
  25. #include <LibCore/Directory.h>
  26. #include <LibFileSystem/FileSystem.h>
  27. #include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
  28. #include <LibLocale/Locale.h>
  29. #include <LibLocale/NumberFormat.h>
  30. #include <LibLocale/PluralRules.h>
  31. #include <math.h>
  32. enum class NumberFormatType {
  33. Standard,
  34. Compact,
  35. };
  36. struct NumberFormat : public Locale::NumberFormat {
  37. using Base = Locale::NumberFormat;
  38. unsigned hash() const
  39. {
  40. auto hash = pair_int_hash(magnitude, exponent);
  41. hash = pair_int_hash(hash, to_underlying(plurality));
  42. hash = pair_int_hash(hash, zero_format_index);
  43. hash = pair_int_hash(hash, positive_format_index);
  44. hash = pair_int_hash(hash, negative_format_index);
  45. for (auto index : identifier_indices)
  46. hash = pair_int_hash(hash, index);
  47. return hash;
  48. }
  49. bool operator==(NumberFormat const& other) const
  50. {
  51. return (magnitude == other.magnitude)
  52. && (exponent == other.exponent)
  53. && (plurality == other.plurality)
  54. && (zero_format_index == other.zero_format_index)
  55. && (positive_format_index == other.positive_format_index)
  56. && (negative_format_index == other.negative_format_index)
  57. && (identifier_indices == other.identifier_indices);
  58. }
  59. size_t zero_format_index { 0 };
  60. size_t positive_format_index { 0 };
  61. size_t negative_format_index { 0 };
  62. Vector<size_t> identifier_indices {};
  63. };
  64. template<>
  65. struct AK::Formatter<NumberFormat> : Formatter<FormatString> {
  66. ErrorOr<void> format(FormatBuilder& builder, NumberFormat const& format)
  67. {
  68. StringBuilder identifier_indices;
  69. identifier_indices.join(", "sv, format.identifier_indices);
  70. return Formatter<FormatString>::format(builder,
  71. "{{ {}, {}, {}, {}, {}, {}, {{ {} }} }}"sv,
  72. format.magnitude,
  73. format.exponent,
  74. to_underlying(format.plurality),
  75. format.zero_format_index,
  76. format.positive_format_index,
  77. format.negative_format_index,
  78. identifier_indices.to_byte_string());
  79. }
  80. };
  81. template<>
  82. struct AK::Traits<NumberFormat> : public DefaultTraits<NumberFormat> {
  83. static unsigned hash(NumberFormat const& f) { return f.hash(); }
  84. };
  85. using NumberFormatList = Vector<size_t>;
  86. using NumericSymbolList = Vector<size_t>;
  87. struct NumberSystem {
  88. unsigned hash() const
  89. {
  90. auto hash = int_hash(symbols);
  91. hash = pair_int_hash(hash, primary_grouping_size);
  92. hash = pair_int_hash(hash, secondary_grouping_size);
  93. hash = pair_int_hash(hash, decimal_format);
  94. hash = pair_int_hash(hash, decimal_long_formats);
  95. hash = pair_int_hash(hash, decimal_short_formats);
  96. hash = pair_int_hash(hash, currency_format);
  97. hash = pair_int_hash(hash, accounting_format);
  98. hash = pair_int_hash(hash, currency_unit_formats);
  99. hash = pair_int_hash(hash, percent_format);
  100. hash = pair_int_hash(hash, scientific_format);
  101. return hash;
  102. }
  103. bool operator==(NumberSystem const& other) const
  104. {
  105. return (symbols == other.symbols)
  106. && (primary_grouping_size == other.primary_grouping_size)
  107. && (secondary_grouping_size == other.secondary_grouping_size)
  108. && (decimal_format == other.decimal_format)
  109. && (decimal_long_formats == other.decimal_long_formats)
  110. && (decimal_short_formats == other.decimal_short_formats)
  111. && (currency_format == other.currency_format)
  112. && (accounting_format == other.accounting_format)
  113. && (currency_unit_formats == other.currency_unit_formats)
  114. && (percent_format == other.percent_format)
  115. && (scientific_format == other.scientific_format);
  116. }
  117. size_t symbols { 0 };
  118. u8 primary_grouping_size { 0 };
  119. u8 secondary_grouping_size { 0 };
  120. size_t decimal_format { 0 };
  121. size_t decimal_long_formats { 0 };
  122. size_t decimal_short_formats { 0 };
  123. size_t currency_format { 0 };
  124. size_t accounting_format { 0 };
  125. size_t currency_unit_formats { 0 };
  126. size_t percent_format { 0 };
  127. size_t scientific_format { 0 };
  128. };
  129. template<>
  130. struct AK::Formatter<NumberSystem> : Formatter<FormatString> {
  131. ErrorOr<void> format(FormatBuilder& builder, NumberSystem const& system)
  132. {
  133. return Formatter<FormatString>::format(builder,
  134. "{{ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} }}"sv,
  135. system.symbols,
  136. system.primary_grouping_size,
  137. system.secondary_grouping_size,
  138. system.decimal_format,
  139. system.decimal_long_formats,
  140. system.decimal_short_formats,
  141. system.currency_format,
  142. system.accounting_format,
  143. system.currency_unit_formats,
  144. system.percent_format,
  145. system.scientific_format);
  146. }
  147. };
  148. template<>
  149. struct AK::Traits<NumberSystem> : public DefaultTraits<NumberSystem> {
  150. static unsigned hash(NumberSystem const& s) { return s.hash(); }
  151. };
  152. struct Unit {
  153. unsigned hash() const
  154. {
  155. auto hash = int_hash(unit);
  156. hash = pair_int_hash(hash, long_formats);
  157. hash = pair_int_hash(hash, short_formats);
  158. hash = pair_int_hash(hash, narrow_formats);
  159. return hash;
  160. }
  161. bool operator==(Unit const& other) const
  162. {
  163. return (unit == other.unit)
  164. && (long_formats == other.long_formats)
  165. && (short_formats == other.short_formats)
  166. && (narrow_formats == other.narrow_formats);
  167. }
  168. size_t unit { 0 };
  169. size_t long_formats { 0 };
  170. size_t short_formats { 0 };
  171. size_t narrow_formats { 0 };
  172. };
  173. template<>
  174. struct AK::Formatter<Unit> : Formatter<FormatString> {
  175. ErrorOr<void> format(FormatBuilder& builder, Unit const& system)
  176. {
  177. return Formatter<FormatString>::format(builder,
  178. "{{ {}, {}, {}, {} }}"sv,
  179. system.unit,
  180. system.long_formats,
  181. system.short_formats,
  182. system.narrow_formats);
  183. }
  184. };
  185. template<>
  186. struct AK::Traits<Unit> : public DefaultTraits<Unit> {
  187. static unsigned hash(Unit const& u) { return u.hash(); }
  188. };
  189. struct LocaleData {
  190. Vector<size_t> number_systems;
  191. HashMap<ByteString, size_t> units {};
  192. u8 minimum_grouping_digits { 0 };
  193. };
  194. struct CLDR {
  195. UniqueStringStorage unique_strings;
  196. UniqueStorage<NumberFormat> unique_formats;
  197. UniqueStorage<NumberFormatList> unique_format_lists;
  198. UniqueStorage<NumericSymbolList> unique_symbols;
  199. UniqueStorage<NumberSystem> unique_systems;
  200. UniqueStorage<Unit> unique_units;
  201. HashMap<ByteString, Array<u32, 10>> number_system_digits;
  202. Vector<ByteString> number_systems;
  203. HashMap<ByteString, LocaleData> locales;
  204. size_t max_identifier_count { 0 };
  205. };
  206. static ErrorOr<void> parse_number_system_digits(ByteString core_supplemental_path, CLDR& cldr)
  207. {
  208. LexicalPath number_systems_path(move(core_supplemental_path));
  209. number_systems_path = number_systems_path.append("numberingSystems.json"sv);
  210. auto number_systems = TRY(read_json_file(number_systems_path.string()));
  211. auto const& supplemental_object = number_systems.as_object().get_object("supplemental"sv).value();
  212. auto const& number_systems_object = supplemental_object.get_object("numberingSystems"sv).value();
  213. number_systems_object.for_each_member([&](auto const& number_system, auto const& digits_object) {
  214. auto type = digits_object.as_object().get_byte_string("_type"sv).value();
  215. if (type != "numeric"sv)
  216. return;
  217. auto digits = digits_object.as_object().get_byte_string("_digits"sv).value();
  218. Utf8View utf8_digits { digits };
  219. VERIFY(utf8_digits.length() == 10);
  220. auto& number_system_digits = cldr.number_system_digits.ensure(number_system);
  221. size_t index = 0;
  222. for (u32 digit : utf8_digits)
  223. number_system_digits[index++] = digit;
  224. if (!cldr.number_systems.contains_slow(number_system))
  225. cldr.number_systems.append(number_system);
  226. });
  227. return {};
  228. }
  229. static ByteString parse_identifiers(ByteString pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
  230. {
  231. static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
  232. while (true) {
  233. Utf8View utf8_pattern { pattern };
  234. Optional<size_t> start_index;
  235. Optional<size_t> end_index;
  236. bool inside_replacement = false;
  237. for (auto it = utf8_pattern.begin(); it != utf8_pattern.end(); ++it) {
  238. if (*it == '{') {
  239. if (start_index.has_value()) {
  240. end_index = utf8_pattern.byte_offset_of(it);
  241. break;
  242. }
  243. inside_replacement = true;
  244. } else if (*it == '}') {
  245. inside_replacement = false;
  246. } else if (!inside_replacement && !start_index.has_value() && !whitespace.contains(*it)) {
  247. start_index = utf8_pattern.byte_offset_of(it);
  248. }
  249. }
  250. if (!start_index.has_value())
  251. return pattern;
  252. end_index = end_index.value_or(pattern.length());
  253. utf8_pattern = utf8_pattern.substring_view(*start_index, *end_index - *start_index);
  254. utf8_pattern = utf8_pattern.trim(whitespace);
  255. auto identifier = utf8_pattern.as_string().replace("'.'"sv, "."sv, ReplaceMode::FirstOnly);
  256. auto identifier_index = cldr.unique_strings.ensure(move(identifier));
  257. size_t replacement_index = 0;
  258. if (auto index = format.identifier_indices.find_first_index(identifier_index); index.has_value()) {
  259. replacement_index = *index;
  260. } else {
  261. replacement_index = format.identifier_indices.size();
  262. format.identifier_indices.append(identifier_index);
  263. cldr.max_identifier_count = max(cldr.max_identifier_count, format.identifier_indices.size());
  264. }
  265. pattern = ByteString::formatted("{}{{{}:{}}}{}",
  266. *start_index > 0 ? pattern.substring_view(0, *start_index) : ""sv,
  267. replacement,
  268. replacement_index,
  269. pattern.substring_view(*start_index + utf8_pattern.byte_length()));
  270. }
  271. }
  272. static void parse_number_pattern(Vector<ByteString> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
  273. {
  274. // https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
  275. // https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
  276. VERIFY((patterns.size() == 1) || (patterns.size() == 2));
  277. auto replace_patterns = [&](ByteString pattern) {
  278. static HashMap<StringView, StringView> replacements = {
  279. { "{0}"sv, "{number}"sv },
  280. { "{1}"sv, "{currency}"sv },
  281. { "%"sv, "{percentSign}"sv },
  282. { "+"sv, "{plusSign}"sv },
  283. { "-"sv, "{minusSign}"sv },
  284. { "¤"sv, "{currency}"sv }, // U+00A4 Currency Sign
  285. { "E"sv, "{scientificSeparator}"sv },
  286. };
  287. for (auto const& replacement : replacements)
  288. pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
  289. if (auto start_number_index = pattern.find_any_of("#0"sv, ByteString::SearchDirection::Forward); start_number_index.has_value()) {
  290. auto end_number_index = *start_number_index + 1;
  291. for (; end_number_index < pattern.length(); ++end_number_index) {
  292. auto ch = pattern[end_number_index];
  293. if ((ch != '#') && (ch != '0') && (ch != ',') && (ch != '.'))
  294. break;
  295. }
  296. if (number_system_for_groupings) {
  297. auto number_pattern = pattern.substring_view(*start_number_index, end_number_index - *start_number_index);
  298. auto group_separators = number_pattern.find_all(","sv);
  299. VERIFY((group_separators.size() == 1) || (group_separators.size() == 2));
  300. auto decimal = number_pattern.find('.');
  301. VERIFY(decimal.has_value());
  302. if (group_separators.size() == 1) {
  303. number_system_for_groupings->primary_grouping_size = *decimal - group_separators[0] - 1;
  304. number_system_for_groupings->secondary_grouping_size = number_system_for_groupings->primary_grouping_size;
  305. } else {
  306. number_system_for_groupings->primary_grouping_size = *decimal - group_separators[1] - 1;
  307. number_system_for_groupings->secondary_grouping_size = group_separators[1] - group_separators[0] - 1;
  308. }
  309. }
  310. pattern = ByteString::formatted("{}{{number}}{}",
  311. *start_number_index > 0 ? pattern.substring_view(0, *start_number_index) : ""sv,
  312. pattern.substring_view(end_number_index));
  313. // This is specifically handled here rather than in the replacements HashMap above so
  314. // that we do not errantly replace zeroes in number patterns.
  315. if (pattern.contains(*replacements.get("E"sv)))
  316. pattern = pattern.replace("0"sv, "{scientificExponent}"sv, ReplaceMode::FirstOnly);
  317. }
  318. if (type == NumberFormatType::Compact)
  319. return parse_identifiers(move(pattern), "compactIdentifier"sv, cldr, format);
  320. return pattern;
  321. };
  322. auto zero_format = replace_patterns(move(patterns[0]));
  323. format.positive_format_index = cldr.unique_strings.ensure(ByteString::formatted("{{plusSign}}{}", zero_format));
  324. if (patterns.size() == 2) {
  325. auto negative_format = replace_patterns(move(patterns[1]));
  326. format.negative_format_index = cldr.unique_strings.ensure(move(negative_format));
  327. } else {
  328. format.negative_format_index = cldr.unique_strings.ensure(ByteString::formatted("{{minusSign}}{}", zero_format));
  329. }
  330. format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
  331. }
  332. static void parse_number_pattern(Vector<ByteString> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
  333. {
  334. NumberFormat format {};
  335. parse_number_pattern(move(patterns), cldr, type, format, number_system_for_groupings);
  336. format_index = cldr.unique_formats.ensure(move(format));
  337. }
  338. static ErrorOr<void> parse_number_systems(ByteString locale_numbers_path, CLDR& cldr, LocaleData& locale)
  339. {
  340. LexicalPath numbers_path(move(locale_numbers_path));
  341. numbers_path = numbers_path.append("numbers.json"sv);
  342. auto numbers = TRY(read_json_file(numbers_path.string()));
  343. auto const& main_object = numbers.as_object().get_object("main"sv).value();
  344. auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
  345. auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
  346. auto const& minimum_grouping_digits = locale_numbers_object.get_byte_string("minimumGroupingDigits"sv).value();
  347. Vector<Optional<NumberSystem>> number_systems;
  348. number_systems.resize(cldr.number_systems.size());
  349. auto ensure_number_system = [&](auto const& system) -> NumberSystem& {
  350. auto system_index = cldr.number_systems.find_first_index(system).value();
  351. VERIFY(system_index < number_systems.size());
  352. auto& number_system = number_systems.at(system_index);
  353. if (!number_system.has_value())
  354. number_system = NumberSystem {};
  355. return number_system.value();
  356. };
  357. auto parse_number_format = [&](auto const& format_object) {
  358. Vector<size_t> result;
  359. result.ensure_capacity(format_object.size());
  360. format_object.for_each_member([&](auto const& key, JsonValue const& value) {
  361. auto split_key = key.split_view('-');
  362. if (split_key.size() != 3)
  363. return;
  364. auto patterns = value.as_string().split(';');
  365. NumberFormat format {};
  366. if (auto type = split_key[0].template to_number<u64>(); type.has_value()) {
  367. VERIFY(*type % 10 == 0);
  368. format.magnitude = static_cast<u8>(log10(*type));
  369. if (patterns[0] != "0"sv) {
  370. auto number_of_zeroes_in_pattern = patterns[0].count("0"sv);
  371. VERIFY(format.magnitude >= number_of_zeroes_in_pattern);
  372. format.exponent = format.magnitude + 1 - number_of_zeroes_in_pattern;
  373. }
  374. } else {
  375. VERIFY(split_key[0] == "unitPattern"sv);
  376. }
  377. format.plurality = Locale::plural_category_from_string(split_key[2]);
  378. parse_number_pattern(move(patterns), cldr, NumberFormatType::Compact, format);
  379. auto format_index = cldr.unique_formats.ensure(move(format));
  380. result.append(format_index);
  381. });
  382. return cldr.unique_format_lists.ensure(move(result));
  383. };
  384. auto numeric_symbol_from_string = [&](StringView numeric_symbol) -> Optional<Locale::NumericSymbol> {
  385. if (numeric_symbol == "approximatelySign"sv)
  386. return Locale::NumericSymbol::ApproximatelySign;
  387. if (numeric_symbol == "decimal"sv)
  388. return Locale::NumericSymbol::Decimal;
  389. if (numeric_symbol == "exponential"sv)
  390. return Locale::NumericSymbol::Exponential;
  391. if (numeric_symbol == "group"sv)
  392. return Locale::NumericSymbol::Group;
  393. if (numeric_symbol == "infinity"sv)
  394. return Locale::NumericSymbol::Infinity;
  395. if (numeric_symbol == "minusSign"sv)
  396. return Locale::NumericSymbol::MinusSign;
  397. if (numeric_symbol == "nan"sv)
  398. return Locale::NumericSymbol::NaN;
  399. if (numeric_symbol == "percentSign"sv)
  400. return Locale::NumericSymbol::PercentSign;
  401. if (numeric_symbol == "plusSign"sv)
  402. return Locale::NumericSymbol::PlusSign;
  403. if (numeric_symbol == "timeSeparator"sv)
  404. return Locale::NumericSymbol::TimeSeparator;
  405. return {};
  406. };
  407. locale_numbers_object.for_each_member([&](auto const& key, JsonValue const& value) {
  408. constexpr auto symbols_prefix = "symbols-numberSystem-"sv;
  409. constexpr auto decimal_formats_prefix = "decimalFormats-numberSystem-"sv;
  410. constexpr auto currency_formats_prefix = "currencyFormats-numberSystem-"sv;
  411. constexpr auto percent_formats_prefix = "percentFormats-numberSystem-"sv;
  412. constexpr auto scientific_formats_prefix = "scientificFormats-numberSystem-"sv;
  413. constexpr auto misc_patterns_prefix = "miscPatterns-numberSystem-"sv;
  414. if (key.starts_with(symbols_prefix)) {
  415. auto system = key.substring(symbols_prefix.length());
  416. auto& number_system = ensure_number_system(system);
  417. NumericSymbolList symbols;
  418. value.as_object().for_each_member([&](auto const& symbol, JsonValue const& localization) {
  419. auto numeric_symbol = numeric_symbol_from_string(symbol);
  420. if (!numeric_symbol.has_value())
  421. return;
  422. if (to_underlying(*numeric_symbol) >= symbols.size())
  423. symbols.resize(to_underlying(*numeric_symbol) + 1);
  424. auto symbol_index = cldr.unique_strings.ensure(localization.as_string());
  425. symbols[to_underlying(*numeric_symbol)] = symbol_index;
  426. });
  427. // The range separator does not appear in the symbols list, we have to extract it from
  428. // the range pattern.
  429. auto misc_patterns_key = ByteString::formatted("{}{}", misc_patterns_prefix, system);
  430. auto misc_patterns = locale_numbers_object.get_object(misc_patterns_key).value();
  431. auto range_separator = misc_patterns.get_byte_string("range"sv).value();
  432. auto begin_index = range_separator.find("{0}"sv).value() + "{0}"sv.length();
  433. auto end_index = range_separator.find("{1}"sv).value();
  434. range_separator = range_separator.substring(begin_index, end_index - begin_index);
  435. if (to_underlying(Locale::NumericSymbol::RangeSeparator) >= symbols.size())
  436. symbols.resize(to_underlying(Locale::NumericSymbol::RangeSeparator) + 1);
  437. auto symbol_index = cldr.unique_strings.ensure(move(range_separator));
  438. symbols[to_underlying(Locale::NumericSymbol::RangeSeparator)] = symbol_index;
  439. number_system.symbols = cldr.unique_symbols.ensure(move(symbols));
  440. } else if (key.starts_with(decimal_formats_prefix)) {
  441. auto system = key.substring(decimal_formats_prefix.length());
  442. auto& number_system = ensure_number_system(system);
  443. auto format_object = value.as_object().get_byte_string("standard"sv).value();
  444. parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.decimal_format, &number_system);
  445. auto const& long_format = value.as_object().get_object("long"sv)->get_object("decimalFormat"sv).value();
  446. number_system.decimal_long_formats = parse_number_format(long_format);
  447. auto const& short_format = value.as_object().get_object("short"sv)->get_object("decimalFormat"sv).value();
  448. number_system.decimal_short_formats = parse_number_format(short_format);
  449. } else if (key.starts_with(currency_formats_prefix)) {
  450. auto system = key.substring(currency_formats_prefix.length());
  451. auto& number_system = ensure_number_system(system);
  452. auto format_object = value.as_object().get_byte_string("standard"sv).value();
  453. parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.currency_format);
  454. format_object = value.as_object().get_byte_string("accounting"sv).value();
  455. parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.accounting_format);
  456. number_system.currency_unit_formats = parse_number_format(value.as_object());
  457. } else if (key.starts_with(percent_formats_prefix)) {
  458. auto system = key.substring(percent_formats_prefix.length());
  459. auto& number_system = ensure_number_system(system);
  460. auto format_object = value.as_object().get_byte_string("standard"sv).value();
  461. parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.percent_format);
  462. } else if (key.starts_with(scientific_formats_prefix)) {
  463. auto system = key.substring(scientific_formats_prefix.length());
  464. auto& number_system = ensure_number_system(system);
  465. auto format_object = value.as_object().get_byte_string("standard"sv).value();
  466. parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.scientific_format);
  467. }
  468. });
  469. locale.number_systems.ensure_capacity(number_systems.size());
  470. for (auto& number_system : number_systems) {
  471. size_t system_index = 0;
  472. if (number_system.has_value())
  473. system_index = cldr.unique_systems.ensure(number_system.release_value());
  474. locale.number_systems.append(system_index);
  475. }
  476. locale.minimum_grouping_digits = minimum_grouping_digits.template to_number<u8>().value();
  477. return {};
  478. }
  479. static ErrorOr<void> parse_units(ByteString locale_units_path, CLDR& cldr, LocaleData& locale)
  480. {
  481. LexicalPath units_path(move(locale_units_path));
  482. units_path = units_path.append("units.json"sv);
  483. auto locale_units = TRY(read_json_file(units_path.string()));
  484. auto const& main_object = locale_units.as_object().get_object("main"sv).value();
  485. auto const& locale_object = main_object.get_object(units_path.parent().basename()).value();
  486. auto const& locale_units_object = locale_object.get_object("units"sv).value();
  487. auto const& long_object = locale_units_object.get_object("long"sv).value();
  488. auto const& short_object = locale_units_object.get_object("short"sv).value();
  489. auto const& narrow_object = locale_units_object.get_object("narrow"sv).value();
  490. HashMap<ByteString, Unit> units;
  491. auto ensure_unit = [&](auto const& unit) -> Unit& {
  492. return units.ensure(unit, [&]() {
  493. auto unit_index = cldr.unique_strings.ensure(unit);
  494. return Unit { .unit = unit_index };
  495. });
  496. };
  497. auto is_sanctioned_unit = [](StringView unit_name) {
  498. // LibUnicode generally tries to avoid being directly dependent on ECMA-402, but this rather significantly reduces the amount
  499. // of data generated here, and ECMA-402 is currently the only consumer of this data.
  500. constexpr auto sanctioned_units = JS::Intl::sanctioned_single_unit_identifiers();
  501. return find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end();
  502. };
  503. auto parse_units_object = [&](auto const& units_object, Locale::Style style) {
  504. constexpr auto unit_pattern_prefix = "unitPattern-count-"sv;
  505. constexpr auto combined_unit_separator = "-per-"sv;
  506. units_object.for_each_member([&](auto const& key, JsonValue const& value) {
  507. auto end_of_category = key.find('-');
  508. if (!end_of_category.has_value())
  509. return;
  510. auto unit_name = key.substring(*end_of_category + 1);
  511. if (!is_sanctioned_unit(unit_name)) {
  512. auto indices = unit_name.find_all(combined_unit_separator);
  513. if (indices.size() != 1)
  514. return;
  515. auto numerator = unit_name.substring_view(0, indices[0]);
  516. auto denominator = unit_name.substring_view(indices[0] + combined_unit_separator.length());
  517. if (!is_sanctioned_unit(numerator) || !is_sanctioned_unit(denominator))
  518. return;
  519. }
  520. auto& unit = ensure_unit(unit_name);
  521. NumberFormatList formats;
  522. value.as_object().for_each_member([&](auto const& unit_key, JsonValue const& pattern_value) {
  523. if (!unit_key.starts_with(unit_pattern_prefix))
  524. return;
  525. NumberFormat format {};
  526. auto plurality = unit_key.substring_view(unit_pattern_prefix.length());
  527. format.plurality = Locale::plural_category_from_string(plurality);
  528. auto zero_format = pattern_value.as_string().replace("{0}"sv, "{number}"sv, ReplaceMode::FirstOnly);
  529. zero_format = parse_identifiers(zero_format, "unitIdentifier"sv, cldr, format);
  530. format.positive_format_index = cldr.unique_strings.ensure(zero_format.replace("{number}"sv, "{plusSign}{number}"sv, ReplaceMode::FirstOnly));
  531. format.negative_format_index = cldr.unique_strings.ensure(zero_format.replace("{number}"sv, "{minusSign}{number}"sv, ReplaceMode::FirstOnly));
  532. format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
  533. formats.append(cldr.unique_formats.ensure(move(format)));
  534. });
  535. auto number_format_list_index = cldr.unique_format_lists.ensure(move(formats));
  536. switch (style) {
  537. case Locale::Style::Long:
  538. unit.long_formats = number_format_list_index;
  539. break;
  540. case Locale::Style::Short:
  541. unit.short_formats = number_format_list_index;
  542. break;
  543. case Locale::Style::Narrow:
  544. unit.narrow_formats = number_format_list_index;
  545. break;
  546. default:
  547. VERIFY_NOT_REACHED();
  548. }
  549. });
  550. };
  551. parse_units_object(long_object, Locale::Style::Long);
  552. parse_units_object(short_object, Locale::Style::Short);
  553. parse_units_object(narrow_object, Locale::Style::Narrow);
  554. for (auto& unit : units) {
  555. auto unit_index = cldr.unique_units.ensure(move(unit.value));
  556. locale.units.set(unit.key, unit_index);
  557. }
  558. return {};
  559. }
  560. static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString numbers_path, ByteString units_path, CLDR& cldr)
  561. {
  562. LexicalPath core_supplemental_path(move(core_path));
  563. core_supplemental_path = core_supplemental_path.append("supplemental"sv);
  564. VERIFY(FileSystem::is_directory(core_supplemental_path.string()));
  565. TRY(parse_number_system_digits(core_supplemental_path.string(), cldr));
  566. auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
  567. auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
  568. StringBuilder builder;
  569. builder.append(cldr.unique_strings.get(parsed_locale.language));
  570. if (auto script = cldr.unique_strings.get(parsed_locale.script); !script.is_empty())
  571. builder.appendff("-{}", script);
  572. if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
  573. builder.appendff("-{}", region);
  574. return builder.to_byte_string();
  575. };
  576. TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", numbers_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
  577. auto numbers_path = LexicalPath::join(directory.path().string(), entry.name).string();
  578. auto language = TRY(remove_variants_from_path(numbers_path));
  579. auto& locale = cldr.locales.ensure(language);
  580. TRY(parse_number_systems(numbers_path, cldr, locale));
  581. return IterationDecision::Continue;
  582. }));
  583. TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", units_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
  584. auto units_path = LexicalPath::join(directory.path().string(), entry.name).string();
  585. auto language = TRY(remove_variants_from_path(units_path));
  586. auto& locale = cldr.locales.ensure(language);
  587. TRY(parse_units(units_path, cldr, locale));
  588. return IterationDecision::Continue;
  589. }));
  590. return {};
  591. }
  592. static ByteString format_identifier(StringView, ByteString identifier)
  593. {
  594. return identifier.to_titlecase();
  595. }
  596. static ErrorOr<void> generate_unicode_locale_header(Core::InputBufferedFile& file, CLDR& cldr)
  597. {
  598. StringBuilder builder;
  599. SourceGenerator generator { builder };
  600. generator.append(R"~~~(
  601. #include <AK/Types.h>
  602. #pragma once
  603. namespace Locale {
  604. )~~~");
  605. generate_enum(generator, format_identifier, "NumberSystem"sv, {}, cldr.number_systems);
  606. generator.append(R"~~~(
  607. }
  608. )~~~");
  609. TRY(file.write_until_depleted(generator.as_string_view().bytes()));
  610. return {};
  611. }
  612. static ErrorOr<void> generate_unicode_locale_implementation(Core::InputBufferedFile& file, CLDR& cldr)
  613. {
  614. StringBuilder builder;
  615. SourceGenerator generator { builder };
  616. generator.set("string_index_type"sv, cldr.unique_strings.type_that_fits());
  617. generator.set("number_format_index_type"sv, cldr.unique_formats.type_that_fits());
  618. generator.set("number_format_list_index_type"sv, cldr.unique_format_lists.type_that_fits());
  619. generator.set("numeric_symbol_list_index_type"sv, cldr.unique_symbols.type_that_fits());
  620. generator.set("identifier_count", ByteString::number(cldr.max_identifier_count));
  621. generator.append(R"~~~(
  622. #include <AK/Array.h>
  623. #include <AK/BinarySearch.h>
  624. #include <AK/Optional.h>
  625. #include <AK/Span.h>
  626. #include <AK/StringView.h>
  627. #include <AK/Vector.h>
  628. #include <LibLocale/Locale.h>
  629. #include <LibLocale/LocaleData.h>
  630. #include <LibLocale/NumberFormat.h>
  631. #include <LibLocale/NumberFormatData.h>
  632. #include <LibLocale/PluralRules.h>
  633. namespace Locale {
  634. )~~~");
  635. cldr.unique_strings.generate(generator);
  636. generator.append(R"~~~(
  637. struct NumberFormatImpl {
  638. NumberFormat to_unicode_number_format() const {
  639. NumberFormat number_format {};
  640. number_format.magnitude = magnitude;
  641. number_format.exponent = exponent;
  642. number_format.plurality = static_cast<PluralCategory>(plurality);
  643. number_format.zero_format = decode_string(zero_format);
  644. number_format.positive_format = decode_string(positive_format);
  645. number_format.negative_format = decode_string(negative_format);
  646. number_format.identifiers.ensure_capacity(identifiers.size());
  647. for (@string_index_type@ identifier : identifiers)
  648. number_format.identifiers.unchecked_append(decode_string(identifier));
  649. return number_format;
  650. }
  651. u8 magnitude { 0 };
  652. u8 exponent { 0 };
  653. u8 plurality { 0 };
  654. @string_index_type@ zero_format { 0 };
  655. @string_index_type@ positive_format { 0 };
  656. @string_index_type@ negative_format { 0 };
  657. Array<@string_index_type@, @identifier_count@> identifiers {};
  658. };
  659. struct NumberSystemData {
  660. @numeric_symbol_list_index_type@ symbols { 0 };
  661. u8 primary_grouping_size { 0 };
  662. u8 secondary_grouping_size { 0 };
  663. @number_format_index_type@ decimal_format { 0 };
  664. @number_format_list_index_type@ decimal_long_formats { 0 };
  665. @number_format_list_index_type@ decimal_short_formats { 0 };
  666. @number_format_index_type@ currency_format { 0 };
  667. @number_format_index_type@ accounting_format { 0 };
  668. @number_format_list_index_type@ currency_unit_formats { 0 };
  669. @number_format_index_type@ percent_format { 0 };
  670. @number_format_index_type@ scientific_format { 0 };
  671. };
  672. struct Unit {
  673. @string_index_type@ unit { 0 };
  674. @number_format_list_index_type@ long_formats { 0 };
  675. @number_format_list_index_type@ short_formats { 0 };
  676. @number_format_list_index_type@ narrow_formats { 0 };
  677. };
  678. )~~~");
  679. cldr.unique_formats.generate(generator, "NumberFormatImpl"sv, "s_number_formats"sv, 10);
  680. cldr.unique_format_lists.generate(generator, cldr.unique_formats.type_that_fits(), "s_number_format_lists"sv);
  681. cldr.unique_symbols.generate(generator, cldr.unique_strings.type_that_fits(), "s_numeric_symbol_lists"sv);
  682. cldr.unique_systems.generate(generator, "NumberSystemData"sv, "s_number_systems"sv, 10);
  683. cldr.unique_units.generate(generator, "Unit"sv, "s_units"sv, 10);
  684. auto locales = cldr.locales.keys();
  685. quick_sort(locales);
  686. generator.set("size", ByteString::number(locales.size()));
  687. generator.append(R"~~~(
  688. static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
  689. bool first = true;
  690. for (auto const& locale : locales) {
  691. generator.append(first ? " "sv : ", "sv);
  692. generator.append(ByteString::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
  693. first = false;
  694. }
  695. generator.append(" } };\n");
  696. auto append_map = [&](ByteString name, auto type, auto const& map) {
  697. generator.set("name", name);
  698. generator.set("type", type);
  699. generator.set("size", ByteString::number(map.size()));
  700. generator.append(R"~~~(
  701. static constexpr Array<@type@, @size@> @name@ { {)~~~");
  702. bool first = true;
  703. for (auto const& item : map) {
  704. generator.append(first ? " "sv : ", "sv);
  705. if constexpr (requires { item.value; })
  706. generator.append(ByteString::number(item.value));
  707. else
  708. generator.append(ByteString::number(item));
  709. first = false;
  710. }
  711. generator.append(" } };");
  712. };
  713. generate_mapping(generator, cldr.number_system_digits, "u32"sv, "s_number_systems_digits"sv, "s_number_systems_digits_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, "u32"sv, value); });
  714. generate_mapping(generator, cldr.locales, cldr.unique_systems.type_that_fits(), "s_locale_number_systems"sv, "s_number_systems_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, cldr.unique_systems.type_that_fits(), value.number_systems); });
  715. generate_mapping(generator, cldr.locales, cldr.unique_units.type_that_fits(), "s_locale_units"sv, "s_units_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, cldr.unique_units.type_that_fits(), value.units); });
  716. generator.append(R"~~~(
  717. static Optional<NumberSystem> keyword_to_number_system(KeywordNumbers keyword)
  718. {
  719. switch (keyword) {)~~~");
  720. for (auto const& number_system : cldr.number_systems) {
  721. generator.set("name"sv, format_identifier({}, number_system));
  722. generator.append(R"~~~(
  723. case KeywordNumbers::@name@:
  724. return NumberSystem::@name@;)~~~");
  725. }
  726. generator.append(R"~~~(
  727. default:
  728. return {};
  729. }
  730. }
  731. Optional<ReadonlySpan<u32>> get_digits_for_number_system(StringView system)
  732. {
  733. auto number_system_keyword = keyword_nu_from_string(system);
  734. if (!number_system_keyword.has_value())
  735. return {};
  736. auto number_system_value = keyword_to_number_system(*number_system_keyword);
  737. if (!number_system_value.has_value())
  738. return {};
  739. auto number_system_index = to_underlying(*number_system_value);
  740. return s_number_systems_digits[number_system_index];
  741. }
  742. static NumberSystemData const* find_number_system(StringView locale, StringView system)
  743. {
  744. auto locale_value = locale_from_string(locale);
  745. if (!locale_value.has_value())
  746. return nullptr;
  747. auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
  748. auto const& number_systems = s_locale_number_systems.at(locale_index);
  749. auto lookup_number_system = [&](auto number_system) -> NumberSystemData const* {
  750. auto number_system_keyword = keyword_nu_from_string(number_system);
  751. if (!number_system_keyword.has_value())
  752. return nullptr;
  753. auto number_system_value = keyword_to_number_system(*number_system_keyword);
  754. if (!number_system_value.has_value())
  755. return nullptr;
  756. auto number_system_index = to_underlying(*number_system_value);
  757. number_system_index = number_systems.at(number_system_index);
  758. if (number_system_index == 0)
  759. return nullptr;
  760. return &s_number_systems.at(number_system_index);
  761. };
  762. if (auto const* number_system = lookup_number_system(system))
  763. return number_system;
  764. auto default_number_system = get_preferred_keyword_value_for_locale(locale, "nu"sv);
  765. if (!default_number_system.has_value())
  766. return nullptr;
  767. return lookup_number_system(*default_number_system);
  768. }
  769. Optional<StringView> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol)
  770. {
  771. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
  772. auto symbols = s_numeric_symbol_lists.at(number_system->symbols);
  773. auto symbol_index = to_underlying(symbol);
  774. if (symbol_index >= symbols.size())
  775. return {};
  776. return decode_string(symbols[symbol_index]);
  777. }
  778. return {};
  779. }
  780. Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system)
  781. {
  782. auto locale_value = locale_from_string(locale);
  783. if (!locale_value.has_value())
  784. return {};
  785. u8 minimum_grouping_digits = s_minimum_grouping_digits[to_underlying(*locale_value) - 1];
  786. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr)
  787. return NumberGroupings { minimum_grouping_digits, number_system->primary_grouping_size, number_system->secondary_grouping_size };
  788. return {};
  789. }
  790. Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type)
  791. {
  792. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
  793. @number_format_index_type@ format_index = 0;
  794. switch (type) {
  795. case StandardNumberFormatType::Decimal:
  796. format_index = number_system->decimal_format;
  797. break;
  798. case StandardNumberFormatType::Currency:
  799. format_index = number_system->currency_format;
  800. break;
  801. case StandardNumberFormatType::Accounting:
  802. format_index = number_system->accounting_format;
  803. break;
  804. case StandardNumberFormatType::Percent:
  805. format_index = number_system->percent_format;
  806. break;
  807. case StandardNumberFormatType::Scientific:
  808. format_index = number_system->scientific_format;
  809. break;
  810. }
  811. return s_number_formats[format_index].to_unicode_number_format();
  812. }
  813. return {};
  814. }
  815. Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type)
  816. {
  817. Vector<NumberFormat> formats;
  818. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
  819. @number_format_list_index_type@ number_format_list_index { 0 };
  820. switch (type) {
  821. case CompactNumberFormatType::DecimalLong:
  822. number_format_list_index = number_system->decimal_long_formats;
  823. break;
  824. case CompactNumberFormatType::DecimalShort:
  825. number_format_list_index = number_system->decimal_short_formats;
  826. break;
  827. case CompactNumberFormatType::CurrencyUnit:
  828. number_format_list_index = number_system->currency_unit_formats;
  829. break;
  830. }
  831. auto number_formats = s_number_format_lists.at(number_format_list_index);
  832. formats.ensure_capacity(number_formats.size());
  833. for (auto number_format : number_formats)
  834. formats.unchecked_append(s_number_formats[number_format].to_unicode_number_format());
  835. }
  836. return formats;
  837. }
  838. static Unit const* find_units(StringView locale, StringView unit)
  839. {
  840. auto locale_value = locale_from_string(locale);
  841. if (!locale_value.has_value())
  842. return nullptr;
  843. auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
  844. auto const& locale_units = s_locale_units.at(locale_index);
  845. for (auto unit_index : locale_units) {
  846. auto const& units = s_units.at(unit_index);
  847. if (unit == decode_string(units.unit))
  848. return &units;
  849. };
  850. return nullptr;
  851. }
  852. Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style)
  853. {
  854. Vector<NumberFormat> formats;
  855. if (auto const* units = find_units(locale, unit); units != nullptr) {
  856. @number_format_list_index_type@ number_format_list_index { 0 };
  857. switch (style) {
  858. case Style::Long:
  859. number_format_list_index = units->long_formats;
  860. break;
  861. case Style::Short:
  862. number_format_list_index = units->short_formats;
  863. break;
  864. case Style::Narrow:
  865. number_format_list_index = units->narrow_formats;
  866. break;
  867. default:
  868. VERIFY_NOT_REACHED();
  869. }
  870. auto number_formats = s_number_format_lists.at(number_format_list_index);
  871. formats.ensure_capacity(number_formats.size());
  872. for (auto number_format : number_formats)
  873. formats.unchecked_append(s_number_formats[number_format].to_unicode_number_format());
  874. }
  875. return formats;
  876. }
  877. }
  878. )~~~");
  879. TRY(file.write_until_depleted(generator.as_string_view().bytes()));
  880. return {};
  881. }
  882. ErrorOr<int> serenity_main(Main::Arguments arguments)
  883. {
  884. StringView generated_header_path;
  885. StringView generated_implementation_path;
  886. StringView core_path;
  887. StringView numbers_path;
  888. StringView units_path;
  889. Core::ArgsParser args_parser;
  890. args_parser.add_option(generated_header_path, "Path to the Unicode locale header file to generate", "generated-header-path", 'h', "generated-header-path");
  891. args_parser.add_option(generated_implementation_path, "Path to the Unicode locale implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
  892. args_parser.add_option(core_path, "Path to cldr-core directory", "core-path", 'r', "core-path");
  893. args_parser.add_option(numbers_path, "Path to cldr-numbers directory", "numbers-path", 'n', "numbers-path");
  894. args_parser.add_option(units_path, "Path to cldr-units directory", "units-path", 'u', "units-path");
  895. args_parser.parse(arguments);
  896. auto generated_header_file = TRY(open_file(generated_header_path, Core::File::OpenMode::Write));
  897. auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::File::OpenMode::Write));
  898. CLDR cldr;
  899. TRY(parse_all_locales(core_path, numbers_path, units_path, cldr));
  900. TRY(generate_unicode_locale_header(*generated_header_file, cldr));
  901. TRY(generate_unicode_locale_implementation(*generated_implementation_file, cldr));
  902. return 0;
  903. }