简体   繁体   中英

GWT i18n HTML files

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?

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, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM