Created
June 8, 2022 17:06
-
-
Save nuxodin/fc555138630c57be9eef06fc19869a55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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