Primer commit del sistema separado falta mejorar mucho

This commit is contained in:
nickpons666
2025-12-30 01:18:46 -06:00
commit 1679c73e52
2384 changed files with 472342 additions and 0 deletions

58
shared/translations/manager.php Executable file
View File

@@ -0,0 +1,58 @@
<?php
/**
* Translation Manager
*/
class TranslationManager {
private static $instance = null;
private $translations = [];
private $language = 'es'; // Idioma por defecto
private function __construct() {
// Obtener el idioma del usuario desde el JWT
if (class_exists('JWTAuth')) {
$userData = JWTAuth::getUserData();
if (isset($userData->idioma)) {
$this->language = $userData->idioma;
}
}
$this->loadTranslations();
}
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new TranslationManager();
}
return self::$instance;
}
private function loadTranslations() {
$filePath = __DIR__ . '/' . $this->language . '.json';
if (file_exists($filePath)) {
$json = file_get_contents($filePath);
$this->translations = json_decode($json, true);
} else {
// Si el archivo de idioma no existe, cargar español por defecto
$defaultFilePath = __DIR__ . '/es.json';
if (file_exists($defaultFilePath)) {
$json = file_get_contents($defaultFilePath);
$this->translations = json_decode($json, true);
}
}
}
public function get($key, $default = null) {
return $this->translations[$key] ?? $default ?? $key;
}
}
/**
* Helper global para traducciones
* @param string $key La clave de traducción.
* @param string|null $default Un valor por defecto si la clave no se encuentra.
* @return string
*/
function __($key, $default = null) {
return TranslationManager::getInstance()->get($key, $default);
}