Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/i18n/getmessage/index.md
6580 views
------{{AddonSidebar()}}
Gets the localized string for the specified message.
See the Internationalization page for a guide on using this function.
Syntax
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_inline}}:
stringorarrayofstring. 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
{{Compat}}
Examples
Get the localized string for "messageContent", with target.url substituted:
This would work with a _locales/en/messages.json file containing:
If target.url is "https://developer.mozilla.org", then the value of message, in the "en" locale, would be:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.i18nAPI. This documentation is derived fromi18n.jsonin the Chromium code.