Title: [124834] trunk/Source/WebCore
Revision
124834
Author
[email protected]
Date
2012-08-06 19:01:26 -0700 (Mon, 06 Aug 2012)

Log Message

[Chromium-Mac] Use the default locale only if the browser locale matches to it
https://bugs.webkit.org/show_bug.cgi?id=93227

Reviewed by Hajime Morita.

For a calendar picker, we have used month names and day-of-week names
obtained from the OS default locale. However, the year-month format and
[Today] [Clear] labels are decided with the browser locale. It made
calendar pickers with mixed languages.

To make calendar pickers with a single language, we use the OS default
locale only if the browser locale matches to it.

No new tests. Behavior for locale setting is not testable in WebKit.

* platform/text/mac/LocaleMac.mm:
(WebCore::languageFromLocale):
A helper for determineLocale. This returns the language part of the
specified locale identifier.
(WebCore::determineLocale):
If the browser language matches to the language of the current NSLocale,
returns the current NSLocale. Otherwise, returns a NSLocale with the
browser language.
Note that [NSLolca localeIdentifier] returns a string in
<language>_<country> format though defaultLanguage() in Chromium returns
a string in <language>-<country> format.
(WebCore::LocaleMac::currentLocale):
Use determineLocale.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (124833 => 124834)


--- trunk/Source/WebCore/ChangeLog	2012-08-07 01:57:28 UTC (rev 124833)
+++ trunk/Source/WebCore/ChangeLog	2012-08-07 02:01:26 UTC (rev 124834)
@@ -1,3 +1,34 @@
+2012-08-05  Kent Tamura  <[email protected]>
+
+        [Chromium-Mac] Use the default locale only if the browser locale matches to it
+        https://bugs.webkit.org/show_bug.cgi?id=93227
+
+        Reviewed by Hajime Morita.
+
+        For a calendar picker, we have used month names and day-of-week names
+        obtained from the OS default locale. However, the year-month format and
+        [Today] [Clear] labels are decided with the browser locale. It made
+        calendar pickers with mixed languages.
+
+        To make calendar pickers with a single language, we use the OS default
+        locale only if the browser locale matches to it.
+
+        No new tests. Behavior for locale setting is not testable in WebKit.
+
+        * platform/text/mac/LocaleMac.mm:
+        (WebCore::languageFromLocale):
+        A helper for determineLocale. This returns the language part of the
+        specified locale identifier.
+        (WebCore::determineLocale):
+        If the browser language matches to the language of the current NSLocale,
+        returns the current NSLocale. Otherwise, returns a NSLocale with the
+        browser language.
+        Note that [NSLolca localeIdentifier] returns a string in
+        <language>_<country> format though defaultLanguage() in Chromium returns
+        a string in <language>-<country> format.
+        (WebCore::LocaleMac::currentLocale):
+        Use determineLocale.
+
 2012-08-06  Luke Macpherson   <[email protected]>
 
         Handle variables in CSSParser::parseValidPrimitive(), preventing null return value.

Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (124833 => 124834)


--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm	2012-08-07 01:57:28 UTC (rev 124833)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm	2012-08-07 02:01:26 UTC (rev 124834)
@@ -33,6 +33,7 @@
 
 #import <Foundation/NSDateFormatter.h>
 #import <Foundation/NSLocale.h>
+#include "Language.h"
 #include "LocalizedDate.h"
 #include "LocalizedStrings.h"
 #include <wtf/DateMath.h>
@@ -74,9 +75,30 @@
     return adoptPtr(new LocaleMac(localeIdentifier));
 }
 
+static inline String languageFromLocale(const String& locale)
+{
+    String normalizedLocale = locale;
+    normalizedLocale.replace('-', '_');
+    size_t separatorPosition = normalizedLocale.find('_');
+    if (separatorPosition == notFound)
+        return normalizedLocale;
+    return normalizedLocale.left(separatorPosition);
+}
+
+static NSLocale* determineLocale()
+{
+    NSLocale* currentLocale = [NSLocale currentLocale];
+    String currentLocaleLanguage = languageFromLocale(String([currentLocale localeIdentifier]));
+    String browserLanguage = languageFromLocale(defaultLanguage());
+    if (equalIgnoringCase(currentLocaleLanguage, browserLanguage))
+        return currentLocale;
+    // It seems initWithLocaleIdentifier accepts dash-separated locale identifier.
+    return [[NSLocale alloc] initWithLocaleIdentifier:defaultLanguage()];
+}
+
 LocaleMac* LocaleMac::currentLocale()
 {
-    static LocaleMac* currentLocale = new LocaleMac([NSLocale currentLocale]);
+    static LocaleMac* currentLocale = new LocaleMac(determineLocale());
     return currentLocale;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to