click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bck...@apache.org
Subject svn commit: r957933 - in /click/trunk/click: documentation/docs/ extras/src/META-INF/resources/click/calendar/ extras/src/org/apache/click/extras/control/
Date Fri, 25 Jun 2010 13:10:18 GMT
Author: bckfnn
Date: Fri Jun 25 13:10:17 2010
New Revision: 957933

URL: http://svn.apache.org/viewvc?rev=957933&view=rev
Log:
load day and month names from JDK and other translations from the 
DateField.properties files. CLK-650

Removed:
    click/trunk/click/extras/src/META-INF/resources/click/calendar/da.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/de.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/fi.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/fr.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/ja.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/nl.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/pl.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/pt.js
    click/trunk/click/extras/src/META-INF/resources/click/calendar/ru.js
Modified:
    click/trunk/click/documentation/docs/roadmap-changes.html
    click/trunk/click/documentation/docs/upgrade-path.html
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_da.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_de.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fi.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fr.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ja.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_nl.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_pl.properties
    click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ru.properties

Modified: click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/roadmap-changes.html?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ click/trunk/click/documentation/docs/roadmap-changes.html Fri Jun 25 13:10:17 2010
@@ -93,6 +93,11 @@ includes improved Ajax support and @Bind
       </div>
       <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
          <li class="change">
