Revision: 6502
Author: [email protected]
Date: Wed Oct 28 06:47:22 2009
Log: Moving the Plural Forms example from the I18N sample to Showcase.

Patch by: jlabanca
Review by: jat


http://code.google.com/p/google-web-toolkit/source/detail?r=6502

Added:
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/CwPluralFormsExample.java
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages.java
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages_ar.properties
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages_fr.properties
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages_zh.properties
Modified:
  /trunk/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants.java
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants.properties
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_ar.properties
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_fr.properties
   
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_zh.properties

=======================================
--- /dev/null
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/CwPluralFormsExample.java
         
Wed Oct 28 06:47:22 2009
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.sample.showcase.client.content.i18n;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.RunAsyncCallback;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.KeyUpEvent;
+import com.google.gwt.event.dom.client.KeyUpHandler;
+import com.google.gwt.event.logical.shared.SelectionEvent;
+import com.google.gwt.i18n.client.Constants;
+import com.google.gwt.sample.showcase.client.ContentWidget;
+import com.google.gwt.sample.showcase.client.ShowcaseConstants;
+import  
com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseData;
+import  
com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseRaw;
+import  
com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseSource;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HasVerticalAlignment;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
+
+/**
+ * Example file.
+ */
+...@showcaseraw({"PluralMessages.java", "PluralMessages_fr.properties"})
+public class CwPluralFormsExample extends ContentWidget {
+  /**
+   * The constants used in this Content Widget.
+   */
+  @ShowcaseSource
+  public static interface CwConstants extends Constants,
+      ContentWidget.CwConstants {
+    String cwPluralFormsExampleArg0Label();
+
+    String cwPluralFormsExampleDescription();
+
+    String cwPluralFormsExampleFormattedLabel();
+
+    String cwPluralFormsExampleLinkText();
+
+    String cwPluralFormsExampleName();
+  }
+
+  /**
+   * The {...@link TextBox} where the user enters argument 0.
+   */
+  @ShowcaseData
+  private TextBox arg0Box = null;
+
+  /**
+   * An instance of the constants.
+   */
+  @ShowcaseData
+  private CwConstants constants;
+
+  /**
+   * The plural messages used in this example.
+   */
+  @ShowcaseData
+  private PluralMessages pluralMessages = null;
+
+  /**
+   * The {...@link Label} used to display the message.
+   */
+  @ShowcaseData
+  private Label formattedMessage = null;
+
+  /**
+   * Indicates whether or not we have loaded the {...@link PluralMessages}  
java
+   * source yet.
+   */
+  private boolean javaLoaded = false;
+
+  /**
+   * The widget used to display {...@link PluralMessages} java source.
+   */
+  private HTML javaWidget = null;
+
+  /**
+   * Indicates whether or not we have loaded the {...@link ErrorMessages}
+   * properties source yet.
+   */
+  private boolean propertiesLoaded = false;
+
+  /**
+   * The widget used to display {...@link ErrorMessages} properties source.
+   */
+  private HTML propertiesWidget = null;
+
+  /**
+   * Constructor.
+   *
+   * @param constants the constants
+   */
+  public CwPluralFormsExample(CwConstants constants) {
+    super(constants);
+    this.constants = constants;
+  }
+
+  @Override
+  public String getDescription() {
+    return constants.cwPluralFormsExampleDescription();
+  }
+
+  @Override
+  public String getName() {
+    return constants.cwPluralFormsExampleName();
+  }
+
+  @Override
+  public boolean hasStyle() {
+    return false;
+  }
+
+  /**
+   * Initialize this example.
+   */
+  @ShowcaseSource
+  @Override
+  public Widget onInitialize() {
+    // Create the internationalized error messages
+    pluralMessages = GWT.create(PluralMessages.class);
+
+    // Use a FlexTable to layout the content
+    FlexTable layout = new FlexTable();
+    FlexCellFormatter formatter = layout.getFlexCellFormatter();
+    layout.setCellSpacing(5);
+
+    // Add a link to the source code of the Interface
+    HTML link = new HTML(" <a  
href=\"javascript:void(0);\">PluralMessages</a>");
+    link.addClickHandler(new ClickHandler() {
+      public void onClick(ClickEvent event) {
+        selectTab(2);
+      }
+    });
+    HorizontalPanel linkPanel = new HorizontalPanel();
+    linkPanel.setSpacing(3);
+    linkPanel.add(new HTML(constants.cwPluralFormsExampleLinkText()));
+    linkPanel.add(link);
+    layout.setWidget(0, 0, linkPanel);
+    formatter.setColSpan(0, 0, 2);
+
+    // Add argument 0
+    arg0Box = new TextBox();
+    arg0Box.setText("13");
+    layout.setHTML(2, 0, constants.cwPluralFormsExampleArg0Label());
+    layout.setWidget(2, 1, arg0Box);
+
+    // Add the formatted message
+    formattedMessage = new Label();
+    layout.setHTML(5, 0, constants.cwPluralFormsExampleFormattedLabel());
+    layout.setWidget(5, 1, formattedMessage);
+    formatter.setVerticalAlignment(5, 0, HasVerticalAlignment.ALIGN_TOP);
+
+    // Add handlers to all of the argument boxes
+    KeyUpHandler keyUpHandler = new KeyUpHandler() {
+      public void onKeyUp(KeyUpEvent event) {
+        updateMessage();
+      }
+    };
+    arg0Box.addKeyUpHandler(keyUpHandler);
+
+    // Return the layout Widget
+    updateMessage();
+    return layout;
+  }
+
+  @Override
+  public void onInitializeComplete() {
+    addMessagesTab();
+  }
+
+  @Override
+  public void onSelection(SelectionEvent<Integer> event) {
+    super.onSelection(event);
+
+    int tabIndex = event.getSelectedItem().intValue();
+    if (!javaLoaded && tabIndex == 2) {
+      // Load PluralMessages.java
+      javaLoaded = true;
+      String className = PluralMessages.class.getName();
+      className = className.substring(className.lastIndexOf(".") + 1);
+      requestSourceContents(ShowcaseConstants.DST_SOURCE_RAW + className
+          + ".java.html", javaWidget, null);
+    } else if (!propertiesLoaded && tabIndex == 3) {
+      // Load ErrorMessages.properties
+      propertiesLoaded = true;
+      String className = PluralMessages.class.getName();
+      className = className.substring(className.lastIndexOf(".") + 1);
+      requestSourceContents(ShowcaseConstants.DST_SOURCE_RAW + className
+          + "_fr.properties.html", propertiesWidget, null);
+    }
+  }
+
+  @Override
+  protected void asyncOnInitialize(final AsyncCallback<Widget> callback) {
+    GWT.runAsync(new RunAsyncCallback() {
+
+      public void onFailure(Throwable caught) {
+        callback.onFailure(caught);
+      }
+
+      public void onSuccess() {
+        callback.onSuccess(onInitialize());
+      }
+    });
+  }
+
+  /**
+   * Add a tab to this example to show the {...@link PluralMessages} source  
code.
+   */
+  private void addMessagesTab() {
+    // Add a tab to show the interface
+    javaWidget = new HTML();
+    add(javaWidget, "PluralMessages.java");
+
+    // Add a tab to show the properties
+    propertiesWidget = new HTML();
+    add(propertiesWidget, "PluralMessages_fr.properties");
+  }
+
+  /**
+   * Update the formatted message.
+   */
+  @ShowcaseSource
+  private void updateMessage() {
+    try {
+      int count = Integer.parseInt(arg0Box.getText().trim());
+      formattedMessage.setText(pluralMessages.treeCount(count));
+    } catch (NumberFormatException e) {
+      // Ignore.
+    }
+  }
+
+}
=======================================
--- /dev/null
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages.java
       
