style: apply biome CSS/JS format

This commit is contained in:
Edouard Vanbelle
2026-04-07 22:48:59 +02:00
parent 786a778546
commit 1ce29c101d
86 changed files with 18032 additions and 15166 deletions
+27 -32
View File
@@ -5,18 +5,13 @@
// Locale files that actually exist (have full translations)
// Keep this list in sync when adding new locale JSON files
const AVAILABLE_LOCALES = new Set([
'en', 'es', 'zh', 'fa', 'fr', 'de', 'pt', 'it', 'nl',
'hi', 'ar', 'ru', 'ja', 'ko'
]);
const AVAILABLE_LOCALES = new Set(['en', 'es', 'zh', 'fa', 'fr', 'de', 'pt', 'it', 'nl', 'hi', 'ar', 'ru', 'ja', 'ko']);
// Language codes, names, and flag emojis
// Only returns languages that have a real locale file
function getAvailableLanguages() {
if (typeof ALL_LANGUAGES !== 'undefined') {
return ALL_LANGUAGES
.filter(l => AVAILABLE_LOCALES.has(l.code))
.map(l => ({ code: l.code, name: l.nativeName, flag: l.flag }));
return ALL_LANGUAGES.filter((l) => AVAILABLE_LOCALES.has(l.code)).map((l) => ({ code: l.code, name: l.nativeName, flag: l.flag }));
}
return [
{ code: 'en', name: 'English', flag: '🇬🇧' },
@@ -37,10 +32,10 @@ const rtlLanguages = ['fa', 'ar'];
// Update HTML lang attribute and dir for RTL languages
function updateHtmlAttributes(langCode) {
const htmlElement = document.documentElement;
// Set lang attribute
htmlElement.setAttribute('lang', langCode);
// Set dir attribute for RTL languages
if (rtlLanguages.includes(langCode)) {
htmlElement.setAttribute('dir', 'rtl');
@@ -62,18 +57,18 @@ function createLanguageSelector(containerId = 'language-selector') {
container.id = containerId;
document.body.appendChild(container);
}
// Ensure container has the right class
container.className = 'language-selector';
// Get current language
const languages = getAvailableLanguages();
const currentLocale = window.i18n ? window.i18n.getCurrentLocale() : 'en';
const currentLang = languages.find(l => l.code === currentLocale) || languages[0];
const currentLang = languages.find((l) => l.code === currentLocale) || languages[0];
// Set initial HTML attributes
updateHtmlAttributes(currentLocale);
// Create toggle button
const toggle = document.createElement('div');
toggle.className = 'language-selector-toggle';
@@ -86,14 +81,14 @@ function createLanguageSelector(containerId = 'language-selector') {
<span class="lang-code">${currentLang.code.toUpperCase()}</span>
<i class="fas fa-chevron-down dropdown-arrow"></i>
`;
// Create dropdown menu
const dropdown = document.createElement('div');
dropdown.className = 'language-selector-dropdown';
dropdown.setAttribute('role', 'listbox');
// Add language options
languages.forEach(lang => {
languages.forEach((lang) => {
const option = document.createElement('div');
option.className = `language-option${lang.code === currentLocale ? ' active' : ''}`;
option.setAttribute('role', 'option');
@@ -104,26 +99,26 @@ function createLanguageSelector(containerId = 'language-selector') {
<span class="lang-name">${lang.name}</span>
<i class="fas fa-check lang-check"></i>
`;
option.addEventListener('click', async (e) => {
e.stopPropagation();
await selectLanguage(lang.code, container);
});
dropdown.appendChild(option);
});
// Clear and build container
container.innerHTML = '';
container.appendChild(toggle);
container.appendChild(dropdown);
// Toggle dropdown on click
toggle.addEventListener('click', (e) => {
e.stopPropagation();
toggleDropdown(container);
});
// Keyboard support
toggle.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
@@ -133,19 +128,19 @@ function createLanguageSelector(containerId = 'language-selector') {
closeDropdown(container);
}
});
// Close dropdown when clicking outside
document.addEventListener('click', (e) => {
if (!container.contains(e.target)) {
closeDropdown(container);
}
});
// Listen for locale changes from i18n system
window.addEventListener('localeChanged', (e) => {
updateSelectedLanguage(e.detail.locale, container);
});
return container;
}
@@ -191,10 +186,10 @@ async function selectLanguage(langCode, container) {
if (window.i18n) {
await window.i18n.setLocale(langCode);
}
// Update HTML lang attribute and dir for RTL languages
updateHtmlAttributes(langCode);
updateSelectedLanguage(langCode, container);
closeDropdown(container);
}
@@ -204,17 +199,17 @@ async function selectLanguage(langCode, container) {
*/
function updateSelectedLanguage(langCode, container) {
const languages = getAvailableLanguages();
const lang = languages.find(l => l.code === langCode) || languages[0];
const lang = languages.find((l) => l.code === langCode) || languages[0];
// Update toggle button text
const langCodeSpan = container.querySelector('.lang-code');
if (langCodeSpan) {
langCodeSpan.textContent = lang.code.toUpperCase();
}
// Update active state on options
const options = container.querySelectorAll('.language-option');
options.forEach(option => {
options.forEach((option) => {
const isActive = option.getAttribute('data-lang') === langCode;
option.classList.toggle('active', isActive);
option.setAttribute('aria-selected', isActive);
@@ -224,4 +219,4 @@ function updateSelectedLanguage(langCode, container) {
// Create language selector when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
createLanguageSelector();
});
});