<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[203141] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/203141">203141</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2016-07-12 17:05:25 -0700 (Tue, 12 Jul 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>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.
Source/WTF:
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 <a href="http://trac.webkit.org/projects/webkit/changeset/200105">r200105</a>, 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 <a href="http://trac.webkit.org/projects/webkit/changeset/200105">r200105</a>.
* wtf/PlatformUserPreferredLanguagesMac.mm:
(WTF::httpStyleLanguageCode):
(WTF::platformUserPreferredLanguages):
(WTF::isValidICUCountryCode): Deleted.
Tools:
Revert the test change in <a href="http://trac.webkit.org/projects/webkit/changeset/200105">r200105</a>.
* TestWebKitAPI/Tests/mac/NavigatorLanguage.mm:
(TestWebKitAPI::languageForSystemLanguage):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfPlatformUserPreferredLanguagesMacmm">trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsmacNavigatorLanguagemm">trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (203140 => 203141)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-07-12 Filip Pizlo <fpizlo@apple.com>
+
+ 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.
+
</ins><span class="cx"> 2016-07-12 Per Arne Vollan <pvollan@apple.com>
</span><span class="cx">
</span><span class="cx"> [Win] Fix for build error when trying to version stamp dll.
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformUserPreferredLanguagesMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm (203140 => 203141)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -77,7 +77,7 @@
</span><span class="cx">
</span><span class="cx"> namespace WTF {
</span><span class="cx">
</span><del>-static String httpStyleLanguageCode(NSString *language, NSString *country)
</del><ins>+static String httpStyleLanguageCode(NSString *language)
</ins><span class="cx"> {
</span><span class="cx"> SInt32 languageCode;
</span><span class="cx"> SInt32 regionCode;
</span><span class="lines">@@ -84,8 +84,6 @@
</span><span class="cx"> SInt32 scriptCode;
</span><span class="cx"> CFStringEncoding stringEncoding;
</span><span class="cx">
</span><del>- bool languageDidSpecifyExplicitVariant = [language rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"-_"]].location != NSNotFound;
-
</del><span class="cx"> // FIXME: This transformation is very wrong:
</span><span class="cx"> // 1. There is no reason why CFBundle localization names would be at all related to language names as used on the Web.
</span><span class="cx"> // 2. Script Manager codes cannot represent all languages that are now supported by the platform, so the conversion is lossy.
</span><span class="lines">@@ -97,19 +95,9 @@
</span><span class="cx">
</span><span class="cx"> // Make the string lowercase.
</span><span class="cx"> NSString *lowercaseLanguageCode = [language lowercaseString];
</span><del>- 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.
</del><ins>+
+ // Turn a '_' into a '-' if it appears after a 2-letter language code
</ins><span class="cx"> if ([lowercaseLanguageCode length] >= 3 && [lowercaseLanguageCode characterAtIndex:2] == '_') {
</span><del>- 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 "-".
</del><span class="cx"> RetainPtr<NSMutableString> mutableLanguageCode = adoptNS([lowercaseLanguageCode mutableCopy]);
</span><span class="cx"> [mutableLanguageCode.get() replaceCharactersInRange:NSMakeRange(2, 1) withString:@"-"];
</span><span class="cx"> return mutableLanguageCode.get();
</span><span class="lines">@@ -118,20 +106,6 @@
</span><span class="cx"> return lowercaseLanguageCode;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-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;
-}
-
</del><span class="cx"> Vector<String> platformUserPreferredLanguages()
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="lines">@@ -147,12 +121,6 @@
</span><span class="cx"> Vector<String>& userPreferredLanguages = preferredLanguages();
</span><span class="cx">
</span><span class="cx"> if (userPreferredLanguages.isEmpty()) {
</span><del>- RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCopyCurrent());
- NSString *countryCode = (NSString *)CFLocaleGetValue(locale.get(), kCFLocaleCountryCode);
-
- if (!isValidICUCountryCode(countryCode))
- countryCode = nil;
-
</del><span class="cx"> RetainPtr<CFArrayRef> languages = adoptCF(CFLocaleCopyPreferredLanguages());
</span><span class="cx"> CFIndex languageCount = CFArrayGetCount(languages.get());
</span><span class="cx"> if (!languageCount)
</span><span class="lines">@@ -159,7 +127,7 @@
</span><span class="cx"> userPreferredLanguages.append("en");
</span><span class="cx"> else {
</span><span class="cx"> for (CFIndex i = 0; i < languageCount; i++)
</span><del>- userPreferredLanguages.append(httpStyleLanguageCode((NSString *)CFArrayGetValueAtIndex(languages.get(), i), countryCode));
</del><ins>+ userPreferredLanguages.append(httpStyleLanguageCode((NSString *)CFArrayGetValueAtIndex(languages.get(), i)));
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (203140 => 203141)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-07-13 00:02:21 UTC (rev 203140)
+++ trunk/Tools/ChangeLog        2016-07-13 00:05:25 UTC (rev 203141)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-07-12 Filip Pizlo <fpizlo@apple.com>
+
+ 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.
+
+ Revert the test change in r200105.
+
+ * TestWebKitAPI/Tests/mac/NavigatorLanguage.mm:
+ (TestWebKitAPI::languageForSystemLanguage):
+
</ins><span class="cx"> 2016-07-12 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> [WK2] Protect against bad database data in LocalStorageDatabase::importItems()
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsmacNavigatorLanguagemm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm (203140 => 203141)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -68,21 +68,17 @@
</span><span class="cx"> return [webView stringByEvaluatingJavaScriptFromString:@"navigator.language"];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-// 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
</del><ins>+// These tests document current behavior. Some of the current results may not be right.
</ins><span class="cx"> NSArray *tests = @[
</span><del>- @[@"ru", @"ru-us"], // This does not match other browsers or CFNetwork's Accept-Language, which all use "ru".
</del><ins>+ @[@"ru", @"ru-ru"], // This does not match other browsers or CFNetwork's Accept-Language, which all use "ru".
</ins><span class="cx"> @[@"en", @"en-us"],
</span><span class="cx"> @[@"en-GB", @"en-gb"],
</span><span class="cx"> @[@"en-US", @"en-us"],
</span><del>- @[@"ja", @"ja-us"],
- @[@"hi", @"hi-us"],
</del><ins>+ @[@"ja", @"ja-jp"],
+ @[@"hi", @"hi-in"],
</ins><span class="cx"> @[@"zh-TW", @"zh-tw"], // This should not map to the generic zh-hant, see rdar://problem/21395180.
</span><span class="cx"> @[@"zh-HK", @"zh-tw"],
</span><del>- @[@"es", @"es-us"],
</del><ins>+ @[@"es", @"es-es"],
</ins><span class="cx"> @[@"es-MX", @"es-xl"],
</span><span class="cx"> @[@"es-ES", @"es-es"],
</span><span class="cx"> @[@"es-419", @"es-xl"],
</span><span class="lines">@@ -90,7 +86,7 @@
</span><span class="cx"> @[@"zh-Hant", @"zh-tw"],
</span><span class="cx"> @[@"pt-BR", @"pt-br"],
</span><span class="cx"> @[@"pt-PT", @"pt-pt"],
</span><del>- @[@"fr", @"fr-us"],
</del><ins>+ @[@"fr", @"fr-fr"],
</ins><span class="cx"> @[@"fr-CA", @"fr-ca"],
</span><span class="cx"> ];
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>