@@ -748,18 +748,35 @@ - (void)onMemoryWarning:(NSNotification*)notification {
748748
749749- (void )onLocaleUpdated : (NSNotification *)notification {
750750 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.
752769 for (NSString * localeID in preferredLocales) {
753- NSLocale * currentLocale = [[NSLocale alloc ] initWithLocaleIdentifier: localeID];
770+ NSLocale * currentLocale = [[[ NSLocale alloc ] initWithLocaleIdentifier: localeID] autorelease ];
754771 NSString * languageCode = [currentLocale objectForKey: NSLocaleLanguageCode ];
755772 NSString * countryCode = [currentLocale objectForKey: NSLocaleCountryCode ];
756773 NSString * scriptCode = [currentLocale objectForKey: NSLocaleScriptCode ];
757774 NSString * variantCode = [currentLocale objectForKey: NSLocaleVariantCode ];
758- if (!languageCode || !countryCode ) {
775+ if (!languageCode) {
759776 continue ;
760777 }
761778 [data addObject: languageCode];
762- [data addObject: countryCode];
779+ [data addObject: ( countryCode ? countryCode : @" " ) ];
763780 [data addObject: (scriptCode ? scriptCode : @" " )];
764781 [data addObject: (variantCode ? variantCode : @" " )];
765782 }
0 commit comments