GithubHelp home page GithubHelp logo

davidmr001 / jquery.i18n Goto Github PK

View Code? Open in Web Editor NEW

This project forked from t-baby/jquery.i18n

0.0 2.0 0.0 41 KB

A lightweight, internationalization (i18n) plugin based on jQuery.

License: Apache License 2.0

HTML 32.71% JavaScript 67.29%

jquery.i18n's Introduction

jquery.i18n.js

中文文档

A lightweight, internationalization (i18n) plugin based on jQuery.

  • Support to set the default language.
  • Support to switch languages.
  • Support to use json file to storage translation content.

According to user-defined different language versions of the json file, according to demand for rendering language on the page, to achieve internationalization.

Installation

You can download the latest version at https://github.com/ZOMAKE/jquery.i18n/releases

First of all, import the jquery.js file in your project:

<script src="jquery.js"></script>

Then, Include jquery.i18n.js after the jQuery library :

<script src="jquery.i18n.js"></script>

Usage

First, create a new i18n folder in the project, Place the i18n_xx.json language files in different languages under this folder. (You can also customize the beginning and end of the file name, such as BaiduCnLang.js, the following example to i18n_ for the file name at the beginning.)

Include the i18n attribute at the DOM structure that needs to use the internationalization feature.(i18n's value is the language file "key", it can be customized.)

<div i18n="i18n.test">multi-language</div>
<div i18n="i18n.test2">internationalization</div>

Then only need to add content in the language file.

For example, the Chinese version of the language file named i18n_cn.json, the English version of the language file named i18n_en.json:

i18n_cn.json

{
    "i18n.test": "多语言",
    "i18n.test2": "国际化"
}

Corresponding to the translation file i18n_en.json:

{
    "i18n.test": "multi-language",
    "i18n.test2": "internationalization"
}

Finally, execute the following method in the script to initialize the plugin:

$("[i18n]").i18n({
    defaultLang: "en",
    filePath: "/i18n/",
    filePrefix: "i18n_",
    fileSuffix: "",
    forever: true,
    callback: function() {
    }
});

Configuration

defaultLang

defaultLang: defaultLang,

Default language name, plugin will automatically filePrefix + defaultLang + fileSuffix spliced together as the language file name.

filePath

filePath: "/i18n/",

This parameter specifies the location of the folder where the language files are located in the project.

filePrefix

filePrefix: "i18n_",

This parameter specifies the name prefix of the language file.

fileSuffix

fileSuffix: "",

This parameter specifies the name suffix of the language file.

callback

callback:function(){
    //do something
}

i18nOnly

HTML element will be the default placeholder, value, html translation with the replacement, if you only need to replace one, you can declare the HTML tag i18nOnly attribute.

<input i18n="i18n.test" i18n-only="placeholder" placeholder="多语言"></input>

Contributors

jquery.i18n's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.