1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:07:34 +00:00

LibJS: Allow specifying keyword values not directly defined for a locale

For example, consider the locales "en-u-nu-fullwide" or "en-u-nu-arab".
The CLDR only declares the "latn" numbering system for the "en" locale,
thus ResolveLocale would change the locale to "en-u-nu-latn". This patch
allows using non-latn numbering systems digits.
This commit is contained in:
Timothy Flynn 2022-07-14 13:55:13 -04:00 committed by Andreas Kling
parent b24b9c0a65
commit aafcdc4c72
6 changed files with 42 additions and 12 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2021-2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -425,13 +425,15 @@ LocaleResult resolve_locale(Vector<String> const& requested_locales, LocaleOptio
// b. Assert: Type(foundLocaleData) is Record.
// c. Let keyLocaleData be foundLocaleData.[[<key>]].
// d. Assert: Type(keyLocaleData) is List.
auto key_locale_data = Unicode::get_keywords_for_locale(found_locale, key);
auto key_locale_data = Unicode::get_available_keyword_values(key);
// e. Let value be keyLocaleData[0].
// f. Assert: Type(value) is either String or Null.
// NOTE: ECMA-402 assumes keyLocaleData is sorted by locale preference. Our list is sorted
// alphabetically, so we get the locale's preferred value from LibUnicode.
Optional<String> value;
if (!key_locale_data.is_empty())
value = key_locale_data[0];
if (auto preference = Unicode::get_preferred_keyword_value_for_locale(found_locale, key); preference.has_value())
value = *preference;
// g. Let supportedExtensionAddition be "".
Optional<Unicode::Keyword> supported_extension_addition {};