modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages.java | 57 +++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_de.properties | 2 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_fr.properties | 2 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java | 30 +++- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestPluralizationView.java | 62 ++++++++++ modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml | 6 modules/enterprise/gui/coregui/src/main/webapp/CoreGUI.html | 2 7 files changed, 152 insertions(+), 9 deletions(-)
New commits: commit be24d107b182042a5917f3bde7afff807ee8c30e Author: Joseph Marques joseph@redhat.com Date: Wed Nov 17 13:52:28 2010 -0500
example showing support for i18n via GWT java interface classes
* TestMessages is the interface class that defines translation for the default locale (in this case 'en') * TestMessages_<locale>.propertie define other supported locales * The module's *.gwt.xml file must specify the list of supported locales, which will determine how many different permutations will be compiled * TestPluralizationView shows how pluralization rules work across locales.. For English, visit /coregui/CoreGUI.html#Test/Misc/PluralizationTest or /coregui/CoreGUI.html?locale=en#Test/Misc/PluralizationTest For German, visit /coregui/CoreGUI.html?locale=de#Test/Misc/PluralizationTest For French, visit /coregui/CoreGUI.html?locale=fr#Test/Misc/PluralizationTest
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages.java new file mode 100644 index 0000000..6ffba7c --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages.java @@ -0,0 +1,57 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.i18n; + +import com.google.gwt.i18n.client.Messages; +import com.google.gwt.i18n.client.LocalizableResource.DefaultLocale; + +/* + * @PluralText takes an array of strings. The even indexes represent plural form names, while the odd indexes + * correspond to the text for the associated plural form. Example: + * + * @PluralText( { "one", "There is a single item in your cart.", + * "two", "There are two items in your cart.", + * "few", "There are a few items in your cart.", + * "many", "There are many items in your cart." } ) + * + * As of GWT 2.0.4, the following plural forms exist: + * + * none one two eighteleven + * few paucal many other + * + * However, not all of them are applicable to each locale. When implementing a new localization, refer to the + * appropriate subclass of "com.google.gwt.i18n.client.impl.plurals.DefaultRule" to obtain the necessary plural + * form subset which must be implemented to correctly support that locale. + * + * The rules implemented in these various subclasses are taken from: + * + * http://translate.sourceforge.net/wiki/l10n/pluralforms + */ +@DefaultLocale("en") +public interface TestMessages extends Messages { + + /** + * @param subject the name of the user + * @param cartItems the number of cart items + * @return a message specifying the number of items in the user's cart + */ + @DefaultMessage("{0}, there are {1,number} items in your cart") + @PluralText( { "one", "{0}, there is {1,number} item in your cart" }) + String cartLabel(String subject, @PluralCount int cartItems); +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_de.properties b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_de.properties new file mode 100644 index 0000000..2a8b4b8 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_de.properties @@ -0,0 +1,2 @@ +cartLabel = {0}, there are {1} items in your German cart +cartLabel[one] = {0}, there is {1} item in your German cart \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_fr.properties b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_fr.properties new file mode 100644 index 0000000..1ff16a6 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/i18n/TestMessages_fr.properties @@ -0,0 +1,2 @@ +cartLabel = {0}, there are {1} items in your French cart +cartLabel[one] = {0}, there is {1} item in your French cart \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java index cf617f8..d1e1c85 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestTopView.java @@ -32,6 +32,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.resource.selection.Resour import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeTreeView; import org.rhq.enterprise.gui.coregui.client.test.configuration.TestConfigurationView; import org.rhq.enterprise.gui.coregui.client.test.configuration.TestGroupConfigurationView; +import org.rhq.enterprise.gui.coregui.client.test.i18n.TestPluralizationView;
/** * The Test top-level view. This view is "hidden", i.e. there are no links to it, so the user must go to the URL @@ -55,6 +56,10 @@ public class TestTopView extends AbstractSectionedLeftNavigationView { private static final String PAGE_CONFIG_EDITOR = "ConfigEditor"; private static final String PAGE_GROUP_CONFIG_EDITOR = "GroupConfigEditor";
+ // view IDs for Misc section + private static final String MISC_SECTION_VIEW_ID = "Misc"; + private static final String PAGE_PLURALIZATION_TEST = "PluralizationTest"; + public TestTopView() { // This is a top level view, so our locator id can simply be our view id. super(VIEW_ID); @@ -77,19 +82,20 @@ public class TestTopView extends AbstractSectionedLeftNavigationView { NavigationSection configurationSection = buildConfigurationSection(); sections.add(configurationSection);
+ NavigationSection miscSection = buildMiscSection(); + sections.add(miscSection); + return sections; }
private NavigationSection buildInventorySection() { - NavigationItem resourceSelectorItem = new NavigationItem(PAGE_RESOURCE_SELECTOR, null, - new ViewFactory() { + NavigationItem resourceSelectorItem = new NavigationItem(PAGE_RESOURCE_SELECTOR, null, new ViewFactory() { public Canvas createView() { return new ResourceSelector(extendLocatorId(PAGE_RESOURCE_SELECTOR)); } });
- NavigationItem typeTreeItem = new NavigationItem(PAGE_TYPE_TREE, null, - new ViewFactory() { + NavigationItem typeTreeItem = new NavigationItem(PAGE_TYPE_TREE, null, new ViewFactory() { public Canvas createView() { return new ResourceTypeTreeView(extendLocatorId(PAGE_TYPE_TREE)); } @@ -99,15 +105,13 @@ public class TestTopView extends AbstractSectionedLeftNavigationView { }
private NavigationSection buildConfigurationSection() { - NavigationItem configEditorItem = new NavigationItem(PAGE_CONFIG_EDITOR, null, - new ViewFactory() { + NavigationItem configEditorItem = new NavigationItem(PAGE_CONFIG_EDITOR, null, new ViewFactory() { public Canvas createView() { return new TestConfigurationView(extendLocatorId(PAGE_CONFIG_EDITOR)); } });
- NavigationItem groupConfigEditorItem = new NavigationItem(PAGE_GROUP_CONFIG_EDITOR, null, - new ViewFactory() { + NavigationItem groupConfigEditorItem = new NavigationItem(PAGE_GROUP_CONFIG_EDITOR, null, new ViewFactory() { public Canvas createView() { return new TestGroupConfigurationView(extendLocatorId(PAGE_GROUP_CONFIG_EDITOR)); } @@ -115,4 +119,14 @@ public class TestTopView extends AbstractSectionedLeftNavigationView {
return new NavigationSection(CONFIGURATION_SECTION_VIEW_ID, configEditorItem, groupConfigEditorItem); } + + private NavigationSection buildMiscSection() { + NavigationItem pluralizationItem = new NavigationItem(PAGE_PLURALIZATION_TEST, null, new ViewFactory() { + public Canvas createView() { + return new TestPluralizationView(extendLocatorId(PAGE_PLURALIZATION_TEST)); + } + }); + + return new NavigationSection(MISC_SECTION_VIEW_ID, pluralizationItem); + } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestPluralizationView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestPluralizationView.java new file mode 100644 index 0000000..fa237ef --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestPluralizationView.java @@ -0,0 +1,62 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.test.i18n; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Label; + +import org.rhq.enterprise.gui.coregui.client.i18n.TestMessages; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; + +/** + * A test class to show how GWT-based i18n can support pluralization + * + * @author Joseph Marques + */ +public class TestPluralizationView extends LocatableVLayout { + + public TestPluralizationView(String locatorId) { + super(locatorId); + } + + @Override + protected void onDraw() { + super.onDraw(); + build(); + } + + public void build() { + TestMessages testMessages = GWT.create(TestMessages.class); + + StringBuilder text = new StringBuilder(); + String subject = "rhqadmin"; + for (int cartItems = 0; cartItems < 5; cartItems++) { + if (cartItems != 0) { + text.append("<br/>"); + } + String nextText = "Count " + cartItems + " --> " + testMessages.cartLabel(subject, cartItems); + text.append(nextText); + } + + Label label = new Label(text.toString()); + label.setWrap(false); + addMember(label); + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml index 13f4660..dce2135 100644 --- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml +++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/CoreGUI.gwt.xml @@ -86,11 +86,15 @@ --> <set-property name="user.agent" value="${gwt.userAgent}"/>
+ <!-- Support for locales ('en' need not be specified as long as @DefaultLocale annotates + the Constants, ConstantsWithLookup, and Messages class). Note, these other locales + must have a file suffixed with _<locale>.properties in the same package/directory as + the corresponding GWT i18n interface class resides.--> + <extend-property name="locale" values="de,fr"/>
<entry-point class='org.rhq.enterprise.gui.coregui.client.CoreGUI'/> <entry-point class='org.rhq.enterprise.gui.coregui.client.SearchGUI'/>
- <servlet path="/AlertGWTService" class="org.rhq.enterprise.gui.coregui.server.gwt.AlertGWTServiceImpl"/> <servlet path="/AlertDefinitionGWTService" class="org.rhq.enterprise.gui.coregui.server.gwt.AlertDefinitionGWTServiceImpl"/> <servlet path="/AlertTemplateGWTService" class="org.rhq.enterprise.gui.coregui.server.gwt.AlertTemplateGWTServiceImpl"/>
commit 76d2848c5aa34c4eae987c91225974c6727f1217 Author: Joseph Marques joseph@redhat.com Date: Tue Nov 16 15:47:46 2010 -0500
add support for rendering interationalized characters in coregui
* note: all relevant source and .properties files should be set to UTF-8 in your IDE of choice
diff --git a/modules/enterprise/gui/coregui/src/main/webapp/CoreGUI.html b/modules/enterprise/gui/coregui/src/main/webapp/CoreGUI.html index 5dd3c64..de84de2 100644 --- a/modules/enterprise/gui/coregui/src/main/webapp/CoreGUI.html +++ b/modules/enterprise/gui/coregui/src/main/webapp/CoreGUI.html @@ -8,6 +8,8 @@ var isomorphicDir = "org.rhq.enterprise.gui.coregui.CoreGUI/sc/"; </script>
+ <!-- support internationalized characters --> + <meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="CoreGUI.css">
rhq-commits@lists.fedorahosted.org