简体   繁体   English

GWT i18n HTML文件

[英]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. 我已经为Java,UI Binder提供了GWT的i18n功能,并试图为i18n提供纯净的,无托管的Java HTML文件。

After reading " Declarative Layout with UiBinder " I implement some code, but it didn't work: 阅读“ 使用UiBinder进行声明式布局 ”之后,我实现了一些代码,但是没有用:

<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: 具有ID的解决方案(在同一页面上进行了描述: https : //developers.google.com/web-toolkit/doc/latest/tutorial/i18n/ )将由RootPanel提取,如下所示:

RootPanel.get("appTitle").add(new Label(constants.stockWatcher()));

Didn't work too, because my HTML file isn't bundled with Java. 也不起作用,因为我的HTML文件未与Java捆绑在一起。

How to do i18n in HTML files? 如何在HTML文件中使用i18n?

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. 好的,您将在此处看到Catch-22:HTML文件在加载从Java代码中编译出的JavaScript之前不知道要使用哪个文本,这是由页面完成的,因此在加载之后。

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. 您必须使用标准的Java Web应用程序技术来国际化HTML页面,例如使其成为JSP,并从Accept-Languages请求标头中检测首选语言。 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. 如果这样做,则生成适当的<meta name="gwt:property" content="locale=XX">这样GWT应用程序引导程序( .nocache.js文件)也不必猜测它,这可以导致GWT应用程序在与生成HTML时不同的语言环境中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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