Wed Oct 28 06:47:22 2009
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.sample.showcase.client.content.i18n;
+
+import com.google.gwt.i18n.client.Messages;
+import com.google.gwt.i18n.client.LocalizableResource.DefaultLocale;
+
+/**
+ * Internationalized messages used by {...@link CwPluralFormsExample}. Used to
+ * demonstrate plural forms support.
+ */
+...@defaultlocale("en")
+public interface PluralMessages extends Messages {
+  @DefaultMessage("You have {0} trees.")
+  @PluralText({"one", "You have one tree."})
+  String treeCount(@PluralCount int count);
+}
=======================================
--- /dev/null
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages_ar.properties
      
Wed Oct 28 06:47:22 2009
@@ -0,0 +1,34 @@
+#
+# Copyright 2009 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+# use this file except in compliance with the License. You may obtain a  
copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations  
under
+# the License.
+#
+
+# The default message to use for the message.
+treeCount=.لديك {0} شجر
+
+# The message to use for the plural form "zero".
+treeCount[none]=ليس لديك أي أشجا.
+
+# The message to use for the plural form "one".
+treeCount[one]=لديك شجرة واحدة.
+
+# The message to use for the plural form "two".
+treeCount[two]=لديك شجرتا.
+
+# The message to use for the plural form "few" (last two digits are 03-10).
+treeCount[few]=لديك {0} أشجا.
+
+# The message to use for the plural form "many" (last two digits are  
11-99).
+treeCount[many]=لديك {0} شجر.
+
=======================================
--- /dev/null
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages_fr.properties
      
