i18n.getMessage()
Gets the localized string for the specified message.
Syntax
browser.i18n.getMessage(
messageName, // string
substitutions // optional any
)
Parameters
messageName
string
. The name of the message, as specified in the messages.json file. If the message can't be found in messages.json:-
- Firefox returns "" and logs an error.
- Chrome returns "" and does not log an error.
substitutions
Optionalstring
orarray
ofstring
. A single substitution string, or an array of substitution strings.- In Chrome, if you supply more than 9 substitution strings,
getMessage()
will returnundefined
.
Return value
string
. Message localized for current locale.
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
getMessage | ChromeFull support17 | EdgeFull support14
| FirefoxFull support45
| OperaFull support15 | SafariFull support14 | Firefox for AndroidFull support48 |
Legend
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Examples
Get the localized string for "messageContent"
, with target.url
substituted:
var message = browser.i18n.getMessage("messageContent", target.url);
console.log(message);
This would work with a _locales/en/messages.json file containing:
{
"messageContent": {
"message": "You clicked $URL$.",
"description": "Tells the user which link they clicked.",
"placeholders": {
"url" : {
"content" : "$1",
"example" : "https://developer.mozilla.org"
}
}
}
}
If target.url
is "https://developer.mozilla.org", then the value of message, in the "en" locale, would be:
"You clicked https://developer.mozilla.org."
Example extensions
Acknowledgements
This API is based on Chromium's chrome.i18n
API. This documentation is derived from i18n.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.