feat: server-side language preference — survives clear site data
Problem: language preference stored only in localStorage, lost on 'clear site data'. French users with browser lang=fr always got French UI even when profile was English. Solution: - Backend: add 'language' field to user profile (default 'fr') - Backend: PATCH /api/auth/me to update language preference - Frontend: initI18n() priority: server > localStorage > navigator > 'fr' - Frontend: initAuth() runs before initI18n() so server check works - Frontend: profile Save persists language to server via PATCH Verified: tabs show English after server profile set to 'en'
This commit is contained in:
@@ -1561,6 +1561,17 @@ function initProfile() {
|
||||
var newLang = langSel.value;
|
||||
await setLocale(newLang); // Live-reload all translations
|
||||
if (nameInp) localStorage.setItem('obsigate-name', nameInp.value.trim());
|
||||
|
||||
// Persist language to server (survives clear site data)
|
||||
try {
|
||||
await fetch('/api/auth/me', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ language: newLang }),
|
||||
});
|
||||
} catch (e) { /* non-bloquant */ }
|
||||
|
||||
if (savedEl) { savedEl.style.display = 'inline'; setTimeout(function() { savedEl.style.display = 'none'; }, 2000); }
|
||||
} catch(e) {}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user