mirror of
https://github.com/tips-of-mine/gestion-certificats2.git
synced 2025-07-01 21:38:42 +02:00
Refactor: Vérification des routes et suppression des fichiers .bak
Ce commit inclut les actions suivantes : - Vérification de la syntaxe des définitions de routes dans app/public/index.php. Aucune correction n'a été nécessaire car la potentielle erreur 'AuthController@@logout' était déjà corrigée. - Suppression des fichiers .bak obsolètes : - app/public/index.php.bak - app/public/ocsp_responder.php.bak - app/src/Services/LanguageService.php.bak Ces changements contribuent à la propreté et à la maintenabilité du code.
This commit is contained in:
@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
/**
|
||||
* Service pour gérer la langue de l'application et charger les traductions.
|
||||
*/
|
||||
class LanguageService
|
||||
{
|
||||
private $langDir; // Répertoire où sont stockés les fichiers de traduction
|
||||
private $currentLang; // Langue actuellement sélectionnée
|
||||
|
||||
/**
|
||||
* Constructeur du service de langue.
|
||||
* Initialise la langue actuelle à partir de la session ou une valeur par défaut.
|
||||
*
|
||||
* @param string $langDir Chemin absolu du répertoire des fichiers de traduction.
|
||||
*/
|
||||
public function __construct($langDir)
|
||||
{
|
||||
$this->langDir = rtrim($langDir, '/') . '/'; // Assure qu'il y a un slash final
|
||||
// Récupère la langue de la session ou utilise 'en' par défaut
|
||||
$this->currentLang = $_SESSION['lang'] ?? 'en';
|
||||
// Vérifie si la langue est supportée, sinon revient à 'en'
|
||||
if (!in_array($this->currentLang, SUPPORTED_LANGUAGES)) {
|
||||
$this->currentLang = 'en';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Définit la langue de l'application.
|
||||
*
|
||||
* @param string $lang Le code de la langue (ex: 'fr', 'en').
|
||||
* @return bool Vrai si la langue a été définie avec succès, faux sinon.
|
||||
*/
|
||||
public function setLanguage($lang)
|
||||
{
|
||||
if (in_array($lang, SUPPORTED_LANGUAGES)) {
|
||||
$_SESSION['lang'] = $lang;
|
||||
$this->currentLang = $lang;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne la langue actuellement sélectionnée.
|
||||
*
|
||||
* @return string Le code de la langue.
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->currentLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge et retourne toutes les traductions pour la langue actuelle.
|
||||
*
|
||||
* @return array Tableau associatif des traductions.
|
||||
*/
|
||||
public function getTranslations()
|
||||
{
|
||||
$filePath = $this->langDir . $this->currentLang . '.json';
|
||||
if (file_exists($filePath)) {
|
||||
$content = file_get_contents($filePath);
|
||||
if ($content === false) {
|
||||
error_log("LanguageService: Impossible de lire le fichier de traduction: " . $filePath);
|
||||
return [];
|
||||
}
|
||||
$translations = json_decode($content, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("LanguageService: Erreur de décodage JSON pour le fichier: " . $filePath . " - " . json_last_error_msg());
|
||||
return [];
|
||||
}
|
||||
return $translations;
|
||||
}
|
||||
// Fallback à l'anglais si le fichier de la langue actuelle est manquant
|
||||
$englishFilePath = $this->langDir . 'en.json';
|
||||
if (file_exists($englishFilePath)) {
|
||||
$content = file_get_contents($englishFilePath);
|
||||
if ($content === false) {
|
||||
error_log("LanguageService: Impossible de lire le fichier de traduction anglais de secours: " . $englishFilePath);
|
||||
return [];
|
||||
}
|
||||
$translations = json_decode($content, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("LanguageService: Erreur de décodage JSON pour le fichier anglais de secours: " . $englishFilePath . " - " . json_last_error_msg());
|
||||
return [];
|
||||
}
|
||||
return $translations;
|
||||
}
|
||||
error_log("LanguageService: Aucun fichier de traduction trouvé pour la langue '" . $this->currentLang . "' ou 'en'.");
|
||||
return []; // Retourne un tableau vide si aucune traduction n'est trouvée
|
||||
}
|
||||
|
||||
/**
|
||||
* Traduit une clé donnée.
|
||||
*
|
||||
* @param string $key La clé de traduction.
|
||||
* @param array $replacements Tableau associatif de [placeholder => valeur] pour les remplacements.
|
||||
* @return string La chaîne traduite ou la clé si non trouvée.
|
||||
*/
|
||||
public function __($key, $replacements = [])
|
||||
{
|
||||
// Utilise la variable globale $translations qui est chargée dans index.php
|
||||
global $translations;
|
||||
|
||||
$translatedString = $translations[$key] ?? $key;
|
||||
|
||||
// Effectuer les remplacements de placeholders
|
||||
foreach ($replacements as $placeholder => $value) {
|
||||
$translatedString = str_replace("{" . $placeholder . "}", $value, $translatedString);
|
||||
}
|
||||
|
||||
return $translatedString;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user