Chrome plugin i18n multi-language implementation

Source: Internet
Author: User
Tags i18n

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.