Reputation: 585
I have already provided GWT's i18n feature for java, UI Binder and trying to provide i18n with pure, none-hosted in java HTML file.
After reading "Declarative Layout with UiBinder" I implement some code, but it didn't work:
<html xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:with field='i18n' type='//.exampleConstants'/>
<head>
<title>Title of none-hosted HTML file and i18n part: <ui:text from='{i18n.title}'/></title>
</head>
<body>
...
</body>
</html>
The solution with id's (described on same page: https://developers.google.com/web-toolkit/doc/latest/tutorial/i18n/) which will be pick-upped by RootPanel, smth like:
RootPanel.get("appTitle").add(new Label(constants.stockWatcher()));
Didn't work too, because my HTML file isn't bundled with Java.
How to do i18n in HTML files?
Upvotes: 2
Views: 355
Reputation: 64541
Well, you'd have a Catch-22 here: the HTML file couldn't know which text to use until the JavaScript compiled out of your Java code is loaded, which is done by the page, so after it's loaded.
You have to use standard Java web app techniques to internationalize your HTML page, e.g. make it a JSP, and detect the preferred language out of the Accept-Languages
request header. If you do that, then generate the appropriate <meta name="gwt:property" content="locale=XX">
so the GWT app bootstrap (the .nocache.js
file) won't have to guess it too, which could result in the GWT app running in a different locale than the one the HTML was generated with.
Upvotes: 1