Changeset 203141 in webkit
- Timestamp:
- Jul 12, 2016 5:05:25 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r203134 r203141 1 2016-07-12 Filip Pizlo <fpizlo@apple.com> 2 3 platformUserPreferredLanguages on Mac should not try to put the region into the language 4 https://bugs.webkit.org/show_bug.cgi?id=159693 5 6 Rubber stamped by Alexey Proskuryakov. 7 8 Currently, navigator.language is the thing that we use as the BCP-47 tag in our Intl code 9 when certain APIs are called without a locale argument. That mostly makes sense, and is 10 deeply wired into our engine. 11 12 In r200105, we made Intl aware of the region as a separate thing from the language by having 13 platformUserPreferredLanguages() return something like a BCP-47 tag that was 14 <language>-<region>. For example, if I told System Preferences that I want to speak English 15 but live in Poland then we'd get "en-pl". This had the effect of making Intl APIs format 16 dates using Polish formatting, for example. 17 18 But this is an odd change, since that same function also feeds into navigator.language. 19 "en-pl" isn't what we want there, since my System Preferences settings aren't supposed to 20 mean that I want to speak Polish-style English. There's no such thing. 21 22 It may be worthwhile to wire the region settings more elegantly into Intl, but if we do that, 23 it should be via a mechanism that is separate from navigator.language. So, this change simply 24 reverts r200105. 25 26 * wtf/PlatformUserPreferredLanguagesMac.mm: 27 (WTF::httpStyleLanguageCode): 28 (WTF::platformUserPreferredLanguages): 29 (WTF::isValidICUCountryCode): Deleted. 30 1 31 2016-07-12 Per Arne Vollan <pvollan@apple.com> 2 32 -
trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm
r201038 r203141 78 78 namespace WTF { 79 79 80 static String httpStyleLanguageCode(NSString *language , NSString *country)80 static String httpStyleLanguageCode(NSString *language) 81 81 { 82 82 SInt32 languageCode; … … 85 85 CFStringEncoding stringEncoding; 86 86 87 bool languageDidSpecifyExplicitVariant = [language rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"-_"]].location != NSNotFound;88 89 87 // FIXME: This transformation is very wrong: 90 88 // 1. There is no reason why CFBundle localization names would be at all related to language names as used on the Web. … … 98 96 // Make the string lowercase. 99 97 NSString *lowercaseLanguageCode = [language lowercaseString]; 100 NSString *lowercaseCountryCode = [country lowercaseString]; 101 102 // If we see a "_" after a 2-letter language code: 103 // If the country is valid and the language did not specify a variant, replace the "_" and 104 // whatever comes after it with "-" followed by the country code. 105 // Otherwise, replace the "_" with a "-" and use whatever country 106 // CFBundleCopyLocalizationForLocalizationInfo() returned. 98 99 // Turn a '_' into a '-' if it appears after a 2-letter language code 107 100 if ([lowercaseLanguageCode length] >= 3 && [lowercaseLanguageCode characterAtIndex:2] == '_') { 108 if (country && !languageDidSpecifyExplicitVariant)109 return [NSString stringWithFormat:@"%@-%@", [lowercaseLanguageCode substringWithRange:NSMakeRange(0, 2)], lowercaseCountryCode];110 111 // Fall back to older behavior, which used the original language-based code but just changed112 // the "_" to a "-".113 101 RetainPtr<NSMutableString> mutableLanguageCode = adoptNS([lowercaseLanguageCode mutableCopy]); 114 102 [mutableLanguageCode.get() replaceCharactersInRange:NSMakeRange(2, 1) withString:@"-"]; … … 117 105 118 106 return lowercaseLanguageCode; 119 }120 121 static bool isValidICUCountryCode(NSString* countryCode)122 {123 if (!countryCode)124 return false;125 const char* const* countries = uloc_getISOCountries();126 const char* countryUTF8 = [countryCode UTF8String];127 for (unsigned i = 0; countries[i]; ++i) {128 const char* possibleCountry = countries[i];129 if (!strcmp(countryUTF8, possibleCountry))130 return true;131 }132 return false;133 107 } 134 108 … … 148 122 149 123 if (userPreferredLanguages.isEmpty()) { 150 RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCopyCurrent());151 NSString *countryCode = (NSString *)CFLocaleGetValue(locale.get(), kCFLocaleCountryCode);152 153 if (!isValidICUCountryCode(countryCode))154 countryCode = nil;155 156 124 RetainPtr<CFArrayRef> languages = adoptCF(CFLocaleCopyPreferredLanguages()); 157 125 CFIndex languageCount = CFArrayGetCount(languages.get()); … … 160 128 else { 161 129 for (CFIndex i = 0; i < languageCount; i++) 162 userPreferredLanguages.append(httpStyleLanguageCode((NSString *)CFArrayGetValueAtIndex(languages.get(), i) , countryCode));130 userPreferredLanguages.append(httpStyleLanguageCode((NSString *)CFArrayGetValueAtIndex(languages.get(), i))); 163 131 } 164 132 } -
trunk/Tools/ChangeLog
r203129 r203141 1 2016-07-12 Filip Pizlo <fpizlo@apple.com> 2 3 platformUserPreferredLanguages on Mac should not try to put the region into the language 4 https://bugs.webkit.org/show_bug.cgi?id=159693 5 6 Rubber stamped by Alexey Proskuryakov. 7 8 Revert the test change in r200105. 9 10 * TestWebKitAPI/Tests/mac/NavigatorLanguage.mm: 11 (TestWebKitAPI::languageForSystemLanguage): 12 1 13 2016-07-12 Chris Dumez <cdumez@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm
r200105 r203141 69 69 } 70 70 71 // These tests document current behavior. Some of the current results may not be right. Note that 72 // this oddly assumes that the user has set their language to something possibly-foreign but still 73 // left their region as US. Hence the "-us" variants. 74 // FIXME: These tests should also set the region to see how WebKit will handle that. 75 // https://bugs.webkit.org/show_bug.cgi?id=157039 71 // These tests document current behavior. Some of the current results may not be right. 76 72 NSArray *tests = @[ 77 @[@"ru", @"ru- us"], // This does not match other browsers or CFNetwork's Accept-Language, which all use "ru".73 @[@"ru", @"ru-ru"], // This does not match other browsers or CFNetwork's Accept-Language, which all use "ru". 78 74 @[@"en", @"en-us"], 79 75 @[@"en-GB", @"en-gb"], 80 76 @[@"en-US", @"en-us"], 81 @[@"ja", @"ja- us"],82 @[@"hi", @"hi- us"],77 @[@"ja", @"ja-jp"], 78 @[@"hi", @"hi-in"], 83 79 @[@"zh-TW", @"zh-tw"], // This should not map to the generic zh-hant, see rdar://problem/21395180. 84 80 @[@"zh-HK", @"zh-tw"], 85 @[@"es", @"es- us"],81 @[@"es", @"es-es"], 86 82 @[@"es-MX", @"es-xl"], 87 83 @[@"es-ES", @"es-es"], … … 91 87 @[@"pt-BR", @"pt-br"], 92 88 @[@"pt-PT", @"pt-pt"], 93 @[@"fr", @"fr- us"],89 @[@"fr", @"fr-fr"], 94 90 @[@"fr-CA", @"fr-ca"], 95 91 ];
Note: See TracChangeset
for help on using the changeset viewer.