@@ -748,18 +748,35 @@ - (void)onMemoryWarning:(NSNotification*)notification {
748
748
749
749
- (void )onLocaleUpdated : (NSNotification *)notification {
750
750
NSArray <NSString *>* preferredLocales = [NSLocale preferredLanguages ];
751
- NSMutableArray <NSString *>* data = [NSMutableArray new ];
751
+ NSMutableArray <NSString *>* data = [[NSMutableArray new ] autorelease ];
752
+
753
+ // Force prepend the [NSLocale currentLocale] to the front of the list
754
+ // to ensure we are including the full default locale. preferredLocales
755
+ // is not guaranteed to include anything beyond the languageCode.
756
+ NSLocale * currentLocale = [NSLocale currentLocale ];
757
+ NSString * languageCode = [currentLocale objectForKey: NSLocaleLanguageCode ];
758
+ NSString * countryCode = [currentLocale objectForKey: NSLocaleCountryCode ];
759
+ NSString * scriptCode = [currentLocale objectForKey: NSLocaleScriptCode ];
760
+ NSString * variantCode = [currentLocale objectForKey: NSLocaleVariantCode ];
761
+ if (languageCode) {
762
+ [data addObject: languageCode];
763
+ [data addObject: (countryCode ? countryCode : @" " )];
764
+ [data addObject: (scriptCode ? scriptCode : @" " )];
765
+ [data addObject: (variantCode ? variantCode : @" " )];
766
+ }
767
+
768
+ // Add any secondary locales/languages to the list.
752
769
for (NSString * localeID in preferredLocales) {
753
- NSLocale * currentLocale = [[NSLocale alloc ] initWithLocaleIdentifier: localeID];
770
+ NSLocale * currentLocale = [[[ NSLocale alloc ] initWithLocaleIdentifier: localeID] autorelease ];
754
771
NSString * languageCode = [currentLocale objectForKey: NSLocaleLanguageCode ];
755
772
NSString * countryCode = [currentLocale objectForKey: NSLocaleCountryCode ];
756
773
NSString * scriptCode = [currentLocale objectForKey: NSLocaleScriptCode ];
757
774
NSString * variantCode = [currentLocale objectForKey: NSLocaleVariantCode ];
758
- if (!languageCode || !countryCode ) {
775
+ if (!languageCode) {
759
776
continue ;
760
777
}
761
778
[data addObject: languageCode];
762
- [data addObject: countryCode];
779
+ [data addObject: ( countryCode ? countryCode : @" " ) ];
763
780
[data addObject: (scriptCode ? scriptCode : @" " )];
764
781
[data addObject: (variantCode ? variantCode : @" " )];
765
782
}
0 commit comments