My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
I18N  
Updated Feb 4, 2010 by hhh...@gmail.com

jquery.i18n.js

Author Copyright (c) 2008 Maxime Haineault (haineault.com)
License MIT License

This is a plugin proposal to ease plugin translation. It currently support namespaces and language switching.

Example

// Translation templates (always starts with english)
$.i18n('en.datePicker', {
    'Month': 'Month',
    'Year':  'Year',
    'Day':   'Day'
});

$.i18n('fr.datePicker', {
    'Month': 'Mois',
    'Year':  'Année',
    'Day':   'Jour'
});

$.i18n('en');
alert($.i18n('datePicker', 'Year')); // returns "Year"

$.i18n('fr');
alert($.i18n('datePicker', 'Year')); // returns "Année"

Tip

Encapsulate a shortcut function like this when writing your plugin

(function($){

    function _(str, args) { 
        return $.i18n('datePicker', str, args); 
    }

    // then you can use it like this
    alert(_('Year')); // returns "Année"
    
})(jQuery);
Comment by lo...@hotmail.co.jp, Jun 28, 2010

Since it was plug-in which seems to be useful, it used, but extension of name space does not work. The code was written as follows. {{ $.i18n('en.dialog',{

ok : 'OK', cancel : 'Cancel', close : 'Close', yes : 'Yes', no : 'No', error : 'Error'
});

$.i18n('en.player',{

play : 'Play', pasue : 'Pause', stop : 'Stop', volume : 'Volume', volume_max : 'Max Volume', volume_min : 'Mute', seek : 'Seek', fullscreen : 'Full Screen'
}); }}

$. i18n ('dialog', 'ok'), it is normally acquirable with 'OK'. However, a $.i18n ('player', 'volume_max') return value will be 'volume_max'.

Comment by afonta...@efidev.com, Aug 29, 2011

Bug when used many Translastion template:

Add

else if(!$.i18n.translang?ns?)
{
$.i18n.translang?ns? = arguments1?;
}

before the last "else" in file.

Comment by jkuf...@gmail.com, Mar 5, 2012

Hello, how this handles plural forms?

For example this in PHP: printf(ngettext('%d item', '%d items', $item_count), $item_count);


Sign in to add a comment
Powered by Google Project Hosting