website/templates/language_redirect.html
vachan-maker 3d33a840b2 Add proper FAQ page and TTS instructions
Signed-off-by: meenbeese <meenbeese@tutanota.com>
Signed-off-by: S. Kozyr <s.trump@gmail.com>
Signed-off-by: Alexander Borsuk <me@alex.bio>
2024-03-07 00:45:07 +02:00

23 lines
1.1 KiB
HTML

<script>
// Supports partially translated pages.
// Redirects a user to his preferred language page translation only if
// there were no previous redirects or explicit language selections before (see language_seletor.html)
if (null === window.localStorage.getItem('lang')) {
// ["en", "ru", ...]
var pageTranslations = {{ resource | get(key="translations", default=[]) | map(attribute="lang") | sort | json_encode() | safe }};
var userPreferredLanguages = navigator.languages ? navigator.languages : [navigator.language];
outerLoop:
for (var i = 0; i < userPreferredLanguages.length; i++) {
for (var j = 0; j < pageTranslations.length; j++) {
if (userPreferredLanguages[i].indexOf(pageTranslations[j]) == 0) {
window.localStorage.setItem('lang', pageTranslations[j]);
// Do not redirect the default 'en' language.
if (pageTranslations[j] != '{{ config.default_language }}') {
window.location.pathname = '/' + pageTranslations[j] + window.location.pathname;
}
break outerLoop;
}
}
}
}
</script>