Created
May 8, 2019 17:50
-
-
Save bodrovis/509c37795718cdb66e582572e1c7ce26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
var current_user = { | |
name: "Alex" | |
}; | |
var consultant = { | |
name: "Ann", | |
gender: "female", | |
message: "How may I help you?" | |
}; | |
$.extend( $.i18n.parser.emitter, { | |
abbr: function (nodes) { | |
return '<abbr title="' + nodes[1] + '">' + nodes[0] + '</abbr>'; | |
} | |
} ); | |
var do_translate = function() { | |
$('h2').i18n(); | |
console.log($.i18n('{{abbr:www|world wide web}}')); | |
$('#welcome').text( | |
$.i18n('welcome', current_user.name) | |
); | |
$('#consulting_chat').text( | |
$.i18n('consulting_info', consultant.name, consultant.gender, consultant.message) | |
); | |
$('#unread_messages').text( | |
$.i18n('unread_messages', 101) | |
); | |
} | |
$.i18n().load({ | |
'en': 'http://localhost/lok/jqi/i18n/en.json', | |
'ru': 'http://localhost/lok/jqi/i18n/ru.json' | |
}).done(function() { | |
$('.locale-switcher').on('click', 'a', function(e) { | |
e.preventDefault(); | |
console.log($(this).data('locale')); | |
$.i18n().locale = $(this).data('locale'); | |
do_translate(); | |
}); | |
do_translate(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment