Prepend [NSLocale currentLocale] for first locale on iOS to ensure countryCode exists. Allow language-only locales. (flutter/engine#6995)
This commit is contained in:
@@ -748,18 +748,35 @@ static blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) {
|
||||
|
||||
- (void)onLocaleUpdated:(NSNotification*)notification {
|
||||
NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
|
||||
NSMutableArray<NSString*>* data = [NSMutableArray new];
|
||||
NSMutableArray<NSString*>* data = [[NSMutableArray new] autorelease];
|
||||
|
||||
// Force prepend the [NSLocale currentLocale] to the front of the list
|
||||
// to ensure we are including the full default locale. preferredLocales
|
||||
// is not guaranteed to include anything beyond the languageCode.
|
||||
NSLocale* currentLocale = [NSLocale currentLocale];
|
||||
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
|
||||
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
|
||||
NSString* scriptCode = [currentLocale objectForKey:NSLocaleScriptCode];
|
||||
NSString* variantCode = [currentLocale objectForKey:NSLocaleVariantCode];
|
||||
if (languageCode) {
|
||||
[data addObject:languageCode];
|
||||
[data addObject:(countryCode ? countryCode : @"")];
|
||||
[data addObject:(scriptCode ? scriptCode : @"")];
|
||||
[data addObject:(variantCode ? variantCode : @"")];
|
||||
}
|
||||
|
||||
// Add any secondary locales/languages to the list.
|
||||
for (NSString* localeID in preferredLocales) {
|
||||
NSLocale* currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:localeID];
|
||||
NSLocale* currentLocale = [[[NSLocale alloc] initWithLocaleIdentifier:localeID] autorelease];
|
||||
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
|
||||
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
|
||||
NSString* scriptCode = [currentLocale objectForKey:NSLocaleScriptCode];
|
||||
NSString* variantCode = [currentLocale objectForKey:NSLocaleVariantCode];
|
||||
if (!languageCode || !countryCode) {
|
||||
if (!languageCode) {
|
||||
continue;
|
||||
}
|
||||
[data addObject:languageCode];
|
||||
[data addObject:countryCode];
|
||||
[data addObject:(countryCode ? countryCode : @"")];
|
||||
[data addObject:(scriptCode ? scriptCode : @"")];
|
||||
[data addObject:(variantCode ? variantCode : @"")];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user