简体   繁体   English

本地化Google Chrome Web应用

[英]Localizing a Google Chrome Web App

I'm trying to add localization support to a Google Chrome Web App and, while it is easy to define strings for manifest and CSS files, it is somewhat more difficult for HTML pages. 我正在尝试为Google Chrome Web App添加本地化支持,尽管为清单文件和CSS文件定义字符串很容易,但HTML页面却要困难一些。

In the manifest and in CSS files I can simply define localization strings like so: 在清单和CSS文件中,我可以像这样简单地定义本地化字符串:

__MSG_name__

but this doesn't work with HTML pages. 但这不适用于HTML页面。

I can make a JavaScript function to fire onload that does the job like so: 我可以制作一个JavaScript函数来触发执行以下操作的onload:

document.title = chrome.i18n.getMessage("name");
document.querySelector("span.name").innerHTML = chrome.i18n.getMessage("name");

but this seems awfully ineffecient. 但这似乎效率很低。 Furthermore, I would like to be able to specify the page metadata; 此外,我希望能够指定页面元数据; application-name and description, pulling the values from the localization files. 应用程序名称和描述,从本地化文件中提取值。 What would be the best way of doing all this? 做这一切的最好方法是什么?

Thanks for your help. 谢谢你的帮助。

不知道,如果我完全了解您要执行的操作,但是您可以动态地获取目标标记的LANG属性(使用.getAttribute("lang").lang )并相应地提供适当的值。

Please refer to this documentation: http://code.google.com/chrome/extensions/i18n.html 请参阅以下文档: http : //code.google.com/chrome/extensions/i18n.html

If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. 如果要在HTML中添加本地化的内容,则需要通过JavaScript进行操作,如前所述。 That is the only way you can do it. 那是唯一的方法。

chrome.i18n.getMessage("name")

It isn't inefficient to do that, you can place your JavaScript at the end of the document (right before the end body tag) and it will fill up the text with respect to the locale. 这样做并不是没有效率的,您可以将JavaScript放置在文档的末尾(在end body标签之前),它将根据语言环境填充文本。

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

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