开发者

Localizing a Google Chrome Web App

开发者 https://www.devze.com 2023-01-27 17:22 出处:网络
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.

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.

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

__MSG_name__

but this doesn't work with HTML pages.

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 in开发者_StackOverflow中文版effecient. 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.


Please refer to this documentation: 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. 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.


Dunno if i understand exactly what you are trying to do but you could dynamically retrieve the LANG attribute (using .getAttribute("lang") or .lang) of the targeted tag and serve accordingly the proper values.

0

精彩评论

暂无评论...
验证码 换一张
取 消