Skip to content

Instantly share code, notes, and snippets.

@nuxodin
Created June 8, 2022 17:06
Show Gist options
  • Save nuxodin/fc555138630c57be9eef06fc19869a55 to your computer and use it in GitHub Desktop.
Save nuxodin/fc555138630c57be9eef06fc19869a55 to your computer and use it in GitHub Desktop.
function computedLang(el){
let root = el.closest('[lang]');
let lang = root ? root.getAttribute('lang') : navigator.language;
if (!el.matches(':lang('+lang+')')) {
console.warn('lang missmatch!');
for (let l of ['de','en','it','es', /*...*/ ]) if (el.matches(':lang('+l+')')) return l;
}
return lang;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment