From e4726d0cb2d6a45235164c72a58a8560a3882f15 Mon Sep 17 00:00:00 2001 From: diaco Date: Sun, 4 Oct 2026 11:00:31 +0330 Subject: [PATCH] Default to Persian and use SVG language flags Co-authored-by: Cursor --- slips/static/slips/css/style.css | 14 ++++++++++++++ slips/static/slips/js/i18n.js | 14 +++++++++++--- slips/templates/slips/base.html | 22 ++++++++++++++-------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/slips/static/slips/css/style.css b/slips/static/slips/css/style.css index 92e555a..3ba845a 100644 --- a/slips/static/slips/css/style.css +++ b/slips/static/slips/css/style.css @@ -137,6 +137,20 @@ html[lang="fa"] body { gap: 0.5rem; } +.lang-label { + display: inline-flex; + align-items: center; + gap: 0.35rem; +} + +.lang-flag { + width: 1.15em; + height: 0.85em; + border-radius: 2px; + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15); + flex-shrink: 0; +} + /* Layout */ .main-content { max-width: 1200px; diff --git a/slips/static/slips/js/i18n.js b/slips/static/slips/js/i18n.js index 9f939d3..dc0e8dc 100644 --- a/slips/static/slips/js/i18n.js +++ b/slips/static/slips/js/i18n.js @@ -83,9 +83,15 @@ const translations = { } }; -let currentLang = localStorage.getItem('slip_lang') || 'en'; +let currentLang = localStorage.getItem('slip_lang') || 'fa'; let currentTheme = localStorage.getItem('slip_theme') || 'light'; +// SVG flags: Windows often cannot render flag emojis (shows "IR"/"GB" instead) +const FLAG_SVG = { + fa: '', + en: '', +}; + function applyTheme(theme) { document.documentElement.setAttribute('data-theme', theme); const label = document.getElementById('theme-label'); @@ -111,10 +117,12 @@ function applyLanguage(lang) { el.textContent = translations[lang][key]; } }); - + + // Button shows the language you can switch to const toggleBtn = document.getElementById('lang-label'); if (toggleBtn) { - toggleBtn.textContent = lang === 'en' ? '🇮🇷 FA' : '🇬🇧 EN'; + const next = lang === 'en' ? 'fa' : 'en'; + toggleBtn.innerHTML = FLAG_SVG[next] + ' ' + next.toUpperCase(); } if (typeof window.updateLabelsPreview === 'function') { diff --git a/slips/templates/slips/base.html b/slips/templates/slips/base.html index 5c13e33..05df980 100644 --- a/slips/templates/slips/base.html +++ b/slips/templates/slips/base.html @@ -1,10 +1,10 @@ {% load static %} - + - {% block title %}Lithium | Print Label{% endblock %} + {% block title %}لیتیوم |‌ پرینت لیبل{% endblock %} @@ -15,6 +15,9 @@ (function () { var t = localStorage.getItem('slip_theme') || 'light'; document.documentElement.setAttribute('data-theme', t); + var lang = localStorage.getItem('slip_lang') || 'fa'; + document.documentElement.lang = lang; + document.documentElement.dir = lang === 'fa' ? 'rtl' : 'ltr'; })(); {% block extra_head %}{% endblock %} @@ -24,19 +27,22 @@ -- 2.49.1