mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 06:46:21 +00:00
traducir en cualquier evento
This commit is contained in:
parent
563c573863
commit
2ae58f4313
1 changed files with 11 additions and 15 deletions
|
@ -1,19 +1,15 @@
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
const clientSideI18n = () => {
|
||||||
const available_locales = ["es","en"];
|
const available_locales = ['es','en']
|
||||||
|
const current_locale = navigator.languages.map(l => l.split('-')[0]).find(l => available_locales.includes(l))
|
||||||
|
|
||||||
let current_locale = navigator.languages.map(function(language) {
|
if (!current_locale) current_locale = available_locales[0]
|
||||||
language.split('-')[0];
|
|
||||||
}).find(function(locale) {
|
|
||||||
return available_locales.includes(available_locales);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (current_locale == undefined) current_locale = available_locales[0];
|
available_locales.forEach(locale => {
|
||||||
|
if (locale == current_locale) return
|
||||||
|
|
||||||
available_locales.forEach(function(locale) {
|
document.querySelectorAll(`[lang=${locale}]`).forEach(el => el.remove())
|
||||||
if (locale == current_locale) return;
|
})
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelectorAll('[lang='+locale+']').forEach(function(el) {
|
document.addEventListener('DOMContentLoaded', clientSideI18n)
|
||||||
el.parentNode.removeChild(el);
|
document.addEventListener('turbolinks:load', clientSideI18n)
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue