mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Implements inline HTML translation.
This commit is contained in:
parent
d5a47711ab
commit
6152f6da21
2 changed files with 41 additions and 20 deletions
20
js/app.js
20
js/app.js
|
@ -1536,32 +1536,32 @@ app = Sammy('#main', function (sam) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the app
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translations
|
* Translations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Default language
|
|
||||||
$.getJSON('locales/en.json', function(data){
|
$.getJSON('locales/en.json', function(data){
|
||||||
y18n.translations['en'] = data;
|
y18n.translations['en'] = data;
|
||||||
|
y18n.translateInlineHTML();
|
||||||
});
|
});
|
||||||
|
|
||||||
// User language
|
// User defined language
|
||||||
if (window.navigator && window.navigator.language) {
|
if (window.navigator && window.navigator.language) {
|
||||||
y18n.locale = window.navigator.language.substr(0, 2);
|
y18n.locale = window.navigator.language.substr(0, 2);
|
||||||
if (y18n.locale !== 'en') {
|
if (y18n.locale !== 'en') {
|
||||||
$.getJSON('locales/'+ y18n.locale +'.json', function(data){
|
$.getJSON('locales/'+ y18n.locale +'.json', function(data){
|
||||||
y18n.translations[y18n.locale] = data;
|
y18n.translations[y18n.locale] = data;
|
||||||
|
y18n.translateInlineHTML();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the app
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$(document).ready(function () {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application
|
* Application
|
||||||
*/
|
*/
|
||||||
|
|
21
js/y18n.js
21
js/y18n.js
|
@ -21,6 +21,27 @@
|
||||||
y18n.init();
|
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
|
* Translation
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue