Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

i18n.getMessage()

Gets the localized string for the specified message.

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

string orarray ofstring. 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.

Examples

Get the localized string for"messageContent", withtarget.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"      }    }  }}

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

Note:This API is based on Chromium'schrome.i18n API. This documentation is derived fromi18n.json in the Chromium code.

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp