🔔 Alert..!! Get 2 Month Free Cloud Hosting With $200 Bonus From Digital Ocean ACTIVATE DEAL

xtr.js is a really small jQuery plugin for client side internationalization that allows to translate text strings in the languages you provide.

localization

Documentation

jquery.xtr

This plugin translate your page client side without page refresh.

Install

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

or

bower install xtr

Usage

  1. add xtr attribute or data-xtr-key="<translation key>" to your elements
<div xtr>Welcome</div>

or

<div data-xtr-key="<translation key>">Good Bye</div>
  1. create translation object
var <translations> = {     "Welcome": {         de: "Willkommen",         fr: "Bienvenue",         es: "Bienvenido"     },     "bye": {         de: "Auf Wiedersehen",         fr: "Au revoir",         es: "Adi?s"     } };
  1. init plugin
$('body').xtr({t: <translations>});

Configuration

default

default init language

default: "en" options: string

lang

translate to after init

default: "en" options: string

regExp

escaped special characters

default:  {             '': /\s/g,             '_': /[&<>"'`\/=]/g           } options: object

Methods

lang()

change new language

$('body').data('plugin_xtr').lang(<languge>);

lang('reset')

set default language

$('body').data('plugin_xtr').lang('reset');

Demo

codepen.io/mel/full/vJNEML

License

@author Mario Vidov
@url www.vidov.it
@twitter MarioVidov
MIT license


You May Also Like