+            Load <a href="extras-api/org/apache/click/extras/control/DateField.html">DateField</a>
+            translations for month and day names from the JDK.
+            [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-650">CLK-650</a>].
+         </li>
+         <li class="change">
             Added <a href="click-api/org/apache/click/service/MessagesMapService.html">MessagesMapService</a>
             interface to support plugable messages map implementations
             [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-655">CLK-655</a>].

Modified: click/trunk/click/documentation/docs/upgrade-path.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/upgrade-path.html?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/upgrade-path.html (original)
+++ click/trunk/click/documentation/docs/upgrade-path.html Fri Jun 25 13:10:17 2010
@@ -86,6 +86,13 @@ versions please email the Click user gro
       <li class="change">
         2.3.0 is backwards compatible with 2.2.0.
       </li>
+      <li class="change">
+        The DateField control now accepts month and day names spelled in the 
+        locale of the browser or application (see 
+        <a href="click-api/org/apache/click/Context.html#getLocale()">Context.getLocale()</a>).
+        In previous version a few locales used localized spelling of month and 
+        week days names and the remaining locales used English names.  
+      </li>
     </ul>
   </dd>
   <dt><a name="2.2.0"></a>

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java Fri Jun 25
13:10:17 2010
@@ -19,9 +19,9 @@
 package org.apache.click.extras.control;
 
 import java.sql.Timestamp;
+import java.text.DateFormatSymbols;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -35,6 +35,7 @@ import org.apache.click.element.JsImport
 import org.apache.click.element.JsScript;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * Provides a Date Field control:   &lt;input type='text'&gt;&lt;img&gt;.
@@ -138,10 +139,6 @@ public class DateField extends TextField
 
     private static final long serialVersionUID = 1L;
 
-    /** Supported locales. */
-    static final String[] SUPPORTED_LANGUAGES =
-        {"da", "de", "en", "fi", "fr", "ja", "nl", "pl", "pt", "ru"};
-
     // Instance Variables -----------------------------------------------------
 
     /** The DateField's date value. */
@@ -623,10 +620,7 @@ public class DateField extends TextField
             // English is default language, only include language pack if other
             // than English
             if (!"en".equals(language)) {
-                JsImport jsImport = new JsImport("/click/calendar/"
-                    + language + ".js", versionIndicator);
-                jsImport.setAttribute("charset", "UTF-8");
-                headElements.add(jsImport);
+                addCalenderTranslations(headElements);
             }
         }
 
@@ -870,7 +864,6 @@ public class DateField extends TextField
      * <pre class="prettyprint">
      * Click.addLoadEvent(function() {
      *   Event.observe('my-calendar-button', 'click', function(){
-     *     Date.first_day_of_week=0;
      *     calendar = new CalendarDateSelect($('my-calendar'), {
      *       minute_interval: 1,
      *       popup_by: 'my-calendar-button',
@@ -904,7 +897,6 @@ public class DateField extends TextField
             HtmlStringBuffer buffer = new HtmlStringBuffer(150);
 
             buffer.append("Event.observe('").append(imgId).append("', 'click', function(){");
-            buffer.append(" Date.first_day_of_week=").append(getFirstDayOfWeek() - 1).append(";");
             buffer.append(" calendar = new CalendarDateSelect($('").append(fieldId).append("'),
{");
             buffer.append("  minute_interval: 1, popup_by: '").append(imgId).append("',");
             buffer.append("  embedded: false,");
@@ -922,6 +914,98 @@ public class DateField extends TextField
     }
 
     /**
+     * Return the names of months and weekdays as a script.
+     */
+    protected void addCalenderTranslations(List<Element> headElements) {
+        JsScript script = new JsScript();
+        script.setId("$datefield_js_setup_global");
+        script.setRenderId(false);
+        if (!headElements.contains(script)) {
+            DateFormatSymbols dfs = new DateFormatSymbols(getLocale());
+
+            HtmlStringBuffer buffer = new HtmlStringBuffer(150);
+            buffer.append("Date.months=new Array(");
+            generateJavaScriptArray(buffer, dfs.getMonths(), 0, 12);
+            buffer.append(");\n");
+
+            buffer.append("Date.monthAbbreviations=new Array(");
+            generateJavaScriptArray(buffer, dfs.getShortMonths(), 0, 12);
+            buffer.append(");\n");
+
+            buffer.append("Date.dayNames=new Array(");
+            generateJavaScriptArray(buffer, dfs.getWeekdays(),
+                    Calendar.SUNDAY, Calendar.SATURDAY+1);
+            buffer.append(");\n");
+
+            buffer.append("Date.dayAbbreviations=new Array(");
+            generateJavaScriptArray(buffer, dfs.getShortWeekdays(),
+                    Calendar.SUNDAY, Calendar.SATURDAY+1);
+            buffer.append(");\n");
+
+            String[] weekdays = null;
+            if (getMessages().containsKey("calendar-weekdays-heading")) {
+                String headings = getMessage("calendar-weekdays-heading");
+                weekdays = StringUtils.splitPreserveAllTokens("," + headings, ',');
+            } else {
+                weekdays = dfs.getShortWeekdays();
+            }
+            String[] days = new String[7];
+            for (int i = 0; i < 7; i++) {
+                days[i] = weekdays[(i + getFirstDayOfWeek()-1) % 7 + 1];   
+            }
+            buffer.append("Date.weekdays=new Array(");
+            generateJavaScriptArray(buffer, days, 0, 7);
+            buffer.append(");\n");
+
+            buffer.append("Date.first_day_of_week=").append(getFirstDayOfWeek() - 1).append(";\n");
+            if (getMessages().containsKey("calendar-ok")) {
+                buffer.append("_translations[\"OK\"] = \"");
+                buffer.append(getMessage("calendar-ok"));
+                buffer.append("\";\n");
+            }
+            if (getMessages().containsKey("calendar-now")) {
+                buffer.append("_translations[\"Now\"] = \"");
+                buffer.append(getMessage("calendar-now"));
+                buffer.append("\";\n");
+            }
+            if (getMessages().containsKey("calendar-today")) {
+                buffer.append("_translations[\"Today\"] = \"");
+                buffer.append(getMessage("calendar-today"));
+                buffer.append("\";\n");
+            }
+            if (getMessages().containsKey("calendar-clear")) {
+                buffer.append("_translations[\"Clear\"] = \"");
+                buffer.append(getMessage("calendar-clear"));
+                buffer.append("\";\n");
+            }
+
+            script.setContent(buffer.toString());
+            headElements.add(script);
+        }
+    }
+
+    /**
+     * Append a list of quoted names delimited by commas.
+     * @param buffer the buffer to append to.
+     * @param names the list of names.
+     * @param start start index in the list.
+     * @param end end index in the list.
+     */
+    private void generateJavaScriptArray(HtmlStringBuffer buffer, 
+           String[] names, int start, int end) {
+        for (int i = start; i < end; i++) {
+            buffer.append('"');
+            buffer.append(names[i]);
+            buffer.append('"');
+            if (i < end - 1) {
+                buffer.append(',');
+            }
+        }
+    }
+       
+
+
+    /**
      * Return the first day of the week. For example e.g., Sunday in US,
      * Monday in France and Australia.
      *
@@ -930,15 +1014,12 @@ public class DateField extends TextField
     protected int getFirstDayOfWeek() {
         Locale locale = getLocale();
 
-        Calendar calendar = Calendar.getInstance(getLocale());
-
-        int dayOfWeek = calendar.getFirstDayOfWeek();
-
         if ("AU".equals(locale.getCountry())) {
-            dayOfWeek += 1;
+            return Calendar.MONDAY;
         }
+        Calendar calendar = Calendar.getInstance(locale);
 
-        return dayOfWeek;
+        return calendar.getFirstDayOfWeek();
     }
 
     /**
@@ -947,21 +1028,7 @@ public class DateField extends TextField
      * @return the locale that should be used in this control
      */
     protected Locale getLocale() {
-        Locale locale = null;
-
-        locale = getContext().getLocale();
-        String lang = locale.getLanguage();
-        if (Arrays.binarySearch(SUPPORTED_LANGUAGES, lang) >= 0) {
-            return locale;
-        }
-
-        locale = Locale.getDefault();
-        lang = locale.getLanguage();
-        if (Arrays.binarySearch(SUPPORTED_LANGUAGES, lang) >= 0) {
-            return locale;
-        }
-
-        return Locale.ENGLISH;
+        return getContext().getLocale();
     }
 
     /**

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties Fri
Jun 25 13:10:17 2010
@@ -18,4 +18,4 @@
 calendar-image-title=Calendar
 date-format-error={0} is invalid. Date format is {1}
 date-format-pattern=dd MMM yyyy
-date-title=Date format: {0}
\ No newline at end of file
+date-title=Date format: {0}

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_da.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_da.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_da.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_da.properties Fri
Jun 25 13:10:17 2010
@@ -14,3 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+calendar-weekdays-heading=S\u00f8,Ma,Ti,On,To,Fr,L\u00F8
+calendar-ok=V\u00E6lg
+calendar-now=Nu
+calendar-today=I dag
+calendar-clear=Slet

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_de.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_de.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_de.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_de.properties Fri
Jun 25 13:10:17 2010
@@ -16,4 +16,8 @@
 # under the License.
 
 calendar-image-title=Kalender
-date-format-error={0} ist ung\u00FCltig. Das Datums-Format ist {1}
\ No newline at end of file
+date-format-error={0} ist ung\u00FCltig. Das Datums-Format ist {1}
+calendar-ok=OK
+calendar-now=Jetzt
+calendar-today=Heute
+calendar-clear=L\u00F6schen

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fi.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fi.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fi.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fi.properties Fri
Jun 25 13:10:17 2010
@@ -14,3 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+calendar-weekdays-heading=Su,Ma,Ti,Ke,To,Pe,La
+calendar-ok=OK
+calendar-now=Nyt
+calendar-today=T\u00E4n\u00E4\u00E4n
+calendar-clear=Tyhjenn\u00E4

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fr.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fr.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fr.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_fr.properties Fri
Jun 25 13:10:17 2010
@@ -16,4 +16,9 @@
 # under the License.
 
 calendar-image-title=Calendrier
-date-format-error={0} n''est pas valide. Le format de date est {1}
\ No newline at end of file
+date-format-error={0} n''est pas valide. Le format de date est {1}
+calendar-weekdays-heading=D,L,Ma,Me,J,V,S
+calendar-ok=OK
+calendar-now=Maintenant
+calendar-today=Aujourd'hui
+calendar-clear=D\u00E9gag\u00E9

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ja.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ja.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ja.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ja.properties Fri
Jun 25 13:10:17 2010
@@ -17,4 +17,9 @@
 
 date-format-error={0} \u306f\u4e0d\u6b63\u3067\u3059\u3002\u65e5\u4ed8\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f
{1} \u3067\u3059\u3002
 date-title=\u65e5\u4ed8\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8: {0}
-calendar-image-title=\u30ab\u30ec\u30f3\u30c0\u30fc
\ No newline at end of file
+calendar-image-title=\u30ab\u30ec\u30f3\u30c0\u30fc
+calendar-weekdays-heading='\u65e5','\u6708','\u706b','\u6c34','\u6728','\u91d1','\u571f'
+calendar-ok=OK
+calendar-now=\u4eca\u65e5
+calendar-today=\u4eca\u65e5
+calendar-clear=\u30af\u30ea\u30a2

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_nl.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_nl.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_nl.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_nl.properties Fri
Jun 25 13:10:17 2010
@@ -16,4 +16,9 @@
 # under the License.
 
 calendar-image-title=Calendar
-date-format-error={0} is ongeldig. Datum formaat is {1}
\ No newline at end of file
+date-format-error={0} is ongeldig. Datum formaat is {1}
+calendar-weekdays-heading=Z,M,D,W,D,V,Z
+calendar-ok=OK
+calendar-now=Nu
+calendar-today=Vandaag
+calendar-clear=Wissen

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_pl.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_pl.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_pl.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_pl.properties Fri
Jun 25 13:10:17 2010
@@ -14,3 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+calendar-weekdays-heading=N,P,W,\u015a,C,P,S
+calendar-ok=OK
+calendar-now=Teraz
+calendar-today=Dzi\u015b
+calendar-clear=Jasny

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ru.properties
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ru.properties?rev=957933&r1=957932&r2=957933&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ru.properties (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/DateField_ru.properties Fri
Jun 25 13:10:17 2010
@@ -18,4 +18,9 @@
 date-format-error={0}: \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435
\u0434\u0430\u0442\u044b. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442
\u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u0442\u044b: {1}
 date-title=\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u0442\u044b:
{0}
 calendar-image-title=\u041a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044c
-date-format-pattern=dd.MM.yyyy
\ No newline at end of file
+date-format-pattern=dd.MM.yyyy
+calendar-weekdays-heading=\u0412\u0441,\u041f\u043d,\u0412\u0442,\u0421\u0440,\u0427\u0442,\u041f\u0442,\u0421\u0431
+calendar-ok=OK
+calendar-now=\u0421\u0435\u0439\u0447\u0430\u0441
+calendar-today=\u0421\u0435\u0433\u043e\u0434\u043d\u044f
+calendar-clear=\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c



Mime
View raw message