Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

i18n.getMessage()

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

Gets the localized string for the specified message.

Syntax

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

This API is also available as browser.i18n.getMessage().

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

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes Yes 45.0 48.0 33

Examples

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

var message = chrome.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 add-ons

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.

ドキュメントのタグと貢献者

 このページの貢献者: Makyen, wbamberg
 最終更新者: Makyen,