Gets the localized string for the specified message.
See the Internationalization page for a guide on using this function.
Gets the localized string for the specified message.
See the Internationalization page for a guide on using this function.
browser.i18n.getMessage(
messageName, // string
substitutions // optional any
)
messageName
string
. The name of the message, as specified in the messages.json file. If the message can't be found in messages.json:
substitutions
Optional
string
or array
of string
. A single substitution string, or an array of substitution strings.
In Chrome, if you supply more than 9 substitution strings, getMessage()
will return undefined
.
string
. Message localized for current locale.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
getMessage |
17 |
14["Throws an exception instead returning an empty string if the message does not exist.", "Expects substitutions to be strings, while other browsers allow any value which is then converted to a string."] |
45Firefox 47 and earlier returns "??" instead of "" if the message is not found in _locales, bug 1258199 changed this act to match Chrome, landed on Firefox 48. |
? | 15 | 14 | ? | ? | 48 | ? | 15 | ? |
Get the localized string for "messageContent"
, with target.url
substituted:
let 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."
Note: This API is based on Chromium's chrome.i18n
API. This documentation is derived from i18n.json
in the Chromium code.
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/i18n/getMessage