Modified: trunk/Source/WTF/ChangeLog (203140 => 203141)
--- trunk/Source/WTF/ChangeLog 2016-07-13 00:02:21 UTC (rev 203140)
+++ trunk/Source/WTF/ChangeLog 2016-07-13 00:05:25 UTC (rev 203141)
@@ -1,3 +1,33 @@
+2016-07-12 Filip Pizlo <[email protected]>
+
+ platformUserPreferredLanguages on Mac should not try to put the region into the language
+ https://bugs.webkit.org/show_bug.cgi?id=159693
+
+ Rubber stamped by Alexey Proskuryakov.
+
+ Currently, navigator.language is the thing that we use as the BCP-47 tag in our Intl code
+ when certain APIs are called without a locale argument. That mostly makes sense, and is
+ deeply wired into our engine.
+
+ In r200105, we made Intl aware of the region as a separate thing from the language by having
+ platformUserPreferredLanguages() return something like a BCP-47 tag that was
+ <language>-<region>. For example, if I told System Preferences that I want to speak English
+ but live in Poland then we'd get "en-pl". This had the effect of making Intl APIs format
+ dates using Polish formatting, for example.
+
+ But this is an odd change, since that same function also feeds into navigator.language.
+ "en-pl" isn't what we want there, since my System Preferences settings aren't supposed to
+ mean that I want to speak Polish-style English. There's no such thing.
+
+ It may be worthwhile to wire the region settings more elegantly into Intl, but if we do that,
+ it should be via a mechanism that is separate from navigator.language. So, this change simply
+ reverts r200105.
+
+ * wtf/PlatformUserPreferredLanguagesMac.mm:
+ (WTF::httpStyleLanguageCode):
+ (WTF::platformUserPreferredLanguages):
+ (WTF::isValidICUCountryCode): Deleted.
+
2016-07-12 Per Arne Vollan <[email protected]>
[Win] Fix for build error when trying to version stamp dll.
Modified: trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm (203140 => 203141)
--- trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm 2016-07-13 00:02:21 UTC (rev 203140)
+++ trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm 2016-07-13 00:05:25 UTC (rev 203141)
@@ -77,7 +77,7 @@
namespace WTF {
-static String httpStyleLanguageCode(NSString *language, NSString *country)
+static String httpStyleLanguageCode(NSString *language)
{
SInt32 languageCode;
SInt32 regionCode;
@@ -84,8 +84,6 @@
SInt32 scriptCode;
CFStringEncoding stringEncoding;
- bool languageDidSpecifyExplicitVariant = [language rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"-_"]].location != NSNotFound;
-
// FIXME: This transformation is very wrong:
// 1. There is no reason why CFBundle localization names would be at all related to language names as used on the Web.
// 2. Script Manager codes cannot represent all languages that are now supported by the platform, so the conversion is lossy.
@@ -97,19 +95,9 @@
// Make the string lowercase.
NSString *lowercaseLanguageCode = [language lowercaseString];
- NSString *lowercaseCountryCode = [country lowercaseString];
-
- // If we see a "_" after a 2-letter language code:
- // If the country is valid and the language did not specify a variant, replace the "_" and
- // whatever comes after it with "-" followed by the country code.
- // Otherwise, replace the "_" with a "-" and use whatever country
- // CFBundleCopyLocalizationForLocalizationInfo() returned.
+
+ // Turn a '_' into a '-' if it appears after a 2-letter language code
if ([lowercaseLanguageCode length] >= 3 && [lowercaseLanguageCode characterAtIndex:2] == '_') {
- if (country && !languageDidSpecifyExplicitVariant)
- return [NSString stringWithFormat:@"%@-%@", [lowercaseLanguageCode substringWithRange:NSMakeRange(0, 2)], lowercaseCountryCode];
-
- // Fall back to older behavior, which used the original language-based code but just changed
- // the "_" to a "-".
RetainPtr<NSMutableString> mutableLanguageCode = adoptNS([lowercaseLanguageCode mutableCopy]);
[mutableLanguageCode.get() replaceCharactersInRange:NSMakeRange(2, 1) withString:@"-"];
return mutableLanguageCode.get();
@@ -118,20 +106,6 @@
return lowercaseLanguageCode;
}
-static bool isValidICUCountryCode(NSString* countryCode)
-{
- if (!countryCode)
- return false;
- const char* const* countries = uloc_getISOCountries();
- const char* countryUTF8 = [countryCode UTF8String];
- for (unsigned i = 0; countries[i]; ++i) {
- const char* possibleCountry = countries[i];
- if (!strcmp(countryUTF8, possibleCountry))
- return true;
- }
- return false;
-}
-
Vector<String> platformUserPreferredLanguages()
{
#if PLATFORM(MAC)
@@ -147,12 +121,6 @@
Vector<String>& userPreferredLanguages = preferredLanguages();
if (userPreferredLanguages.isEmpty()) {
- RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCopyCurrent());
- NSString *countryCode = (NSString *)CFLocaleGetValue(locale.get(), kCFLocaleCountryCode);
-
- if (!isValidICUCountryCode(countryCode))
- countryCode = nil;
-
RetainPtr<CFArrayRef> languages = adoptCF(CFLocaleCopyPreferredLanguages());
CFIndex languageCount = CFArrayGetCount(languages.get());
if (!languageCount)
@@ -159,7 +127,7 @@
userPreferredLanguages.append("en");
else {
for (CFIndex i = 0; i < languageCount; i++)
- userPreferredLanguages.append(httpStyleLanguageCode((NSString *)CFArrayGetValueAtIndex(languages.get(), i), countryCode));
+ userPreferredLanguages.append(httpStyleLanguageCode((NSString *)CFArrayGetValueAtIndex(languages.get(), i)));
}
}
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm (203140 => 203141)
--- trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm 2016-07-13 00:02:21 UTC (rev 203140)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm 2016-07-13 00:05:25 UTC (rev 203141)
@@ -68,21 +68,17 @@
return [webView stringByEvaluatingJavaScriptFromString:@"navigator.language"];
}
-// These tests document current behavior. Some of the current results may not be right. Note that
-// this oddly assumes that the user has set their language to something possibly-foreign but still
-// left their region as US. Hence the "-us" variants.
-// FIXME: These tests should also set the region to see how WebKit will handle that.
-// https://bugs.webkit.org/show_bug.cgi?id=157039
+// These tests document current behavior. Some of the current results may not be right.
NSArray *tests = @[
- @[@"ru", @"ru-us"], // This does not match other browsers or CFNetwork's Accept-Language, which all use "ru".
+ @[@"ru", @"ru-ru"], // This does not match other browsers or CFNetwork's Accept-Language, which all use "ru".
@[@"en", @"en-us"],
@[@"en-GB", @"en-gb"],
@[@"en-US", @"en-us"],
- @[@"ja", @"ja-us"],
- @[@"hi", @"hi-us"],
+ @[@"ja", @"ja-jp"],
+ @[@"hi", @"hi-in"],
@[@"zh-TW", @"zh-tw"], // This should not map to the generic zh-hant, see rdar://problem/21395180.
@[@"zh-HK", @"zh-tw"],
- @[@"es", @"es-us"],
+ @[@"es", @"es-es"],
@[@"es-MX", @"es-xl"],
@[@"es-ES", @"es-es"],
@[@"es-419", @"es-xl"],
@@ -90,7 +86,7 @@
@[@"zh-Hant", @"zh-tw"],
@[@"pt-BR", @"pt-br"],
@[@"pt-PT", @"pt-pt"],
- @[@"fr", @"fr-us"],
+ @[@"fr", @"fr-fr"],
@[@"fr-CA", @"fr-ca"],
];