5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 12:16:22 +00:00
panel/public/client_site_i18n.js

16 lines
536 B
JavaScript
Raw Normal View History

2020-08-01 17:12:27 +00:00
const clientSideI18n = () => {
const available_locales = ['es','en']
const current_locale = navigator.languages.map(l => l.split('-')[0]).find(l => available_locales.includes(l))
2020-08-01 00:06:26 +00:00
2020-08-01 17:12:27 +00:00
if (!current_locale) current_locale = available_locales[0]
2020-08-01 00:06:26 +00:00
2020-08-01 17:12:27 +00:00
available_locales.forEach(locale => {
if (locale == current_locale) return
2020-08-01 00:06:26 +00:00
2020-08-01 17:12:27 +00:00
document.querySelectorAll(`[lang=${locale}]`).forEach(el => el.remove())
})
}
2020-08-01 00:06:26 +00:00
2020-08-01 17:12:27 +00:00
document.addEventListener('DOMContentLoaded', clientSideI18n)
document.addEventListener('turbolinks:load', clientSideI18n)