i18n.getMessage()

Gets the localized string for the specified message.

See the Internationalization page for a guide on using this function.

Syntax

js
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 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.

Return value

string. Message localized for current locale.

Examples

Get the localized string for "messageContent", with target.url substituted:

js
let message = browser.i18n.getMessage("messageContent", target.url);
console.log(message);

This would work with a _locales/en/messages.json file containing:

json
{
  "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

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getMessage
Chrome – Full support
Chrome 17 (Release date: 2012-02-08)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote
footnote Throws an exception instead returning an empty string if the message does not exist.
footnote Expects substitutions to be strings, while other browsers allow any value which is then converted to a string.
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote Firefox 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.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 48 (Release date: 2016-08-02)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

Note: This API is based on Chromium's chrome.i18n API. This documentation is derived from i18n.json in the Chromium code.