- Backend PHP: architecture MVC avec API REST (upload, merge, preview, extract) - Frontend JavaScript: composants modulaires (arborescence, upload, themes, i18n) - Fonctionnalités: drag&drop, sélection exclusive, détection conflits, persistance état - Sécurité: validation stricte, isolation sessions, sanitization chemins - UI/UX: responsive, thèmes clair/sombre, multi-langue (FR/EN) - Documentation: README complet avec installation et utilisation
106 lines
2.8 KiB
JavaScript
106 lines
2.8 KiB
JavaScript
/**
|
|
* FuZip - Gestionnaire de langue (Bilingual FR/EN)
|
|
* Gère le toggle entre français et anglais avec persistance localStorage
|
|
*/
|
|
|
|
class LanguageManager {
|
|
constructor() {
|
|
this.storageKey = 'fuzip_lang';
|
|
this.currentLang = this.loadLang();
|
|
this.btnToggle = document.getElementById('btn-lang-toggle');
|
|
this.i18n = window.FUZIP_CONFIG?.i18n || {};
|
|
|
|
this.init();
|
|
}
|
|
|
|
/**
|
|
* Initialise le gestionnaire de langue
|
|
*/
|
|
init() {
|
|
// Écoute le clic sur le bouton toggle
|
|
if (this.btnToggle) {
|
|
this.btnToggle.addEventListener('click', () => this.toggle());
|
|
}
|
|
|
|
// Synchronise le localStorage avec la langue actuelle de la page
|
|
this.saveLang(this.currentLang);
|
|
|
|
console.log(`[LanguageManager] Initialized with lang: ${this.currentLang}`);
|
|
}
|
|
|
|
/**
|
|
* Charge la langue depuis localStorage ou depuis la config globale
|
|
* @returns {string} 'fr' ou 'en'
|
|
*/
|
|
loadLang() {
|
|
// Vérifie localStorage en premier
|
|
const saved = localStorage.getItem(this.storageKey);
|
|
if (saved === 'fr' || saved === 'en') {
|
|
return saved;
|
|
}
|
|
|
|
// Sinon utilise la langue de la config (depuis PHP)
|
|
return window.FUZIP_CONFIG?.lang || 'fr';
|
|
}
|
|
|
|
/**
|
|
* Sauvegarde la langue dans localStorage
|
|
* @param {string} lang - 'fr' ou 'en'
|
|
*/
|
|
saveLang(lang) {
|
|
if (lang === 'fr' || lang === 'en') {
|
|
localStorage.setItem(this.storageKey, lang);
|
|
this.currentLang = lang;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Toggle entre français et anglais
|
|
* Recharge la page avec le paramètre ?lang=XX
|
|
*/
|
|
toggle() {
|
|
const newLang = this.currentLang === 'fr' ? 'en' : 'fr';
|
|
this.saveLang(newLang);
|
|
|
|
// Recharge la page avec le nouveau paramètre lang
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.set('lang', newLang);
|
|
window.location.href = url.toString();
|
|
}
|
|
|
|
/**
|
|
* Récupère la langue actuelle
|
|
* @returns {string}
|
|
*/
|
|
getLang() {
|
|
return this.currentLang;
|
|
}
|
|
|
|
/**
|
|
* Définit une langue spécifique
|
|
* @param {string} lang - 'fr' ou 'en'
|
|
*/
|
|
setLang(lang) {
|
|
if (lang === 'fr' || lang === 'en') {
|
|
this.saveLang(lang);
|
|
|
|
// Recharge la page
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.set('lang', lang);
|
|
window.location.href = url.toString();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Récupère une traduction depuis l'objet i18n
|
|
* @param {string} key - Clé de traduction
|
|
* @returns {string}
|
|
*/
|
|
t(key) {
|
|
return this.i18n[key] || key;
|
|
}
|
|
}
|
|
|
|
// Export pour utilisation dans app.js
|
|
window.LanguageManager = LanguageManager;
|