tinoni / translate.js

A jQuery plugin to translate text in the client side
MIT License
87 stars 84 forks source link

translate.js

A jQuery plugin to translate text in the client side.

Usage

Step 1: include JQuery and translate.js in your page

<script src="https://github.com/tinoni/translate.js/raw/master/jquery.js"/>
<script src="https://github.com/tinoni/translate.js/raw/master/jquery.translate.js"/>

Step 2: every text you want translated include the trn class

<span class="trn">text to translate</span>

Step 3: create your dictionary

var dict = {
  "Home": {
    pt: "Início"
  },
  "Download plugin": {
     pt: "Descarregar plugin",
     en: "Download plugin"
  }
}

Step 4: initialize the plugin and translate the entire page body

var translator = $('body').translate({lang: "en", t: dict}); //use English

Step 5: change to another language

translator.lang("pt"); //change to Portuguese

License

You may use translate.js under the terms of the MIT License. More information.