docs.rodeo

MDN Web Docs mirror

i18n.getMessage()

{{AddonSidebar}} 

Gets the localized string for the specified message.

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

Syntax

browser.i18n.getMessage(
  messageName,  // string
  substitutions // optional any
)

Parameters

Return value

string. Message localized for current locale.

Browser compatibility

{{Compat}} 

Examples

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

{{WebExtExamples}} 

[!NOTE] This API is based on Chromium’s chrome.i18n API. This documentation is derived from i18n.json in the Chromium code.

In this article

View on MDN