Enable legacy locales "sh", "no", "tl"

Use new API available in ICU65.1 so legacy locales won't be hidden.

Bug: v8:9312,chromium:968269
Change-Id: I6e44501249cdb863ff9b1ab858efdf8908380a82
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2131373
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66957}
This commit is contained in:
Frank Tang 2020-04-01 14:54:46 -07:00 committed by Commit Bot
parent e0de3b6d42
commit 7cba1ed502
10 changed files with 55 additions and 41 deletions

View File

@ -563,14 +563,12 @@ bool ValidateResource(const icu::Locale locale, const char* path,
} // namespace
std::set<std::string> Intl::BuildLocaleSet(
const icu::Locale* icu_available_locales, int32_t count, const char* path,
const std::vector<std::string>& icu_available_locales, const char* path,
const char* validate_key) {
std::set<std::string> locales;
for (int32_t i = 0; i < count; ++i) {
std::string locale =
Intl::ToLanguageTag(icu_available_locales[i]).FromJust();
for (const std::string& locale : icu_available_locales) {
if (path != nullptr || validate_key != nullptr) {
if (!ValidateResource(icu_available_locales[i], path, validate_key)) {
if (!ValidateResource(icu::Locale(locale.c_str()), path, validate_key)) {
continue;
}
}
@ -2107,9 +2105,9 @@ Maybe<bool> Intl::GetNumberingSystem(Isolate* isolate,
return Just(false);
}
const std::set<std::string>& Intl::GetAvailableLocalesForLocale() {
static base::LazyInstance<Intl::AvailableLocales<icu::Locale>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
const std::set<std::string>& Intl::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<>>::type available_locales =
LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}
@ -2123,8 +2121,7 @@ struct CheckCalendar {
} // namespace
const std::set<std::string>& Intl::GetAvailableLocalesForDateFormat() {
static base::LazyInstance<
Intl::AvailableLocales<icu::DateFormat, CheckCalendar>>::type
static base::LazyInstance<Intl::AvailableLocales<CheckCalendar>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}

View File

@ -49,7 +49,7 @@ class Intl {
// script; eg, pa_Guru_IN (language=Panjabi, script=Gurmukhi, country-India)
// would include pa_IN.
static std::set<std::string> BuildLocaleSet(
const icu::Locale* icu_available_locales, int32_t count, const char* path,
const std::vector<std::string>& locales, const char* path,
const char* validate_key);
static Maybe<std::string> ToLanguageTag(const icu::Locale& locale);
@ -276,21 +276,34 @@ class Intl {
static const char* path() { return nullptr; }
};
template <typename T, typename C = SkipResourceCheck>
template <typename C = SkipResourceCheck>
class AvailableLocales {
public:
AvailableLocales() {
int32_t num_locales = 0;
const icu::Locale* icu_available_locales =
T::getAvailableLocales(num_locales);
set = Intl::BuildLocaleSet(icu_available_locales, num_locales, C::path(),
C::key());
UErrorCode status = U_ZERO_ERROR;
UEnumeration* uenum =
uloc_openAvailableByType(ULOC_AVAILABLE_WITH_LEGACY_ALIASES, &status);
DCHECK(U_SUCCESS(status));
std::vector<std::string> all_locales;
const char* loc;
while ((loc = uenum_next(uenum, NULL, &status)) != nullptr) {
DCHECK(U_SUCCESS(status));
std::string locstr(loc);
std::replace(locstr.begin(), locstr.end(), '_', '-');
// Handle special case
if (locstr == "en-US-POSIX") locstr = "en-US-u-va-posix";
all_locales.push_back(locstr);
}
uenum_close(uenum);
set_ = Intl::BuildLocaleSet(all_locales, C::path(), C::key());
}
virtual ~AvailableLocales() {}
const std::set<std::string>& Get() const { return set; }
const std::set<std::string>& Get() const { return set_; }
private:
std::set<std::string> set;
std::set<std::string> set_;
};
// Utility function to set text to BreakIterator.
@ -311,7 +324,7 @@ class Intl {
static String ConvertOneByteToLower(String src, String dst);
static const std::set<std::string>& GetAvailableLocalesForLocale();
static const std::set<std::string>& GetAvailableLocales();
static const std::set<std::string>& GetAvailableLocalesForDateFormat();
};

View File

@ -239,9 +239,7 @@ String JSV8BreakIterator::BreakType(Isolate* isolate,
}
const std::set<std::string>& JSV8BreakIterator::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::BreakIterator>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
return Intl::GetAvailableLocales();
}
} // namespace internal

View File

@ -493,18 +493,33 @@ MaybeHandle<JSCollator> JSCollator::New(Isolate* isolate, Handle<Map> map,
namespace {
struct CheckColl {
static const char* key() { return nullptr; }
class CollatorAvailableLocales {
public:
CollatorAvailableLocales() {
int32_t num_locales = 0;
const icu::Locale* icu_available_locales =
icu::Collator::getAvailableLocales(num_locales);
std::vector<std::string> locales;
for (int32_t i = 0; i < num_locales; ++i) {
locales.push_back(
Intl::ToLanguageTag(icu_available_locales[i]).FromJust());
}
#define U_ICUDATA_COLL U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll"
static const char* path() { return U_ICUDATA_COLL; }
set_ = Intl::BuildLocaleSet(locales, U_ICUDATA_COLL, nullptr);
#undef U_ICUDATA_COLL
}
virtual ~CollatorAvailableLocales() {}
const std::set<std::string>& Get() const { return set_; }
private:
std::set<std::string> set_;
};
} // namespace
const std::set<std::string>& JSCollator::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::Collator, CheckColl>>::
type available_locales = LAZY_INSTANCE_INITIALIZER;
static base::LazyInstance<CollatorAvailableLocales>::type available_locales =
LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}

View File

@ -750,8 +750,7 @@ struct CheckCalendar {
} // namespace
const std::set<std::string>& JSDisplayNames::GetAvailableLocales() {
static base::LazyInstance<
Intl::AvailableLocales<icu::Locale, CheckCalendar>>::type
static base::LazyInstance<Intl::AvailableLocales<CheckCalendar>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}

View File

@ -331,8 +331,7 @@ struct CheckListPattern {
} // namespace
const std::set<std::string>& JSListFormat::GetAvailableLocales() {
static base::LazyInstance<
Intl::AvailableLocales<icu::Locale, CheckListPattern>>::type
static base::LazyInstance<Intl::AvailableLocales<CheckListPattern>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}

View File

@ -1494,8 +1494,7 @@ struct CheckNumberElements {
} // namespace
const std::set<std::string>& JSNumberFormat::GetAvailableLocales() {
static base::LazyInstance<
Intl::AvailableLocales<icu::NumberFormat, CheckNumberElements>>::type
static base::LazyInstance<Intl::AvailableLocales<CheckNumberElements>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}

View File

@ -325,7 +325,6 @@ const std::set<std::string>& JSPluralRules::GetAvailableLocales() {
static base::LazyInstance<PluralRulesAvailableLocales>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
// return Intl::GetAvailableLocalesForLocale();
}
} // namespace internal

View File

@ -163,9 +163,7 @@ Handle<String> JSSegmenter::GranularityAsString() const {
}
const std::set<std::string>& JSSegmenter::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::BreakIterator>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
return Intl::GetAvailableLocales();
}
} // namespace internal

View File

@ -34,9 +34,6 @@
'collator/check-kf-option': [FAIL],
'collator/check-kn-option': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=9312
'regress-9312': [FAIL],
# http://crbug/v8/9930
'date-format/format_range_hour_cycle': [FAIL],
}], # ALWAYS