本地化Google Chrome Web App [英] Localizing a Google Chrome Web App

查看:151
本文介绍了本地化Google Chrome Web App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Google Chrome Web应用添加本地化支持,并且为清单和CSS文件定义字符串非常容易,但对于HTML页面来说,这样做有点困难。

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.

在清单和CSS文件中,我可以简单地定义如下的本地化字符串:

In the manifest and in CSS files I can simply define localization strings like so:

__MSG_name__

但这不适用于HTML网页。

but this doesn't work with HTML pages.

我可以创建一个JavaScript函数来触发onload,完成这样的工作:

I can make a JavaScript function to fire onload that does the job like so:

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.

推荐答案

请参阅此文档:
http://代码.google.com / chrome / extensions / i18n.html

如果您想在HTML中添加本地化内容,您需要通过JavaScript你之前提到过。

If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. That is the only way you can do it.

chrome.i18n.getMessage("name")

这样做效率并不低,您可以将JavaScript放在文档的末尾(即在正文标签之前) ),并且它将填充关于语言环境的文本。

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.

这篇关于本地化Google Chrome Web App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