I18N (whose source is the English word internationalization the first character I and n,18 as the middle character number) is the abbreviation of "internationalization". The I18N encapsulation API in the Chrome plugin framework:
Chrome.i18n.getMessage (name)
The characters used can be defined in a format similar to __msg_extname__, and then invoked through this API, for example:
Chrome.i18n.getMessage (' Extname ')
There is still some work to be done before calling this interface:
1. The directory structure definition of the plug-in, the blue highlighted part is the Multilingual folder:
Myextension
|
|---_locales
| |------en---------Messages.json
| |------ZH_CN----Messages.json
| |------ ...
|---*.js
|---*.html
|--- *.*
2. Manifest.json definition, if _locales is created, the Default_locale field must be defined:
{ "name": "Name", "version": "1.6", "Default_locale": "ZH_CN", "manifest_version": 2, ...}
The 3.messages.json file defines a multi-language symbol in the following format:
{ "extname": { "message": "Plug-in Name", "description": "description" }, "extdescription": { "message": "Plugin description", " Description ":" Description 2 " },
"width": {
"Message": "200px",
"description": "CSS width"
}}
Symbols defined in Messages.json can be used directly in Manifest.json and *.css files, for example:
Manifest.json:
{ "name": "__msg_extname__", "version": "1.6", "Default_locale": "ZH_CN", "manifest_version": 2, "description": "__msg_extdescription__" , ...}
CSS file
{ width: __msg_width__;}
JavaScript files:
var title = Chrome.i18n.getMessage ("Extname");d Ocument.getelementbyid (' div-test '). InnerHTML = Title
*.html file
The corresponding interface has not been found for the time being, according to the Help document, the HTML interface of the multi-language initialization is placed in the JS file, so that work OK. But this approach is not recommended, another scenario: regular.
Use __msg_xxx__ in tags, traverse all textnode nodes, and replace node contents.
Click here to download
Chrome plugin i18n multi-language implementation