Revision: 8767
Author: [email protected]
Date: Mon Sep 13 14:21:48 2010
Log: Improve locale handling for default scripts and languages where some
scripts are written RTL even if the language isn't RTL in general.

Patch by: jat
Review by: pdr

Review at http://gwt-code-reviews.appspot.com/851802

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

Added:
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_dv.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ha_Arab.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ku.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ku_Latn.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_pa_Arab.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_syr.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ug.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_uz_Arab.java
 /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_yi.java
 /trunk/user/test/com/google/gwt/i18n/I18NTest_pa_Arab.gwt.xml
 /trunk/user/test/com/google/gwt/i18n/I18NTest_pa_PK.gwt.xml
 /trunk/user/test/com/google/gwt/i18n/client/I18N_pa_Arab_Test.java
 /trunk/user/test/com/google/gwt/i18n/client/I18N_pa_PK_Test.java
Modified:
 /trunk/user/src/com/google/gwt/i18n/server/DefaultLanguageScripts.java
 /trunk/user/src/com/google/gwt/i18n/server/GwtLocaleImpl.java
 /trunk/user/test/com/google/gwt/i18n/I18NSuite.java
 /trunk/user/test/com/google/gwt/i18n/server/GwtLocaleTest.java

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_dv.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_dv extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ha_Arab.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_ha_Arab extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ku.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_ku extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ku_Latn.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_ku_Latn extends CldrImpl_ku {
+
+  @Override
+  public boolean isRTL() {
+    return false;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_pa_Arab.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_pa_Arab extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_syr.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_syr extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_ug.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_ug extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_uz_Arab.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_uz_Arab extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/i18n/client/impl/cldr/CldrImpl_yi.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010 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.i18n.client.impl.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ *
+ * Eventually all CldrImpl implementations will be machine-generated from
+ * Unicode's CLDR data.
+ */
+public class CldrImpl_yi extends CldrImpl {
+
+  @Override
+  public boolean isRTL() {
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/i18n/I18NTest_pa_Arab.gwt.xml Mon Sep 13 14:21:48 2010
@@ -0,0 +1,23 @@
+<!-- --> +<!-- Copyright 2010 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 --> +<!-- 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. License for the specific language governing permissions and --> +<!-- limitations under the License. -->
+
+<module>
+       <!-- Inherit the JUnit support -->
+       <inherits name='com.google.gwt.junit.JUnit'/>
+       <inherits name = 'com.google.gwt.i18n.I18N'/>
+       <!-- Include client-side source for the test cases -->
+       <source path="client"/>
+       <extend-property name="locale" values="pa_Arab"/>
+       <set-property name="locale" value="pa_Arab"/>
+</module>
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/i18n/I18NTest_pa_PK.gwt.xml Mon Sep 13 14:21:48 2010
@@ -0,0 +1,23 @@
+<!-- --> +<!-- Copyright 2010 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 --> +<!-- 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. License for the specific language governing permissions and --> +<!-- limitations under the License. -->
+
+<module>
+       <!-- Inherit the JUnit support -->
+       <inherits name='com.google.gwt.junit.JUnit'/>
+       <inherits name = 'com.google.gwt.i18n.I18N'/>
+       <!-- Include client-side source for the test cases -->
+       <source path="client"/>
+       <extend-property name="locale" values="pa_PK"/>
+       <set-property name="locale" value="pa_PK"/>
+</module>
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/i18n/client/I18N_pa_Arab_Test.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010 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.i18n.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.impl.CldrImpl;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests Punjabi written in Arabic script.
+ */
+public class I18N_pa_Arab_Test extends GWTTestCase {
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.i18n.I18NTest_pa_Arab";
+  }
+
+  public void testCldrImpl() {
+    CldrImpl cldr = GWT.create(CldrImpl.class);
+    assertTrue(cldr.isRTL());
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/i18n/client/I18N_pa_PK_Test.java Mon Sep 13 14:21:48 2010
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010 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.i18n.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.impl.CldrImpl;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests Punjabi as written in Pakistan (which uses an Arabic script).
+ */
+public class I18N_pa_PK_Test extends GWTTestCase {
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.i18n.I18NTest_pa_PK";
+  }
+
+  public void testCldrImpl() {
+    CldrImpl cldr = GWT.create(CldrImpl.class);
+    assertTrue(cldr.isRTL());
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/i18n/server/DefaultLanguageScripts.java Wed Oct 28 09:10:53 2009 +++ /trunk/user/src/com/google/gwt/i18n/server/DefaultLanguageScripts.java Mon Sep 13 14:21:48 2010
@@ -29,13 +29,16 @@
   private static Map<String, String> defaultScripts;

   static {
-    // From http://www.iana.org/assignments/language-subtag-registry
+ // From http://www.iana.org/assignments/language-subtag-registry, and CLDR
+    // alias data.
     defaultScripts = new HashMap<String, String>();
     defaultScripts.put("ab", "Cyrl");
     defaultScripts.put("af", "Latn");
     defaultScripts.put("am", "Ethi");
     defaultScripts.put("ar", "Arab");
     defaultScripts.put("as", "Beng");
+    defaultScripts.put("az_AZ", "Latn");
+    defaultScripts.put("az_IR", "Arab");
     defaultScripts.put("ay", "Latn");
     defaultScripts.put("be", "Cyrl");
     defaultScripts.put("bg", "Cyrl");
@@ -67,6 +70,10 @@
     defaultScripts.put("gn", "Latn");
     defaultScripts.put("gu", "Latn");
     defaultScripts.put("gv", "Latn");
+    defaultScripts.put("ha_GH", "Latn");
+    defaultScripts.put("ha_NE", "Latn");
+    defaultScripts.put("ha_NG", "Latn");
+    defaultScripts.put("ha_SD", "Arab");
     defaultScripts.put("he", "Hebr");
     defaultScripts.put("hi", "Deva");
     defaultScripts.put("hr", "Latn");
@@ -81,10 +88,15 @@
     defaultScripts.put("ja", "Jpan");
     defaultScripts.put("ka", "Geor");
     defaultScripts.put("kk", "Cyrl");
+    defaultScripts.put("kk_KZ", "Cyrl"); // ?
     defaultScripts.put("kl", "Latn");
     defaultScripts.put("km", "Khmr");
     defaultScripts.put("kn", "Knda");
     defaultScripts.put("ko", "Kore");
+    defaultScripts.put("ku_IQ", "Arab");
+    defaultScripts.put("ku_IR", "Arab");
+    defaultScripts.put("ku_SY", "Latn");
+    defaultScripts.put("ku_TR", "Latn");
     defaultScripts.put("la", "Latn");
     defaultScripts.put("lb", "Latn");
     defaultScripts.put("ln", "Latn");
@@ -95,6 +107,8 @@
     defaultScripts.put("mh", "Latn");
     defaultScripts.put("mk", "Cyrl");
     defaultScripts.put("ml", "Mlym");
+    defaultScripts.put("mn_CN", "Mong");
+    defaultScripts.put("mn_MN", "Cyrl");
     defaultScripts.put("mo", "Latn");
     defaultScripts.put("mr", "Deva");
     defaultScripts.put("ms", "Latn");
@@ -112,6 +126,7 @@
     defaultScripts.put("om", "Latn");
     defaultScripts.put("or", "Latn");
     defaultScripts.put("pa", "Guru");
+    defaultScripts.put("pa_PK", "Arab");
     defaultScripts.put("pl", "Latn");
     defaultScripts.put("ps", "Arab");
     defaultScripts.put("pt", "Latn");
@@ -127,12 +142,18 @@
     defaultScripts.put("sm", "Latn");
     defaultScripts.put("so", "Latn");
     defaultScripts.put("sq", "Latn");
+    defaultScripts.put("sr_BA", "Cyrl");
+    defaultScripts.put("sr_CS", "Cyrl");
+    defaultScripts.put("sr_ME", "Latn");
+    defaultScripts.put("sr_RS", "Cyrl");
+    defaultScripts.put("sr_YU", "Cyrl");
     defaultScripts.put("ss", "Latn");
     defaultScripts.put("st", "Latn");
     defaultScripts.put("sv", "Latn");
     defaultScripts.put("sw", "Latn");
     defaultScripts.put("ta", "Taml");
     defaultScripts.put("te", "Telu");
+    defaultScripts.put("tg_TJ", "Cyrl");
     defaultScripts.put("th", "Thai");
     defaultScripts.put("ti", "Ethi");
     defaultScripts.put("tl", "Latn");
@@ -140,13 +161,22 @@
     defaultScripts.put("to", "Latn");
     defaultScripts.put("tr", "Latn");
     defaultScripts.put("ts", "Latn");
+    defaultScripts.put("ug_CN", "Arab");
     defaultScripts.put("uk", "Cyrl");
     defaultScripts.put("ur", "Arab");
+    defaultScripts.put("uz_AF", "Arab");
+    defaultScripts.put("uz_UZ", "Cyrl");
     defaultScripts.put("ve", "Latn");
     defaultScripts.put("vi", "Latn");
     defaultScripts.put("wo", "Latn");
+    defaultScripts.put("wo_SN", "Latn"); // ?
     defaultScripts.put("xh", "Latn");
     defaultScripts.put("yi", "Hebr");
+    defaultScripts.put("zh_CN", "Hans");
+    defaultScripts.put("zh_HK", "Hant");
+    defaultScripts.put("zh_MO", "Hant");
+    defaultScripts.put("zh_SG", "Hans");
+    defaultScripts.put("zh_TW", "Hant");
     defaultScripts.put("zu", "Latn");
     defaultScripts.put("dsb", "Latn");
     defaultScripts.put("frs", "Latn");
@@ -159,21 +189,43 @@
     defaultScripts.put("niu", "Latn");
     defaultScripts.put("nqo", "Nkoo");
     defaultScripts.put("nso", "Latn");
+    defaultScripts.put("shi_MA", "Latn");
     defaultScripts.put("tem", "Latn");
     defaultScripts.put("tkl", "Latn");
     defaultScripts.put("tmh", "Latn");
     defaultScripts.put("tpi", "Latn");
     defaultScripts.put("tvl", "Latn");
+    defaultScripts.put("tzm_MA", "Latn");
     defaultScripts.put("zbl", "Blis");
   }

   /**
    * Returns the default script for a language, or null if none.
    *
-   * @param language language code to get default script for
+   * @param language language code to get default script for (in lowercase)
    * @return default script for language, or null if none
    */
   public static String getDefaultScript(String language) {
     return defaultScripts.get(language);
   }
-}
+
+  /**
+ * Returns the default script for a language/region combination, or null if
+   * none.
+   *
+   * @param language language code to get default script for (in lowercase)
+ * @param region region code to get default script for (in uppercase); may be
+   *     null
+   * @return default script for language/region, or null if none
+   */
+  public static String getDefaultScript(String language, String region) {
+    String script = null;
+    if (region != null) {
+      script = defaultScripts.get(language + "_" + region);
+    }
+    if (script == null) {
+      script = defaultScripts.get(language);
+    }
+    return script;
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/i18n/server/GwtLocaleImpl.java Mon Nov 16 13:28:11 2009 +++ /trunk/user/src/com/google/gwt/i18n/server/GwtLocaleImpl.java Mon Sep 13 14:21:48 2010
@@ -146,36 +146,28 @@

   /**
    * Add special aliases for a given locale.
-   *
- * This includes things like choosing the default script/region for Chinese - * based on the other one, handling Norwegian language changes, and treating
-   * pt_BR as the default pt type.
-   *
+   *
+ * This includes things like choosing the default region for Chinese based on + * the script, handling Norwegian language changes, and treating pt_BR as the
+   * default pt type.
+   *
    * @param factory GwtLocaleFactory to create new instances with
    * @param locale locale to add deprecated pair for
    * @param aliases where to store the alias if present
    */
   private static void addSpecialAliases(GwtLocaleFactory factory,
-      GwtLocale locale, List<GwtLocale> aliases) {
+      GwtLocale locale, String initialScript, List<GwtLocale> aliases) {
     String language = locale.getLanguage();
     String script = locale.getScript();
     String region = locale.getRegion();
     String variant = locale.getVariant();
-    if ("zh".equals(language)) {
-      if (script == null) {
-        // infer script from region
-        if ("TW".equals(region)) {
- aliases.add(factory.fromComponents("zh", "Hant", region, variant));
-        } else if ("CN".equals(region)) {
- aliases.add(factory.fromComponents("zh", "Hans", region, variant));
-        }
-      } else {
-        if (region == null) {
-          // Add aliases for main users of particular scripts
-          aliases.add(factory.fromComponents("zh", script,
-              "Hant".equals(script) ? "TW" : "CN", variant));
-        }
-      }
+    if ("zh".equals(language) && region == null
+        && (initialScript == null || initialScript.equals(script))) {
+      // Add aliases for main users of particular scripts, but only if the
+ // script matches what was initially supplied. This is to avoid cases
+      // like zh_TW => zh => zh_CN, while still allowing zh => zh_CN.
+      aliases.add(factory.fromComponents("zh", script,
+          "Hant".equals(script) ? "TW" : "CN", variant));
     } else if ("no".equals(language)) {
       if (variant == null || "BOKMAL".equals(variant)) {
         aliases.add(factory.fromComponents("nb", script, region, null));
@@ -293,7 +285,8 @@
         ArrayList<GwtLocale> nextGroup = new ArrayList<GwtLocale>();
         nextGroup.add(this);
         // Account for default script
- String defaultScript = DefaultLanguageScripts.getDefaultScript(language); + String defaultScript = DefaultLanguageScripts.getDefaultScript(language,
+            region);
         if (defaultScript != null) {
           if (script == null) {
             nextGroup.add(factory.fromComponents(language, defaultScript,
@@ -303,6 +296,7 @@
                 variant));
           }
         }
+        String initialScript = script == null ? defaultScript : script;
         while (!nextGroup.isEmpty()) {
           List<GwtLocale> thisGroup = nextGroup;
           nextGroup = new ArrayList<GwtLocale>();
@@ -315,7 +309,7 @@
               cachedAliases.add(locale);
             }
             addDeprecatedPairs(factory, locale, nextGroup);
-            addSpecialAliases(factory, locale, nextGroup);
+            addSpecialAliases(factory, locale, initialScript, nextGroup);
           }
         }
         cachedAliases = Collections.unmodifiableList(cachedAliases);
@@ -407,7 +401,7 @@
     }
     // Remove any default script for the language
     if (canonScript != null && canonScript.equals(
-        DefaultLanguageScripts.getDefaultScript(canonLanguage))) {
+ DefaultLanguageScripts.getDefaultScript(canonLanguage, canonRegion))) {
       canonScript = null;
     }
     return factory.fromComponents(canonLanguage, canonScript, canonRegion,
@@ -415,11 +409,20 @@
   }

   public List<GwtLocale> getCompleteSearchList() {
-    // TODO(jat): get zh_Hant to come before zh in search list for zh_TW
+ // TODO(jat): base order on distance from the initial locale, such as the
+    // draft proposal at:
+ // http://cldr.unicode.org/development/design-proposals/languagedistance + // This will ensure that zh_Hant will come before zh in the search list for
+    // zh_TW, and pa_Arab to come before pa in the search list for pa_PK.
     synchronized (cacheLock) {
       if (cachedSearchList == null) {
         cachedSearchList = new ArrayList<GwtLocale>();
         Set<GwtLocale> seen = new HashSet<GwtLocale>();
+        String initialScript = script;
+        if (initialScript == null) {
+          initialScript = DefaultLanguageScripts.getDefaultScript(language,
+              region);
+        }
List<GwtLocale> thisGroup = new ArrayList<GwtLocale>(this.getAliases());
         seen.addAll(thisGroup);
         GwtLocale defLocale = factory.getDefault();
@@ -428,7 +431,9 @@
           cachedSearchList.addAll(thisGroup);
           List<GwtLocale> nextGroup = new ArrayList<GwtLocale>();
           for (GwtLocale locale : thisGroup) {
- List<GwtLocale> work = new ArrayList<GwtLocale>(locale.getAliases());
+            List<GwtLocale> aliases = locale.getAliases();
+            aliases = filterBadScripts(aliases, initialScript);
+            List<GwtLocale> work = new ArrayList<GwtLocale>(aliases);
             work.removeAll(seen);
             nextGroup.addAll(work);
             seen.addAll(work);
@@ -576,4 +581,27 @@
     }
     return false;
   }
-}
+
+  /**
+ * Remove aliases which are incompatible with the initial script provided or
+   * defaulted in a locale.
+   *
+   * @param aliases
+   * @param initialScript
+   * @return copy of aliases with incompatible scripts removed
+   */
+  private List<GwtLocale> filterBadScripts(List<GwtLocale> aliases,
+      String initialScript) {
+    if (initialScript == null) {
+      return aliases;
+    }
+    List<GwtLocale> result = new ArrayList<GwtLocale>();
+    for (GwtLocale alias : aliases) {
+      String aliasScript = alias.getScript();
+      if (aliasScript == null || aliasScript.equals(initialScript)) {
+        result.add(alias);
+      }
+    }
+    return result;
+  }
+}
=======================================
--- /trunk/user/test/com/google/gwt/i18n/I18NSuite.java Sun Apr 25 03:44:04 2010 +++ /trunk/user/test/com/google/gwt/i18n/I18NSuite.java Mon Sep 13 14:21:48 2010
@@ -31,6 +31,8 @@
 import com.google.gwt.i18n.client.I18N_es_MX_Test;
 import com.google.gwt.i18n.client.I18N_iw_Test;
 import com.google.gwt.i18n.client.I18N_nb_Test;
+import com.google.gwt.i18n.client.I18N_pa_Arab_Test;
+import com.google.gwt.i18n.client.I18N_pa_PK_Test;
 import com.google.gwt.i18n.client.LocaleInfoTest;
 import com.google.gwt.i18n.client.LocaleInfo_ar_Test;
 import com.google.gwt.i18n.client.NumberFormat_ar_Test;
@@ -81,6 +83,8 @@
     suite.addTestSuite(GwtLocaleTest.class);
     suite.addTestSuite(I18NTest.class);
     suite.addTestSuite(I18N2Test.class);
+    suite.addTestSuite(I18N_pa_Arab_Test.class);
+    suite.addTestSuite(I18N_pa_PK_Test.class);
     suite.addTestSuite(I18N_iw_Test.class);
     suite.addTestSuite(I18N_es_MX_Test.class);
     suite.addTestSuite(I18N_es_MX_RuntimeTest.class);
=======================================
--- /trunk/user/test/com/google/gwt/i18n/server/GwtLocaleTest.java Mon Apr 20 16:10:15 2009 +++ /trunk/user/test/com/google/gwt/i18n/server/GwtLocaleTest.java Mon Sep 13 14:21:48 2010
@@ -31,22 +31,8 @@
   private GwtLocaleFactory factory = new GwtLocaleFactoryImpl();

   public void testAliases() {
-    GwtLocale zhCN = factory.fromString("zh_CN");
-    List<GwtLocale> aliases = zhCN.getAliases();
-    assertEquals(2, aliases.size());
-    assertEquals(aliases.get(0), zhCN);
- assertContainsAndGetPosition(aliases, factory.fromString("zh_Hans_CN"));
-    GwtLocale zhHant = factory.fromString("zh_Hant");
-    aliases = zhHant.getAliases();
-    assertEquals(aliases.get(0), factory.fromString("zh_TW"));
- assertContainsAndGetPosition(aliases, factory.fromString("zh_Hant_TW"));
-    GwtLocale zhHans = factory.fromString("zh_Hans");
-    aliases = zhHans.getAliases();
-    assertEquals(aliases.get(0), zhCN);
- assertContainsAndGetPosition(aliases, factory.fromString("zh_Hans_CN"));
-    assertContainsAndGetPosition(aliases, zhHans);
     GwtLocale en = factory.fromString("en");
-    aliases = en.getAliases();
+    List<GwtLocale> aliases = en.getAliases();
     assertEquals(aliases.get(0), en);
     GwtLocale enLatn = factory.fromString("en_Latn");
     assertContainsAndGetPosition(aliases, enLatn);
@@ -77,6 +63,22 @@
     aliases = ji.getAliases();
     assertContainsAndGetPosition(aliases, factory.fromString("yi"));
   }
+
+  public void testCanonicalForm() {
+    GwtLocale zhCN = factory.fromString("zh_CN");
+    GwtLocale zhHansCN = factory.fromString("zh_Hans_CN");
+    GwtLocale zhHant = factory.fromString("zh_Hant");
+    GwtLocale zhTW = factory.fromString("zh_TW");
+    GwtLocale zhHantTW = factory.fromString("zh_Hant_TW");
+    GwtLocale zhHans = factory.fromString("zh_Hans");
+    assertEquals(zhCN, zhHansCN.getCanonicalForm());
+    assertEquals(zhTW, zhHantTW.getCanonicalForm());
+    assertEquals(zhCN, zhHans.getCanonicalForm());
+    assertEquals(zhTW, zhHant.getCanonicalForm());
+    GwtLocale paPK = factory.fromString("pa_PK");
+    GwtLocale paArabPK = factory.fromString("pa_Arab_PK");
+    assertEquals(paPK, paArabPK.getCanonicalForm());
+  }

   public void testCompare() {
     GwtLocale[] locales = new GwtLocale[] {
@@ -207,6 +209,27 @@
     assertNull(priv.getVariant());
     assertFalse(priv.isDefault());
   }
+  public void testScriptAliases() {
+    GwtLocale zhCN = factory.fromString("zh_CN");
+    List<GwtLocale> aliases = zhCN.getAliases();
+    assertEquals(2, aliases.size());
+    assertEquals(aliases.get(0), zhCN);
+ assertContainsAndGetPosition(aliases, factory.fromString("zh_Hans_CN"));
+    GwtLocale zhHant = factory.fromString("zh_Hant");
+    aliases = zhHant.getAliases();
+    assertEquals(aliases.get(0), factory.fromString("zh_TW"));
+ assertContainsAndGetPosition(aliases, factory.fromString("zh_Hant_TW"));
+    GwtLocale zhHans = factory.fromString("zh_Hans");
+    aliases = zhHans.getAliases();
+    assertEquals(aliases.get(0), zhCN);
+ assertContainsAndGetPosition(aliases, factory.fromString("zh_Hans_CN"));
+    assertContainsAndGetPosition(aliases, zhHans);
+    GwtLocale pa = factory.fromString("pa");
+    GwtLocale paPK = factory.fromString("pa_PK");
+    GwtLocale paArabPK = factory.fromString("pa_Arab_PK");
+    aliases = paPK.getAliases();
+    assertContainsAndGetPosition(aliases, paArabPK);
+  }

   public void testSearchList() {
     GwtLocale nbNO = factory.fromString("nb_NO");
@@ -243,6 +266,18 @@
     idx_default = assertContainsAndGetPosition(searchList,
         factory.getDefault());
     assertEquals(searchList.size() - 1, idx_default);
+    GwtLocale pa = factory.fromString("pa");
+    GwtLocale paPK = factory.fromString("pa_PK");
+    GwtLocale paArab = factory.fromString("pa_Arab");
+    GwtLocale paGuru = factory.fromString("pa_Guru");
+    searchList = paPK.getCompleteSearchList();
+    int arabPos = assertContainsAndGetPosition(searchList, paArab);
+    int paPos = assertContainsAndGetPosition(searchList, pa);
+    assertNotContains(searchList, paGuru);
+ // See TODO in {...@link GwtLocaleImpl#getCompleteSearchList()} for what is + // needed for this test to pass (and likewise for zh_Hant appearing before
+    // zh in the search list for zh_TW).
+    // assertTrue(arabPos < paPos);
   }

   private <T> int assertContainsAndGetPosition(List<T> list, T value) {

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

Reply via email to