fix: take into account cookie in js

This commit is contained in:
Anna 2021-10-10 13:42:33 -04:00
parent 1d67debfd0
commit 1a3cecabe5
4 changed files with 23 additions and 4 deletions

View File

@ -42,8 +42,8 @@ body {
} }
.no-js .requires-js { .no-js .requires-js {
display: none; display: none !important;
visibility: hidden; visibility: hidden !important;
} }
details { details {

View File

@ -5,7 +5,7 @@
allowed: [], allowed: [],
centre: 'All', centre: 'All',
list: null, list: null,
lang: 'en', lang: null,
}; };
function addJsClass() { function addJsClass() {
@ -62,6 +62,16 @@
dataCentre.value = state.centre; dataCentre.value = state.centre;
let language = document.getElementById('language'); let language = document.getElementById('language');
if (state.lang === null) {
state.lang = language.dataset.accept;
let cookie = document.cookie
.split(';')
.find(row => row.trim().startsWith('lang='));
if (cookie !== undefined) {
state.lang = decodeURIComponent(cookie.split('=')[1]);
}
}
language.value = state.lang; language.value = state.lang;
} }

View File

@ -30,6 +30,15 @@ pub enum Language {
} }
impl Language { impl Language {
pub fn code(&self) -> &'static str {
match self {
Self::English => "en",
Self::Japanese => "ja",
Self::German => "de",
Self::French => "fr",
}
}
pub fn from_codes(val: Option<&str>) -> Self { pub fn from_codes(val: Option<&str>) -> Self {
let val = match val { let val = match val {
Some(v) => v, Some(v) => v,

View File

@ -52,7 +52,7 @@ Remote Party Finder
</details> </details>
</div> </div>
<div class="right"> <div class="right">
<select id="language"> <select id="language" data-accept="{{ lang.code() }}">
<option value="en">English</option> <option value="en">English</option>
<option value="ja">日本語</option> <option value="ja">日本語</option>
<option value="de">Deutsch</option> <option value="de">Deutsch</option>