Use the chrome.i18n
module to manipulate the i18n related browser
settings, such as the accept languages, or to get localized messages for current
locale.
Examples
The following code gets accept-languages from the browser and display them as a string by separating each accept-language with ','.
function getAcceptLanguages() { chrome.i18n.getAcceptLanguages(function(languageList) { var languages = languageList.join(","); document.getElementById("languageSpan").innerHTML = languages; }) }
The following code gets localized message from the browser and displays it as a string. It replaces two placeholders within the message with values arg1 and arg2.
function getMessage() { var message = chrome.i18n.getMessage("click_here", ["arg1", "arg2"]); document.getElementById("languageSpan").innerHTML = message; }
API reference: chrome.i18n
Methods
getAcceptLanguages
Get accept languages of browser
Parameters
-
callback
( function )
- Undocumented.
Returns
Callback function
If you specify the callback parameter, it should specify a function that looks like this:
function(array of string languages) {...});
-
languages
( array of string )
- Array of the accept languages of the browser, such as en-US,en,zh-CN
getMessage
Get a message from the extension language catalog, for a current locale.
Parameters
-
message_name
( string )
- Message name from the extension catalog.
-
paramName
( optional string or array of string )
- 1 - 9 substitution parameters, if the message requires any.
Returns
-
paramName
( string )
- Message localized for current locale.