Gets the localized string for the specified message.
见 国际化 page for a guide on using this function.
browser.i18n.getMessage(
messageName, // string
substitutions // optional any
)
messageName
string
. The name of the message, as specified in the messages.json file. If the message can't be found in messages.json:
substitutions
可选
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()
将返回
undefined
.
string
. Message localized for current locale.
BCD tables only load in the browser
Get the localized string for
"messageContent"
,采用
target.url
substituted:
var 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"
}
}
}
}
若
target.url
is "https://developer.mozilla.org", then the value of message, in the "en" locale, would be:
"You clicked https://developer.mozilla.org."
注意:
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.
最后修改: , 由 MDN 贡献者