Please review this patch, relative to trunk at r3808. Consider the following:
public interface A extends Messages { public interface B extends Messages { @DefaultMessage("foo") String foo(); } } Currently, the translations for the foo method are looked up in files named A$B_locale.properties. The problem is that some build tools don't like filenames with $ in them, and while you might be able to work around it with quoting an easier solution is to also allow the files to be named A_B_locale.properties. Note that this could be a breaking change, since if you had a different interface named A_B there could be confusion about which properties correspond to which class. Hopefully this will be rare. If this approach is accepted, I will create an issue to revisit this solution when AbstractResource/etc are rewritten for XLIFF/etc support. -- John A. Tamplin Software Engineer (GWT), Google --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
Index: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java =================================================================== --- user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java (revision 3808) +++ user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java (working copy) @@ -31,6 +31,15 @@ @Generate(format = "com.google.gwt.i18n.rebind.format.PropertiesFormat") public interface TestAnnotatedMessages extends Messages { + public interface Nested extends Messages { + + @DefaultMessage("nested dollar") + String nestedDollar(); + + @DefaultMessage("nested underscore") + String nestedUnderscore(); +} + @DefaultMessage("Test me") String basicText(); Index: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties =================================================================== --- user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties (revision 0) +++ user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties (revision 0) @@ -0,0 +1 @@ +nestedUnderscore = estednay underscoray Property changes on: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties ___________________________________________________________________ Name: svn:eol-style + native Index: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties =================================================================== --- user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties (revision 0) +++ user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties (revision 0) @@ -0,0 +1 @@ +nestedUnderscore = nested underscore b Property changes on: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties ___________________________________________________________________ Name: svn:eol-style + native Index: user/test/com/google/gwt/i18n/client/I18N2Test.java =================================================================== --- user/test/com/google/gwt/i18n/client/I18N2Test.java (revision 3808) +++ user/test/com/google/gwt/i18n/client/I18N2Test.java (working copy) @@ -16,6 +16,7 @@ package com.google.gwt.i18n.client; import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.TestAnnotatedMessages.Nested; import com.google.gwt.i18n.client.gen.Colors; import com.google.gwt.i18n.client.gen.TestBadKeys; import com.google.gwt.junit.client.GWTTestCase; @@ -32,6 +33,7 @@ return "com.google.gwt.i18n.I18N2Test"; } + @SuppressWarnings("deprecation") public void testAnnotatedMessages() { TestAnnotatedMessages m = GWT.create(TestAnnotatedMessages.class); assertEquals("Test me", m.basicText()); @@ -125,6 +127,18 @@ assertEquals("a circle", s.circle()); } + /** + * Verify that nested annotations are looked up with both A$B names + * and A_B names. Note that $ takes precedence and only one file for a + * given level in the inheritance tree will be used, so A$B_locale will + * be used and A_B_locale ignored. + */ + public void testNestedAnnotations() { + Nested m = GWT.create(Nested.class); + assertEquals("nested dollar b_C", m.nestedDollar()); + assertEquals("nested underscore b", m.nestedUnderscore()); + } + public void testWalkUpColorTree() { Colors colors = (Colors) GWT.create(Colors.class); assertEquals("red_b_C_d", colors.red()); Index: user/test/com/google/gwt/i18n/client/I18NTest.java =================================================================== --- user/test/com/google/gwt/i18n/client/I18NTest.java (revision 3808) +++ user/test/com/google/gwt/i18n/client/I18NTest.java (working copy) @@ -16,6 +16,7 @@ package com.google.gwt.i18n.client; import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.TestAnnotatedMessages.Nested; import com.google.gwt.i18n.client.gen.Colors; import com.google.gwt.i18n.client.gen.Shapes; import com.google.gwt.i18n.client.gen.TestMessages; @@ -51,6 +52,7 @@ return "com.google.gwt.i18n.I18NTest"; } + @SuppressWarnings("unchecked") // intentional test of raw map public void testAnnotatedConstants() { TestAnnotatedConstants c = GWT.create(TestAnnotatedConstants.class); assertEquals(14, c.fourteen()); @@ -115,8 +117,10 @@ assertEquals("PL: Total is US$11,305.01", m.currencyFormat(11305.01)); assertEquals("PL: Default number format is 1,017.1", m.defaultNumberFormat(1017.1)); + @SuppressWarnings("deprecation") + Date date = new Date(107, 11, 1, 12, 1, 2); assertEquals("PL: It is 12:01 PM on Saturday, December 1, 2007", - m.getTimeDate(new Date(107, 11, 1, 12, 1, 2))); + m.getTimeDate(date)); assertEquals("PL: 13 widgets", m.pluralWidgetsOther(13)); assertEquals("Too many widgets to count (150) in pig-latin", m.pluralWidgetsOther(150)); @@ -519,6 +523,13 @@ assertEquals("Extend Protected Inner", extendProtectedInner); } + public void testNestedAnnotations() { + Nested m = GWT.create(Nested.class); + // no translation exists in piglatin for nested dollar + assertEquals("nested dollar", m.nestedDollar()); + assertEquals("estednay underscoray", m.nestedUnderscore()); + } + public void testShapesFamily() { Shapes shapes = (Shapes) GWT.create(Shapes.class); // test overload Index: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties =================================================================== --- user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties (revision 0) +++ user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties (revision 0) @@ -0,0 +1 @@ +nestedDollar = nested dollar b_C Property changes on: user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties ___________________________________________________________________ Name: svn:eol-style + native Index: user/src/com/google/gwt/i18n/rebind/ResourceFactory.java =================================================================== --- user/src/com/google/gwt/i18n/rebind/ResourceFactory.java (revision 3808) +++ user/src/com/google/gwt/i18n/rebind/ResourceFactory.java (working copy) @@ -304,8 +304,15 @@ String partialPath = localizedPath.replace('.', '/'); for (int i = 0; i < loaders.size(); i++) { ResourceFactory element = loaders.get(i); - String path = partialPath + "." + element.getExt(); + String ext = "." + element.getExt(); + String path = partialPath + ext; InputStream m = loader.getResourceAsStream(path); + if (m == null && partialPath.contains("$")) { + // Also look for A_B for inner classes, as $ in path names + // can cause issues for some build tools. + path = partialPath.replace('$', '_') + ext; + m = loader.getResourceAsStream(path); + } if (m != null) { AbstractResource found = element.load(m); found.setPath(path);