Remove stripping scriptCodes for localization. (#83903)

This commit is contained in:
greymag
2021-06-16 23:39:05 +03:00
committed by GitHub
parent 430bfac41c
commit f8d73be84c
2 changed files with 17 additions and 20 deletions

View File

@@ -16,29 +16,9 @@ bool _dateIntlDataInitialized = false;
/// invocations have no effect.
void loadDateIntlDataIfNotLoaded() {
if (!_dateIntlDataInitialized) {
// TODO(garyq): Add support for scriptCodes. Do not strip scriptCode from string.
// Keeps track of initialized locales. This can only happen if a locale
// with a stripped scriptCode has already been initialized. The set of
// initialized locales should be removed when scriptCode stripping is
// removed.
final Set<String> initializedLocales = <String>{};
date_localizations.dateSymbols
.cast<String, Map<String, dynamic>>()
.forEach((String locale, Map<String, dynamic> data) {
// Strip scriptCode from the locale, as we do not distinguish between scripts
// for dates.
final List<String> codes = locale.split('_');
String? countryCode;
if (codes.length == 2) {
countryCode = codes[1].length < 4 ? codes[1] : null;
} else if (codes.length == 3) {
countryCode = codes[1].length < codes[2].length ? codes[1] : codes[2];
}
locale = codes[0] + (countryCode != null ? '_$countryCode' : '');
if (initializedLocales.contains(locale))
return;
initializedLocales.add(locale);
// Perform initialization.
assert(date_localizations.datePatterns.containsKey(locale));
final intl.DateSymbols symbols = intl.DateSymbols.deserializeFromMap(data);