JQuery.i18n.properties is a lightweight jquery internationalization plugin that enables the internationalization of the Web front end.
The internationalized English word is: internationalization, also called i18n, "I" is the first letter of the word, "18" is the number of words between "I" and "N", and "N" represents the last letter of the word. JQuery.i18n.properties uses the. properties file to internationalize JavaScript. The JQuery.i18n.properties plugin loads the default resource file (strings.properties) First, and then loads the resource file for the specific locale (strings_ Zh.properties), which guarantees that the default value is always valid when translations for a language are not available.
Resource files are named in the following three formats:
Basename.properties
Basename_language.properties
Basname_language_country.properties
JQuery.i18n.properties API
JQuery.i18n.properties's API is only a few: JQuery.i18n.properties (), JQuery.i18n.prop (), JQuery.i18n.browserLang (), and of course it can be used< Span id= "mathjax-span-4" class= "Mi" >< Span id= "mathjax-span-7" class= "Mo" >< Span id= "mathjax-span-10" class= "Mi" > < Span id= "mathjax-span-15" class= "Mi" > < Span id= "mathjax-span-20" class= "Texatom" > , These APIs are used in the form of. I18n.properties (),. I18n.prop (), $.i18n.browserlang ().
JQuery.i18n.properties (Settings)
This method loads the resource file, where settings is a series of key-value pairs that configure the load option. The specific descriptions of each configuration item are as follows:
Options |
Describe |
Type |
Options available |
Name |
The name of the resource file, such as strings or [STRINGS1,STRINGS2], which represents a resource file, which represents an array of resource files |
String or string[] |
Whether |
Path |
The path where the resource file resides |
String |
Is |
Mode |
Load mode: "VARs" means using a key from a resource file in the form of a JavaScript variable or function "Map" means using the key from the resource file in map mode "Both" means to use both ways. If the key in the resource file contains a JavaScript keyword, you can only use "map." The default value is "VARs". |
String |
Is |
Language |
ISO-639 The specified language encoding (e.g. "en" for English, "zh" for Chinese), or both ISO-639 and ISO-3166 encoding (e.g. "en_US", "ZH_CN"). If not specified, the language encoding that is reported by the browser is used. |
String |
Is |
Cache |
Specifies whether the browser caches the resource files, the default value is False |
Boolean |
Is |
Encoding |
The encoding to use when loading the resource file. The default value is UTF-8 |
String |
Is |
Callback |
callback function to run when code execution is complete |
function |
Is |
function LoadProperties () { jQuery.i18n.properties ({///Load Explorer language for resource file name : ' Strings ',//resource file name path: ' /i18n/',///resource file path mode: ' Map ',//Use the value in the resource file in map mode language: ' zh ', callback:function () {//The display content is set after successful loading $ ('. L-btn-text '). each (the function () { $ (this). Text ($.i18n.prop (the. Text ()) );} );});
JQuery.i18n.prop (Key)
The method uses the value in the resource file in map mode, where key refers to the key in the resource file. When the value specified by key contains a placeholder, use JQuery.i18n.prop (Key,val1,val2 ...) is available. The form of which val1,val2 ... The order is replaced by the dot character.
JQuery.i18n.browserLang ()
Used to obtain language information for the browser.
How to use
Project Organizational Structure
In the i18n directory, strings.properties corresponds to the default translation, Strings_zh.properties corresponds to the Chinese translation.
Strings.properties
Strings_zh.properties
<script type= "Text/javascript" src= "/js/jquery-1.7.2.min.js" ></script><script type= "text/ JavaScript "src="/js/jquery.i18n.properties-1.0.9.js "></script>
<div id= "Content" > <div> <label id= "Label_username" ></label> <input type= " Text "id=" username "></input> </div> <div> <label id=" Label_password ">< /label> <input type= "password" id= "password" ></input> </div> <input type= " Button "id=" Button_login "/> </div>
<script type= "Text/javascript" > $ (function () { jQuery.i18n.properties ({ name: ' Strings ',// Source file name path : '/i18n/',//resource file path mode: ' Map ',//Use the value in the resource file in map mode language: ' zh ', callback:function () {///load successfully after setting display content $ (' #button-login '). HTML ($.i18n.prop (' login ')); $ (' #label-username '). HTML ($.i18n.prop (' User Name ')); $ (' #label-password '). HTML ($.i18n.prop (' Password ');});}) ; </script>
:
Https://code.google.com/p/jquery-i18n-properties/downloads/list
jquery Front-end internationalization jQuery.i18n.properties