Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

translation in JS?

Basically need to generate custom(some different then yes no) messeges(alert) in JS , how to deal with translation in it?

like image 921
simple Avatar asked Mar 04 '10 06:03

simple


1 Answers

Plese take a look at jQuery-i18n translation plugin

var my_dictionary = { 
    "some text"  : "a translation",
    "some more text"  : "another translation"
}
$.i18n.load(my_dictionary);


$('div#example').text($.i18n._('some text'));

And jQuery localisation

$.localise('js/greeting');
$('#greeting').val(greeting);
$('#languages').val($.localise.defaultLanguage);
$('#changeLocale').change(function() {
    var newLang = $(this).val();
    $.localise('js/greeting', {language: newLang, loadBase: true});
    $('#greeting').val(greeting);
    $('#languages').val(newLang);
});

Or, If you really want more translation than looking up data, try google translate api

google.language.translate("Hello world", "en", "es", function(result) {
  if (!result.error) {
    var container = document.getElementById("translation");
    container.innerHTML = result.translation;
  }
});
like image 169
YOU Avatar answered Oct 08 '22 15:10

YOU