【问题标题】:How can a GWT served html page have the lang attribute set?GWT 服务的 html 页面如何设置 lang 属性?
【发布时间】:2014-07-11 02:43:57
【问题描述】:

根据 GAR 合规性,必须在页面上注明语言。

Question 2.9. Is the content’s human language indicated in the markup?
E.g. for a page written in all one language, `<html lang="fr">`, or for a multi-lingual page,  `<div lang="fr">`.

GWT 应用程序在其 gwt.xml 中指明其支持的语言环境列表,并提供具有客户端请求的语言环境的 html 页面。 GWT 应用程序如何在 html 标记中设置 lang 属性? 我们的应用程序是基于 UI 小部件的,因此我们没有主机 html 页面,而是直接将小部件添加到 RootPanel()。

【问题讨论】:

    标签: gwt lang


    【解决方案1】:

    试试这个:

     Document.get().getDocumentElement().setAttribute("lang",
         LocaleInfo.getCurrentLocale().getLocaleName());
    

    【讨论】:

    • 我试过了:HelloWorld helloWorld = new HelloWorld("abcd"); // HelloWorld 是一个 ui 小部件。 Document.get().getBody().appendChild(helloWorld.getElement()); Document.get().getDocumentElement().setAttribute("lang", LocaleInfo.getCurrentLocale().getLocaleName());但是当我在浏览器上去渲染页面的页面源时,html标签中没有任何属性。
    • 试试 .setAttribute("lang", "fr")。你有同样的结果吗?
    • 好的,你的答案已经正确了。浏览器中的页面源没有显示 lang 属性,但将页面保存为文件并在编辑器中打开会显示该属性。
    猜你喜欢
    • 2016-05-13
    • 2016-03-13
    • 2020-08-02
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    相关资源
    最近更新 更多