Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle single quotes in internationalization constants?

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?

like image 350
z00bs Avatar asked Jun 30 '11 16:06

z00bs


People also ask

How do you handle a single quote in a string?

Use escapeEcmaScript method from Apache Commons Lang package: Escapes any values it finds into their EcmaScript String form. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.). So a tab becomes the characters '\\' and 't' .

How do you escape single quote in Yaml?

In single quoted strings the single quote character can be escaped by prefixing it with another single quote, basically doubling it. Backslashes in single quoted strings do not need to be escaped. Quoted strings can also span across multiple lines, just indent the following lines.

How do you escape a single quote?

Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.

How do you escape a single quote in Swift?

Using escape character for single quotes \' = ' and interpolation ( \() )for variables you can achieve this in one string.


2 Answers

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}
like image 20
boudu Avatar answered Oct 21 '22 09:10

boudu


This issue seems to be fixed in the current release.

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

like image 99
Alex Avatar answered Oct 21 '22 09:10

Alex