15

We define all our internationalized constant strings in a single properties file LocalizableResource_xx.properties (one per language) located in google.gwt.i18n.client.

This way it is possible to access the constants in Java code via the constants interface

Window.alert(myConstants.helloWorld());

as well as to use them inside the UiBinder .ui.xml

<ui:attribute key="some.key" name="text" description="useful info" />

This approach doesn't work well if the string contains a single quote ('). This is because the GWT compiler throws a java.text.ParseException: Unterminated single quote: when it processes the .ui.xml files. If we escape the quote, meaning double it (''), the compiler passes but the strings accessed via the constant interface contain both single quotes (like in You can''t do that).

Replacing the single quotes with the utf-8 encoding \u0027 doesn't help (same exception as above).

Is it somehow possible to use the same properties file in UiBinder templates as well as in Java code without running into annoying single quote problems?

z00bs
  • 7,518
  • 4
  • 34
  • 53
  • 1
    Have you tried escaping it like this: \'? – Paweł Dyda Jun 30 '11 at 16:53
  • 2
    (Just for reference: The Javadoc for [`java.util.Properties.load(Reader)`](http://download.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader)) says: "Escapes are not necessary for single and double quotes; however, by the rule above, single and double quote characters preceded by a backslash still yield single and double quote characters, respectively.") – Chris Lercher Jun 30 '11 at 17:17
  • @Paweł Dyda: Yeah I've tried that, but the `java.text.ParseException` still occurred. – z00bs Jun 30 '11 at 18:48
  • @Chris Lercher: Thanks for the reference but it seems to me that this is more likely a GWT related issue and not related to the properties file format. – z00bs Jun 30 '11 at 18:56

5 Answers5

13

This issue seems to be fixed in the current release.

'' (that's two single quotes) works fine for us!

alex
  • 479,566
  • 201
  • 878
  • 984
Alex
  • 143
  • 1
  • 7
7

The escape char is the single quote ' (instead of the usual backslash \)

Example:

register.form.success=Un courriel a 'ét'é envoy'é a l''adresse suivante ': {0}
Java Devil
  • 10,629
  • 7
  • 33
  • 48
boudu
  • 99
  • 1
  • 4
3

You have to escape your characters using HTML escape characters (e.g. &#39; to represent a single quote ' ) before storing them in your localisation file:

You will find a list of HTML escape characters at http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php (or you can search for "html escape list" on google).

In your case you have to write &#39; instead of "'"

Hope this solves your problem.

Community
  • 1
  • 1
Stefan
  • 14,826
  • 17
  • 80
  • 143
  • Thanks for your reply. I don't get the difference between the two notations of yours. But when I write `"'"` all three chars get output. – z00bs Jul 01 '11 at 21:13
3

Created a bug report for this on the gwt issue tracker - please vote for it: http://code.google.com/p/google-web-toolkit/issues/detail?id=6647

Dennis
  • 31
  • 3
1

Since there doesn't seem to be another solution I'll post our workaround to the mentioned issue:

We created a wrapper class implementing the constants interface that simply passes the i18n constants to a String modify(String) before they're passed to the caller.

public class ConstantsWrapper implements MyConstants {

    private static MyConstants sConstants = GWT.create(MyConstants.class);

    public static String transform(String text) {
        return text.replaceAll("''", "'");
    }

    @Override
    public String someText() {
        return transform(sConstants.someText());
    }

    ...
}

I am still looking forward to a real solution.

z00bs
  • 7,518
  • 4
  • 34
  • 53