Wed Oct 28 06:47:22 2009
@@ -0,0 +1,21 @@
+#
+# Copyright 2009 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+# use this file except in compliance with the License. You may obtain a  
copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations  
under
+# the License.
+#
+
+# The default message to use for the message.
+treeCount=Vous avez {0} arbres.
+
+# The message to use for the plural form "one", which in French is applied  
to counts of 0 or 1.
+treeCount[one]=Vous avez {0} arbre.
=======================================
--- /dev/null
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/i18n/PluralMessages_zh.properties
      
Wed Oct 28 06:47:22 2009
@@ -0,0 +1,20 @@
+#
+# Copyright 2009 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+# use this file except in compliance with the License. You may obtain a  
copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations  
under
+# the License.
+#
+
+# The default message to use for the message.
+treeCount=你有{0}棵树。
+
+
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml     
 
Mon Mar  2 23:51:53 2009
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml     
 
Wed Oct 28 06:47:22 2009
@@ -25,4 +25,5 @@
    <extend-property name="locale" values="ar"/>
    <extend-property name="locale" values="fr"/>
    <extend-property name="locale" values="zh"/>
+  <set-property-fallback name="locale" value="en"/>
  </module>
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java 
 
Mon Oct 12 14:48:21 2009
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java 
 
Wed Oct 28 06:47:22 2009
@@ -37,6 +37,7 @@
  import  
com.google.gwt.sample.showcase.client.content.i18n.CwDictionaryExample;
  import  
com.google.gwt.sample.showcase.client.content.i18n.CwMessagesExample;
  import com.google.gwt.sample.showcase.client.content.i18n.CwNumberFormat;
+import  
com.google.gwt.sample.showcase.client.content.i18n.CwPluralFormsExample;
  import com.google.gwt.sample.showcase.client.content.lists.CwListBox;
  import com.google.gwt.sample.showcase.client.content.lists.CwMenuBar;
  import com.google.gwt.sample.showcase.client.content.lists.CwStackPanel;
@@ -366,6 +367,8 @@
          images.catI18N());
      setupMainMenuOption(catI18N, new CwMessagesExample(constants),
          images.catI18N());
