i18n.getMessage()

指定したメッセージのローカライズされた文字列を取得します。

構文

js
browser.i18n.getMessage(
  messageName, // 文字列
  substitutions, // 任意
);

引数

messageName

文字列。messages.json で指定されたメッセージ名です。messages.json 内にメッセージを見つけられない場合は:

  • Firefox は "" を返し、エラーログを出力します。
  • Chrome は "" を返し、エラーログを出力しません。
substitutions省略可

文字列 または 文字列配列。単一の置換文字列、または置換文字列の配列です。 Chrome では、9 個より多くの置換文字列を与えると、getMessage()undefined を返します。

戻り値

文字列。現在のロケール向けにローカライズされたメッセージ。

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getMessage

Legend

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

Full support
Full support
See implementation notes.

target.url を置換文字列として渡し、"messageContent" のローカライズされた文字列を取得します:

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

これは、_locales/en/messages.json ファイルに含まれた次の内容で動作します:

json
{
  "messageContent": {
    "message": "You clicked $URL$.",
    "description": "Tells the user which link they clicked.",
    "placeholders": {
      "url": {
        "content": "$1",
        "example": "https://developer.mozilla.org"
      }
    }
  }
}

target.url が "https://developer.mozilla.org" である場合、"en" ロケールでのメッセージの値は次のようになります:

"You clicked https://developer.mozilla.org."

Example extensions

メモ: この API は、Chromium の chrome.i18n API を基にしています。このドキュメンテーションは、Chromium コード内の i18n.json に由来しています。Microsoft Edge 互換性データは、Microsoft Corporation より供給され、Creative Commons Attribution 3.0 United States License の下で含まれています。