diff --git a/js/app.js b/js/app.js index 8f371ff4..09aa564a 100644 --- a/js/app.js +++ b/js/app.js @@ -1536,32 +1536,32 @@ app = Sammy('#main', function (sam) { }); +/** + * Translations + */ +$.getJSON('locales/en.json', function(data){ + y18n.translations['en'] = data; + y18n.translateInlineHTML(); +}); + +// User defined language +if (window.navigator && window.navigator.language) { + y18n.locale = window.navigator.language.substr(0, 2); + if (y18n.locale !== 'en') { + $.getJSON('locales/'+ y18n.locale +'.json', function(data){ + y18n.translations[y18n.locale] = data; + y18n.translateInlineHTML(); + }); + } +} + + /** * Run the app * */ - $(document).ready(function () { - /** - * Translations - */ - - // Default language - $.getJSON('locales/en.json', function(data){ - y18n.translations['en'] = data; - }); - - // User language - if (window.navigator && window.navigator.language) { - y18n.locale = window.navigator.language.substr(0, 2); - if (y18n.locale !== 'en') { - $.getJSON('locales/'+ y18n.locale +'.json', function(data){ - y18n.translations[y18n.locale] = data; - }); - } - } - /** * Application */ diff --git a/js/y18n.js b/js/y18n.js index 6de487dc..59fba6ea 100644 --- a/js/y18n.js +++ b/js/y18n.js @@ -21,6 +21,27 @@ y18n.init(); + /** + * HTML Inline translation + */ + y18n.translateInlineHTML = function(){ + // Inner HTML + [].forEach.call( + document.querySelectorAll('[data-y18n]'), + function(el){ + el.innerText = y18n.translate(el.getAttribute('data-y18n')) + } + ); + + // Attributes + [].forEach.call( + document.querySelectorAll('[data-y18n-title]'), + function(el){ + el.title = y18n.translate(el.getAttribute('data-y18n-title')) + } + ); + } + /** * Translation */