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); }