My Google Chome extension makes use of a content script declared in its manifest via:
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/jquery-1.6.1.min.js", "js/content.js"]
}
],
It also comes with a localization-related resource bundle in _locales/en.
Looking up a key using chrome.i18n.getMessage(...) works flawlessly from general extension code (i.e., in options.html), but it fails (i.e., does not return anything) when executed from js/content.js while that script is being run in the context of the regular web page.
Is this a general limitation (this Chrome bug may be related) or did someone manage to get this working?
I would say a bug report needs to be created.
It doesn’t say anywhere that it is supposed to work, but it doesn’t throw an error that
chrome.i18n.getMessageisn’t accessible from a content scripts either, as all other API calls do. So that’s a bug already.It would be a nice feature to have. I think they started implementing it but either forget or left it for better times. A bug report would be a good reminder.
Meanwhile, you can get localization strings from a background page through messaging. Perhaps send one request at the beginning of a content script requesting an array of all strings you will need.