Title: [113166] trunk/Source/WebCore
Revision
113166
Author
tk...@chromium.org
Date
2012-04-04 04:06:03 -0700 (Wed, 04 Apr 2012)

Log Message

Add localization functions for the calendar picker
https://bugs.webkit.org/show_bug.cgi?id=83129

Reviewed by Hajime Morita.

No behavior changes yet.

* WebCore.gypi: Add LocalizedCalendar.h and LocalizedCalendarICU.cpp.
* platform/LocalizedStrings.h: Add calendarTodayText() and calendarClearText().
* platform/text/LocalizedCalendar.h:
Added. This provides monthLabels(), weekDayShortLabels(), and firstDayOfWeek().
* platform/text/LocalizedCalendarICU.cpp: Added. ICU implementations of the above functions.
(WebCore::ScopedDateFormat): A wrapper for UDateFormat*.
(WebCore::ScopedDateFormat::ScopedDateFormat):
(WebCore::ScopedDateFormat::~ScopedDateFormat):
(WebCore::ScopedDateFormat::get):
(createFallbackMonthLabels): Creates fallback month labels in English.
(createLabelVector):
A helper for createMonthLabels() and createWeekDayShortLabels().
(createMonthLabels):
Creates month labels using createLabelVector() or createFallbackMonthLabels().
(WebCore::monthLabels):
(createFallbackWeekDayShortLabels): Creates fallback week labels in English.
(createWeekDayShortLabels):
Creates month labels using createLabelVector() or createFallbackWeekDayShortLabels().
(WebCore::weekDayShortLabels):
(getFirstDayOfWeek):
(WebCore::firstDayOfWeek):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (113165 => 113166)


--- trunk/Source/WebCore/ChangeLog	2012-04-04 11:00:21 UTC (rev 113165)
+++ trunk/Source/WebCore/ChangeLog	2012-04-04 11:06:03 UTC (rev 113166)
@@ -1,3 +1,34 @@
+2012-04-04  Kent Tamura  <tk...@chromium.org>
+
+        Add localization functions for the calendar picker
+        https://bugs.webkit.org/show_bug.cgi?id=83129
+
+        Reviewed by Hajime Morita.
+
+        No behavior changes yet.
+
+        * WebCore.gypi: Add LocalizedCalendar.h and LocalizedCalendarICU.cpp.
+        * platform/LocalizedStrings.h: Add calendarTodayText() and calendarClearText().
+        * platform/text/LocalizedCalendar.h:
+        Added. This provides monthLabels(), weekDayShortLabels(), and firstDayOfWeek().
+        * platform/text/LocalizedCalendarICU.cpp: Added. ICU implementations of the above functions.
+        (WebCore::ScopedDateFormat): A wrapper for UDateFormat*.
+        (WebCore::ScopedDateFormat::ScopedDateFormat):
+        (WebCore::ScopedDateFormat::~ScopedDateFormat):
+        (WebCore::ScopedDateFormat::get):
+        (createFallbackMonthLabels): Creates fallback month labels in English.
+        (createLabelVector):
+        A helper for createMonthLabels() and createWeekDayShortLabels().
+        (createMonthLabels):
+        Creates month labels using createLabelVector() or createFallbackMonthLabels().
+        (WebCore::monthLabels):
+        (createFallbackWeekDayShortLabels): Creates fallback week labels in English.
+        (createWeekDayShortLabels):
+        Creates month labels using createLabelVector() or createFallbackWeekDayShortLabels().
+        (WebCore::weekDayShortLabels):
+        (getFirstDayOfWeek):
+        (WebCore::firstDayOfWeek):
+
 2012-04-03  Hans Wennborg  <h...@chromium.org>
 
         Speech _javascript_ API: Plumbing for Chromium

Modified: trunk/Source/WebCore/WebCore.gypi (113165 => 113166)


--- trunk/Source/WebCore/WebCore.gypi	2012-04-04 11:00:21 UTC (rev 113165)
+++ trunk/Source/WebCore/WebCore.gypi	2012-04-04 11:06:03 UTC (rev 113166)
@@ -4437,6 +4437,8 @@
             'platform/text/LocaleToScriptMapping.h',
             'platform/text/LocaleToScriptMappingDefault.cpp',
             'platform/text/LocaleToScriptMappingICU.cpp',
+            'platform/text/LocalizedCalendar.h',
+            'platform/text/LocalizedCalendarICU.cpp',
             'platform/text/LocalizedDate.h',
             'platform/text/LocalizedDateNone.cpp',
             'platform/text/LocalizedNumber.h',

Modified: trunk/Source/WebCore/platform/LocalizedStrings.h (113165 => 113166)


--- trunk/Source/WebCore/platform/LocalizedStrings.h	2012-04-04 11:00:21 UTC (rev 113165)
+++ trunk/Source/WebCore/platform/LocalizedStrings.h	2012-04-04 11:06:03 UTC (rev 113166)
@@ -211,6 +211,10 @@
     String validationMessageRangeUnderflowText(const String& minimum);
     String validationMessageRangeOverflowText(const String& maximum);
     String validationMessageStepMismatchText(const String& base, const String& step);
+#if ENABLE(CALENDAR_PICKER)
+    String calendarTodayText();
+    String calendarClearText();
+#endif
 
 #if !PLATFORM(CHROMIUM)
 #define WEB_UI_STRING(string, description) WebCore::localizedString(string)

