|
I18N
jquery.i18n.js
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"
TipEncapsulate 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);
| ||||
► Sign in to add a comment
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',{
});$.i18n('en.player',{
}); }}$. i18n ('dialog', 'ok'), it is normally acquirable with 'OK'. However, a $.i18n ('player', 'volume_max') return value will be 'volume_max'.
Bug when used many Translastion template:
Add
}before the last "else" in file.
Hello, how this handles plural forms?
For example this in PHP: printf(ngettext('%d item', '%d items', $item_count), $item_count);