+    setupMainMenuOption(catI18N, new CwPluralFormsExample(constants),
+        images.catI18N());
      setupMainMenuOption(catI18N, new CwConstantsExample(constants),
          images.catI18N());
      setupMainMenuOption(catI18N, new  
CwConstantsWithLookupExample(constants),
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants.java
         
Tue Dec 23 16:45:21 2008
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants.java
         
Wed Oct 28 06:47:22 2009
@@ -22,6 +22,7 @@
  import  
com.google.gwt.sample.showcase.client.content.i18n.CwDictionaryExample;
  import  
com.google.gwt.sample.showcase.client.content.i18n.CwMessagesExample;
  import com.google.gwt.sample.showcase.client.content.i18n.CwNumberFormat;
+import  
com.google.gwt.sample.showcase.client.content.i18n.CwPluralFormsExample;
  import com.google.gwt.sample.showcase.client.content.lists.CwListBox;
  import com.google.gwt.sample.showcase.client.content.lists.CwMenuBar;
  import com.google.gwt.sample.showcase.client.content.lists.CwStackPanel;
@@ -74,7 +75,8 @@
      CwDateTimeFormat.CwConstants, CwMessagesExample.CwConstants,
      CwConstantsExample.CwConstants,  
CwConstantsWithLookupExample.CwConstants,
      CwDictionaryExample.CwConstants, CwDecoratorPanel.CwConstants,
-    CwAnimation.CwConstants, CwDatePicker.CwConstants {
+    CwAnimation.CwConstants, CwDatePicker.CwConstants,
+    CwPluralFormsExample.CwConstants {

    /**
     * The path to source code for examples, raw files, and style  
definitions.
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants.properties
   
Tue Dec 23 16:45:21 2008
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants.properties
   
Wed Oct 28 06:47:22 2009
@@ -183,6 +183,11 @@
  cwNumberFormatPatternLabel = <b>Pattern:</b>
  cwNumberFormatPatterns = Decimal, Currency, Scientific, Percent, Custom
  cwNumberFormatValueLabel = <b>Value to format:</b>
+cwPluralFormsExampleName = Plural Forms
+cwPluralFormsExampleDescription = Plural Forms provide a way to create  
message translations that depend on the count of something.
+cwPluralFormsExampleArg0Label = <b>Argument {0}:</b>
+cwPluralFormsExampleFormattedLabel = <b>Formatted message:</b>
+cwPluralFormsExampleLinkText = This example interacts with the sample  
interface:
  cwRadioButtonName = Radio Button
  cwRadioButtonDescription = Basic RadioButton Widget
  cwRadioButtonColors = blue, red, yellow, green
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_ar.properties
        
Tue Dec 23 16:45:21 2008
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_ar.properties
        
Wed Oct 28 06:47:22 2009
@@ -172,6 +172,9 @@
  cwNumberFormatPatternLabel = <b>نمط:</b>
  cwNumberFormatPatterns = عشري, عملة, علمي, نسبة مؤوية, تخصيص
  cwNumberFormatValueLabel = <b>قيمة للتنسيق:</b>
+cwPluralFormsExampleArg0Label = <b>متغير {0}:</b>
+cwPluralFormsExampleFormattedLabel = <b>رسالة منسقة:</b>
+cwPluralFormsExampleLinkText = هذا المثال يتفاعل مع عينة الواجهة:
  cwRadioButtonName = زر انتقاء
  cwRadioButtonDescription = ودجة زر انتقاء اساسي
  cwRadioButtonColors = ازرق ,احمر ,اصفر ,اخضر
@@ -238,3 +241,5 @@
  cwDatePickerDescription = اسمحوا المستخدمين اختيار تاريخ باستخدام  
DatePicker.
  cwDatePickerBoxLabel = <br><br><br><b>DateBox مع قافزة DatePicker : </b>
  cwDatePickerLabel = <b>الدائم DatePicker : </b>
+cwPluralFormsExampleName = تعدد أشكال
+cwPluralFormsExampleDescription = تعدد أشكال توفير وسيلة لخلق ترجمة  
الرسالة التي تعتمد على عدد من شيء.
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_fr.properties
        
Tue Dec 23 16:45:21 2008
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_fr.properties
        
Wed Oct 28 06:47:22 2009
@@ -179,6 +179,9 @@
  cwNumberFormatPatternLabel = <b>Patron:</b>
  cwNumberFormatPatterns = Décimales, devise, scientifique, pourcentage,  
personnalisé
  cwNumberFormatValueLabel = <b>Valeur au format:</b>
+cwPluralFormsExampleArg0Label = <b>Paramètre {0}:</b>
+cwPluralFormsExampleFormattedLabel = <b>Valeur formattée:</b>
+cwPluralFormsExampleLinkText = Cet exemple interagit avec l'échantillon  
de l'interface:
  cwRadioButtonName = Bouton radio
  cwRadioButtonDescription = Widget de bouton radio basique
  cwRadioButtonColors = bleu, rouge, jaune, vert
@@ -236,3 +239,5 @@
  cwDatePickerDescription = Permettre aux utilisateurs de sélectionner une  
date à l'aide de la DatePicker.
  cwDatePickerBoxLabel = <br><br><b>DateBox avec popup DatePicker:</b>
  cwDatePickerLabel = <b>DatePicker permanent:</b>
+cwPluralFormsExampleName = Formes plurielles
+cwPluralFormsExampleDescription = Les formes plurielles de fournir un  
moyen de créer les traductions des messages qui dépendent du chef  
d'accusation de quelque chose.
=======================================
---  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_zh.properties
        
Tue Dec 23 16:45:21 2008
+++  
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseConstants_zh.properties
        
Wed Oct 28 06:47:22 2009
@@ -172,6 +172,9 @@
  cwNumberFormatPatternLabel = <b>模板:</b>
  cwNumberFormatPatterns = 小数, 货币, 科学, 百分数, 自定义
  cwNumberFormatValueLabel = <b>需要格式的值:</b>
+cwPluralFormsExampleArg0Label = <b>论点(0): </b>
+cwPluralFormsExampleFormattedLabel = <b>格式化信息: </b>
+cwPluralFormsExampleLinkText = 这个例子使用了示例接口:
  cwRadioButtonName = 单选按钮
  cwRadioButtonDescription = 单选按钮部件
  cwRadioButtonColors = 蓝, 红, 黄, 绿
@@ -236,3 +239,6 @@
  cwDatePickerDescription =让用户选择日期使用DatePicker 。
  cwDatePickerBoxLabel = <br><br><br><b>DateBox与弹出DatePicker:</b>
  cwDatePickerLabel =<b>常驻DatePicker:</b>
+cwPluralFormsExampleName = 复数形式
+cwPluralFormsExampleDescription = 复数形式提供了一种方法来创建消息翻译依赖 
于数的东西。
+

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to