Added: trunk/Source/WebCore/platform/text/LocalizedCalendar.h (0 => 113166)


--- trunk/Source/WebCore/platform/text/LocalizedCalendar.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/text/LocalizedCalendar.h	2012-04-04 11:06:03 UTC (rev 113166)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LocalizedCalendar_h
+#define LocalizedCalendar_h
+
+#if ENABLE(CALENDAR_PICKER)
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+// Returns a vector of string of which size is 12. The first item is a
+// localized string of January, and the last item is a localized
+// string of December. These strings should not be abbreviations.
+const Vector<String>& monthLabels();
+
+// Returns a vector of string of which size is 7. The first item is a
+// localized short string of Monday, and the last item is a localized
+// short string of Saturday. These strings should be short.
+const Vector<String>& weekDayShortLabels();
+
+// The first day of a week. 0 is Sunday, and 6 is Saturday.
+unsigned firstDayOfWeek();
+
+}
+#endif
+#endif

Added: trunk/Source/WebCore/platform/text/LocalizedCalendarICU.cpp (0 => 113166)


--- trunk/Source/WebCore/platform/text/LocalizedCalendarICU.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/text/LocalizedCalendarICU.cpp	2012-04-04 11:06:03 UTC (rev 113166)
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LocalizedCalendar.h"
+
+#if ENABLE(CALENDAR_PICKER)
+#include "Language.h"
+#include <unicode/ucal.h>
+#include <unicode/udat.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+class ScopedDateFormat {
+public:
+    ScopedDateFormat()
+    {
+        UErrorCode status = U_ZERO_ERROR;
+        m_dateFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
+    }
+
+    ~ScopedDateFormat()
+    {
+        if (m_dateFormat)
+            udat_close(m_dateFormat);
+    }
+
+    UDateFormat* get() const { return m_dateFormat; }
+
+private:
+    UDateFormat* m_dateFormat;
+};
+
+static PassOwnPtr<Vector<String> > createFallbackMonthLabels()
+{
+    OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
+    labels->reserveCapacity(12);
+    labels->append("January");
+    labels->append("February");
+    labels->append("March");
+    labels->append("April");
+    labels->append("May");
+    labels->append("June");
+    labels->append("July");
+    labels->append("August");
+    labels->append("September");
+    labels->append("October");
+    labels->append("November");
+    labels->append("December");
+    return labels.release();
+}
+
+static PassOwnPtr<Vector<String> > createLabelVector(UDateFormatSymbolType type, int32_t size)
+{
+    ScopedDateFormat dateFormat;
+    if (!dateFormat.get())
+        return PassOwnPtr<Vector<String> >();
+    if (udat_countSymbols(dateFormat.get(), type) != size)
+        return PassOwnPtr<Vector<String> >();
+
+    OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
+    labels->reserveCapacity(size);
+    for (int32_t i = 0; i < size; ++i) {
+        UErrorCode status = U_ZERO_ERROR;
+        int32_t length = udat_getSymbols(dateFormat.get(), type, i, 0, 0, &status);
+        if (status != U_BUFFER_OVERFLOW_ERROR)
+            return PassOwnPtr<Vector<String> >();
+        Vector<UChar> buffer(length);
+        status = U_ZERO_ERROR;
+        udat_getSymbols(dateFormat.get(), type, i, buffer.data(), length, &status);
+        if (U_FAILURE(status))
+            return PassOwnPtr<Vector<String> >();
+        labels->append(String::adopt(buffer));
+    }
+    return labels.release();
+}
+
+static PassOwnPtr<Vector<String> > createMonthLabels()
+{
+    OwnPtr<Vector<String> > labels = createLabelVector(UDAT_MONTHS, 12);
+    return labels ? labels.release() : createFallbackMonthLabels();
+}
+
+const Vector<String>& monthLabels()
+{
+    static const Vector<String>* labels = createMonthLabels().leakPtr();
+    return *labels;
+}
+
+static PassOwnPtr<Vector<String> > createFallbackWeekDayShortLabels()
+{
+    OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
+    labels->reserveCapacity(7);
+    labels->append("Sun");
+    labels->append("Mon");
+    labels->append("Tue");
+    labels->append("Wed");
+    labels->append("Thu");
+    labels->append("Fri");
+    labels->append("Sat");
+    return labels.release();
+}
+
+static PassOwnPtr<Vector<String> > createWeekDayShortLabels()
+{
+    OwnPtr<Vector<String> > labels = createLabelVector(UDAT_SHORT_WEEKDAYS, 7);
+    return labels ? labels.release() : createFallbackWeekDayShortLabels();
+}
+
+const Vector<String>& weekDayShortLabels()
+{
+    static const Vector<String>* labels = createWeekDayShortLabels().leakPtr();
+    return *labels;
+}
+
+static unsigned getFirstDayOfWeek()
+{
+    ScopedDateFormat dateFormat;
+    if (!dateFormat.get())
+        return 0;
+    unsigned firstDay = ucal_getAttribute(udat_getCalendar(dateFormat.get()), UCAL_FIRST_DAY_OF_WEEK);
+    return firstDay;
+}
+
+unsigned firstDayOfWeek()
+{
+    static unsigned firstDay = getFirstDayOfWeek();
+    return firstDay;
+}
+
+}
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to