diff --git a/_includes/header-en.html b/_includes/header-en.html index 445e986..99ab9a8 100644 --- a/_includes/header-en.html +++ b/_includes/header-en.html @@ -22,8 +22,8 @@  English diff --git a/_includes/header.html b/_includes/header.html index 8ebc253..c1f0c58 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -22,8 +22,8 @@  Русский diff --git a/_layouts/default-en.html b/_layouts/default-en.html index bbe35e6..615bd65 100644 --- a/_layouts/default-en.html +++ b/_layouts/default-en.html @@ -1,41 +1,63 @@ - - - - - {{ page.title }} - - - - - - - - - - - - - - {% feed_meta %} - {% seo %} - + + + + + + + + + + + + {% feed_meta %} {% seo %} + - - {% include header-en.html %} -
- {{ content }} -
- {% include footer.html %} - - - - \ No newline at end of file + + {% include header-en.html %} +
{{ content }}
+ {% include footer.html %} + + + diff --git a/_layouts/default.html b/_layouts/default.html index 88df5fa..1262d5d 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -1,41 +1,63 @@ - - - - - {{ page.title }} - - - - - - - - - - - - - - {% feed_meta %} - {% seo %} - + + + + + + + + + + + + {% feed_meta %} {% seo %} + - - {% include header.html %} -
- {{ content }} -
- {% include footer.html %} - - - - \ No newline at end of file + + {% include header.html %} +
{{ content }}
+ {% include footer.html %} + + + diff --git a/assets/scripts/change_language.js b/assets/scripts/change_language.js new file mode 100644 index 0000000..48164dd --- /dev/null +++ b/assets/scripts/change_language.js @@ -0,0 +1,41 @@ +function usePrefferedLanguage(newLang) { + function changeLanguageTo(language) { + if (document.title.includes('404')) return; // TODO: make an english version of 404 + if (document.querySelector('html').lang == language) return; + switch (language) { + case 'en': + location.pathname = `/en${location.pathname}`; + break; + + case 'ru': + location.pathname = location.pathname.replace('/en', ''); + break; + + default: + break; + } + } + + function browserPrefferedLanguage() { + if (navigator.languages.includes('ru')) { + return 'ru'; + } + return 'en'; + } + + let prefferedLanguage = localStorage.getItem('prefferedLanguage'); + + if (newLang) { + localStorage.setItem('prefferedLanguage', newLang); + prefferedLanguage = localStorage.getItem('prefferedLanguage'); + } + + if (!prefferedLanguage) { + localStorage.setItem('prefferedLanguage', browserPrefferedLanguage()); + prefferedLanguage = localStorage.getItem('prefferedLanguage'); + } + + changeLanguageTo(prefferedLanguage); +} + +usePrefferedLanguage();