How to handle single quotes in internationalization constants?

隐身守侯 提交于 2019-12-03 23:52:22
Alex

This issue seems to be fixed in the current release.

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

boudu

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}

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

Stefan

You have to escape your characters using HTML escape characters (e.g. ' 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 ' instead of "'"

Hope this solves your problem.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!