fix(i18n): sélecteur langue sans emoji flags, détection navigateur multi-lang, défaut anglais
- Options du select : noms natifs (Français, English, Deutsch…) à la place des emojis flags - detectLang() itère navigator.languages[] pour trouver la première langue supportée - Fallback sur "en" au lieu de "fr" si aucune langue connue - Fallback t() sur "en" au lieu de "fr" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6a1b2c3e44
commit
dc9239c38e
2 changed files with 18 additions and 14 deletions
|
|
@ -7,14 +7,18 @@ const API_BASE = "https://bm.nicolasfryder.ovh";
|
||||||
const SUPPORTED_LANGS = ["fr", "en", "de", "es", "it", "pl", "nl", "ro", "pt", "cs", "sv"];
|
const SUPPORTED_LANGS = ["fr", "en", "de", "es", "it", "pl", "nl", "ro", "pt", "cs", "sv"];
|
||||||
|
|
||||||
function detectLang() {
|
function detectLang() {
|
||||||
const nav = (navigator.language || navigator.languages?.[0] || "fr").split("-")[0].toLowerCase();
|
const langs = navigator.languages?.length ? navigator.languages : [navigator.language || "en"];
|
||||||
return SUPPORTED_LANGS.includes(nav) ? nav : "fr";
|
for (const l of langs) {
|
||||||
|
const code = l.split("-")[0].toLowerCase();
|
||||||
|
if (SUPPORTED_LANGS.includes(code)) return code;
|
||||||
|
}
|
||||||
|
return "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentLang = localStorage.getItem("lang") || detectLang();
|
let currentLang = localStorage.getItem("lang") || detectLang();
|
||||||
|
|
||||||
function t(key) {
|
function t(key) {
|
||||||
return window.LOCALES?.[currentLang]?.[key] ?? window.LOCALES?.["fr"]?.[key] ?? key;
|
return window.LOCALES?.[currentLang]?.[key] ?? window.LOCALES?.["en"]?.[key] ?? key;
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyI18n() {
|
function applyI18n() {
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,17 @@
|
||||||
<div class="brand">Metal from Europe</div>
|
<div class="brand">Metal from Europe</div>
|
||||||
<div class="topbar-right">
|
<div class="topbar-right">
|
||||||
<select id="langSelect" class="lang-select" aria-label="Language">
|
<select id="langSelect" class="lang-select" aria-label="Language">
|
||||||
<option value="fr">🇫🇷 FR</option>
|
<option value="en">English</option>
|
||||||
<option value="en">🇬🇧 EN</option>
|
<option value="fr">Français</option>
|
||||||
<option value="de">🇩🇪 DE</option>
|
<option value="de">Deutsch</option>
|
||||||
<option value="es">🇪🇸 ES</option>
|
<option value="es">Español</option>
|
||||||
<option value="it">🇮🇹 IT</option>
|
<option value="it">Italiano</option>
|
||||||
<option value="pl">🇵🇱 PL</option>
|
<option value="pl">Polski</option>
|
||||||
<option value="nl">🇳🇱 NL</option>
|
<option value="nl">Nederlands</option>
|
||||||
<option value="ro">🇷🇴 RO</option>
|
<option value="ro">Română</option>
|
||||||
<option value="pt">🇵🇹 PT</option>
|
<option value="pt">Português</option>
|
||||||
<option value="cs">🇨🇿 CS</option>
|
<option value="cs">Čeština</option>
|
||||||
<option value="sv">🇸🇪 SV</option>
|
<option value="sv">Svenska</option>
|
||||||
</select>
|
</select>
|
||||||
<a href="https://discord.gg/P2DE57Ab" target="_blank" rel="noopener noreferrer" class="social-link" title="Rejoindre notre Discord">
|
<a href="https://discord.gg/P2DE57Ab" target="_blank" rel="noopener noreferrer" class="social-link" title="Rejoindre notre Discord">
|
||||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue