Primer commit del sistema separado falta mejorar mucho
This commit is contained in:
75
shared/translations/en.json
Executable file
75
shared/translations/en.json
Executable file
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"main_panel_title": "Main Dashboard - Bot System",
|
||||
"bot_admin_system_title": "Bot Administration System",
|
||||
"languages": "Languages",
|
||||
"logout": "Logout",
|
||||
"discord": "Discord",
|
||||
"discord_description": "Manage your Discord bot, send messages, manage templates, and more",
|
||||
"users": "Users",
|
||||
"messages": "Messages",
|
||||
"templates": "Templates",
|
||||
"telegram": "Telegram",
|
||||
"telegram_description": "Manage your Telegram bot, send messages, manage templates, and more",
|
||||
"discord_dashboard_title": "Discord Dashboard - Bot System",
|
||||
"discord_dashboard_header": "Discord Dashboard",
|
||||
"back_to_main_dashboard": "Back to Main Dashboard",
|
||||
"templates_module_title": "Templates",
|
||||
"templates_module_description": "Manage message templates",
|
||||
"create_message_module_title": "Create Message",
|
||||
"create_message_module_description": "Send messages to Discord",
|
||||
"sent_messages_module_title": "Sent Messages",
|
||||
"sent_messages_module_description": "Message history",
|
||||
"recipients_module_title": "Recipients",
|
||||
"recipients_module_description": "Manage users and channels",
|
||||
"commands_module_title": "Commands",
|
||||
"commands_module_description": "View executed commands",
|
||||
"welcome_message_module_title": "Welcome Message",
|
||||
"welcome_message_module_description": "Configure welcome message",
|
||||
"system_logs_module_title": "System Logs",
|
||||
"system_logs_module_description": "History of errors and events",
|
||||
"gallery_module_title": "Gallery",
|
||||
"gallery_module_description": "Manage images",
|
||||
"languages_module_title": "Languages",
|
||||
"languages_module_description": "Manage translations",
|
||||
"connection_test_module_title": "Connection Test",
|
||||
"connection_test_module_description": "Test connection with Discord",
|
||||
"telegram_dashboard_title": "Telegram Dashboard - Bot System",
|
||||
"telegram_dashboard_header": "Telegram Dashboard",
|
||||
"recipients_module_description_telegram": "Manage users and chats",
|
||||
"connection_test_module_description_telegram": "Test connection with Telegram",
|
||||
"language_manager_title": "Language Management - Bot System",
|
||||
"language_manager_header": "Language Management",
|
||||
"back_to_dashboard": "Back to Dashboard",
|
||||
"available_languages": "Available Languages",
|
||||
"sync_with_libretranslate": "Sync with LibreTranslate",
|
||||
"flag": "Flag",
|
||||
"code": "Code",
|
||||
"name": "Name",
|
||||
"native": "Native",
|
||||
"status": "Status",
|
||||
"action": "Action",
|
||||
"active": "Active",
|
||||
"inactive": "Inactive",
|
||||
"translation_test": "Translation Test",
|
||||
"test_connection_with_libretranslate": "Test the connection with LibreTranslate",
|
||||
"translate_to": "Translate to:",
|
||||
"type_something_to_translate": "Type something to translate...",
|
||||
"translate": "Translate",
|
||||
"result": "Result:",
|
||||
"error": "Error: ",
|
||||
"libretranslate_connection_error": "Connection error with LibreTranslate. Verify that the service is running.",
|
||||
"select_flag": "Select Flag",
|
||||
"paste_emoji_here": "Paste an emoji here...",
|
||||
"save": "Save",
|
||||
"or_select_common_one": "Or select a common one:",
|
||||
"confirm_sync": "Sync languages with LibreTranslate? This will add new available languages.",
|
||||
"syncing": "Syncing...",
|
||||
"synced_languages": "Synced {count} languages",
|
||||
"sync_error": "Error while syncing: ",
|
||||
"connection_error": "Connection error",
|
||||
"confirm_toggle_language": "Activate/deactivate this language?",
|
||||
"language_updated": "Language updated",
|
||||
"language_update_error": "Error updating language",
|
||||
"translating": "Translating...",
|
||||
"json_parse_error": "Error parsing JSON"
|
||||
}
|
||||
75
shared/translations/es.json
Executable file
75
shared/translations/es.json
Executable file
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"main_panel_title": "Panel Principal - Sistema de Bots",
|
||||
"bot_admin_system_title": "Sistema de Administración de Bots",
|
||||
"languages": "Idiomas",
|
||||
"logout": "Cerrar Sesión",
|
||||
"discord": "Discord",
|
||||
"discord_description": "Administra tu bot de Discord, envía mensajes, gestiona plantillas y más",
|
||||
"users": "Usuarios",
|
||||
"messages": "Mensajes",
|
||||
"templates": "Plantillas",
|
||||
"telegram": "Telegram",
|
||||
"telegram_description": "Administra tu bot de Telegram, envía mensajes, gestiona plantillas y más",
|
||||
"discord_dashboard_title": "Dashboard Discord - Sistema de Bots",
|
||||
"discord_dashboard_header": "Dashboard Discord",
|
||||
"back_to_main_dashboard": "Volver al Panel Principal",
|
||||
"templates_module_title": "Plantillas",
|
||||
"templates_module_description": "Gestionar plantillas de mensajes",
|
||||
"create_message_module_title": "Crear Mensaje",
|
||||
"create_message_module_description": "Enviar mensajes a Discord",
|
||||
"sent_messages_module_title": "Mensajes Enviados",
|
||||
"sent_messages_module_description": "Historial de mensajes",
|
||||
"recipients_module_title": "Destinatarios",
|
||||
"recipients_module_description": "Gestionar usuarios y canales",
|
||||
"commands_module_title": "Comandos",
|
||||
"commands_module_description": "Ver comandos ejecutados",
|
||||
"welcome_message_module_title": "Mensaje de Bienvenida",
|
||||
"welcome_message_module_description": "Configurar mensaje de bienvenida",
|
||||
"system_logs_module_title": "Logs del Sistema",
|
||||
"system_logs_module_description": "Historial de errores y eventos",
|
||||
"gallery_module_title": "Galería",
|
||||
"gallery_module_description": "Gestionar imágenes",
|
||||
"languages_module_title": "Idiomas",
|
||||
"languages_module_description": "Gestionar traducciones",
|
||||
"connection_test_module_title": "Test de Conexión",
|
||||
"connection_test_module_description": "Probar conexión con Discord",
|
||||
"telegram_dashboard_title": "Dashboard Telegram - Sistema de Bots",
|
||||
"telegram_dashboard_header": "Dashboard Telegram",
|
||||
"recipients_module_description_telegram": "Gestionar usuarios y chats",
|
||||
"connection_test_module_description_telegram": "Probar conexión con Telegram",
|
||||
"language_manager_title": "Gestión de Idiomas - Sistema de Bots",
|
||||
"language_manager_header": "Gestión de Idiomas",
|
||||
"back_to_dashboard": "Volver al Panel",
|
||||
"available_languages": "Idiomas Disponibles",
|
||||
"sync_with_libretranslate": "Sincronizar con LibreTranslate",
|
||||
"flag": "Bandera",
|
||||
"code": "Código",
|
||||
"name": "Nombre",
|
||||
"native": "Nativo",
|
||||
"status": "Estado",
|
||||
"action": "Acción",
|
||||
"active": "Activo",
|
||||
"inactive": "Inactivo",
|
||||
"translation_test": "Prueba de Traducción",
|
||||
"test_connection_with_libretranslate": "Prueba la conexión con LibreTranslate",
|
||||
"translate_to": "Traducir a:",
|
||||
"type_something_to_translate": "Escribe algo para traducir...",
|
||||
"translate": "Traducir",
|
||||
"result": "Resultado:",
|
||||
"error": "Error: ",
|
||||
"libretranslate_connection_error": "Error de conexión con LibreTranslate. Verifica que el servicio esté corriendo.",
|
||||
"select_flag": "Seleccionar Bandera",
|
||||
"paste_emoji_here": "Pega un emoji aquí...",
|
||||
"save": "Guardar",
|
||||
"or_select_common_one": "O selecciona una común:",
|
||||
"confirm_sync": "¿Sincronizar idiomas con LibreTranslate? Esto agregará nuevos idiomas disponibles.",
|
||||
"syncing": "Sincronizando...",
|
||||
"synced_languages": "Sincronizados {count} idiomas",
|
||||
"sync_error": "Error al sincronizar: ",
|
||||
"connection_error": "Error de conexión",
|
||||
"confirm_toggle_language": "¿Activar/desactivar este idioma?",
|
||||
"language_updated": "Idioma actualizado",
|
||||
"language_update_error": "Error al actualizar idioma",
|
||||
"translating": "Traduciendo...",
|
||||
"json_parse_error": "Error al parsear JSON"
|
||||
}
|
||||
58
shared/translations/manager.php
Executable file
58
shared/translations/manager.php
Executable 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);
|
||||
}
|
||||
75
shared/translations/pt.json
Executable file
75
shared/translations/pt.json
Executable file
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"main_panel_title": "Painel Principal - Sistema de Bots",
|
||||
"bot_admin_system_title": "Sistema de Administração de Bots",
|
||||
"languages": "Idiomas",
|
||||
"logout": "Sair",
|
||||
"discord": "Discord",
|
||||
"discord_description": "Gerencie seu bot do Discord, envie mensagens, gerencie templates e mais",
|
||||
"users": "Usuários",
|
||||
"messages": "Mensagens",
|
||||
"templates": "Templates",
|
||||
"telegram": "Telegram",
|
||||
"telegram_description": "Gerencie seu bot do Telegram, envie mensagens, gerencie templates e mais",
|
||||
"discord_dashboard_title": "Dashboard do Discord - Sistema de Bots",
|
||||
"discord_dashboard_header": "Dashboard do Discord",
|
||||
"back_to_main_dashboard": "Voltar ao Painel Principal",
|
||||
"templates_module_title": "Templates",
|
||||
"templates_module_description": "Gerenciar templates de mensagens",
|
||||
"create_message_module_title": "Criar Mensagem",
|
||||
"create_message_module_description": "Enviar mensagens para o Discord",
|
||||
"sent_messages_module_title": "Mensagens Enviadas",
|
||||
"sent_messages_module_description": "Histórico de mensagens",
|
||||
"recipients_module_title": "Destinatários",
|
||||
"recipients_module_description": "Gerenciar usuários e canais",
|
||||
"commands_module_title": "Comandos",
|
||||
"commands_module_description": "Ver comandos executados",
|
||||
"welcome_message_module_title": "Mensagem de Boas-Vindas",
|
||||
"welcome_message_module_description": "Configurar mensagem de boas-vindas",
|
||||
"system_logs_module_title": "Logs do Sistema",
|
||||
"system_logs_module_description": "Histórico de erros e eventos",
|
||||
"gallery_module_title": "Galeria",
|
||||
"gallery_module_description": "Gerenciar imagens",
|
||||
"languages_module_title": "Idiomas",
|
||||
"languages_module_description": "Gerenciar traduções",
|
||||
"connection_test_module_title": "Teste de Conexão",
|
||||
"connection_test_module_description": "Testar conexão com o Discord",
|
||||
"telegram_dashboard_title": "Dashboard do Telegram - Sistema de Bots",
|
||||
"telegram_dashboard_header": "Dashboard do Telegram",
|
||||
"recipients_module_description_telegram": "Gerenciar usuários e chats",
|
||||
"connection_test_module_description_telegram": "Testar conexão com o Telegram",
|
||||
"language_manager_title": "Gerenciamento de Idiomas - Sistema de Bots",
|
||||
"language_manager_header": "Gerenciamento de Idiomas",
|
||||
"back_to_dashboard": "Voltar ao Painel",
|
||||
"available_languages": "Idiomas Disponíveis",
|
||||
"sync_with_libretranslate": "Sincronizar com LibreTranslate",
|
||||
"flag": "Bandeira",
|
||||
"code": "Código",
|
||||
"name": "Nome",
|
||||
"native": "Nativo",
|
||||
"status": "Status",
|
||||
"action": "Ação",
|
||||
"active": "Ativo",
|
||||
"inactive": "Inativo",
|
||||
"translation_test": "Teste de Tradução",
|
||||
"test_connection_with_libretranslate": "Teste a conexão com o LibreTranslate",
|
||||
"translate_to": "Traduzir para:",
|
||||
"type_something_to_translate": "Digite algo para traduzir...",
|
||||
"translate": "Traduzir",
|
||||
"result": "Resultado:",
|
||||
"error": "Erro: ",
|
||||
"libretranslate_connection_error": "Erro de conexão com o LibreTranslate. Verifique se o serviço está em execução.",
|
||||
"select_flag": "Selecionar Bandeira",
|
||||
"paste_emoji_here": "Cole um emoji aqui...",
|
||||
"save": "Salvar",
|
||||
"or_select_common_one": "Ou selecione um comum:",
|
||||
"confirm_sync": "Sincronizar idiomas com o LibreTranslate? Isso adicionará novos idiomas disponíveis.",
|
||||
"syncing": "Sincronizando...",
|
||||
"synced_languages": "Sincronizados {count} idiomas",
|
||||
"sync_error": "Erro ao sincronizar: ",
|
||||
"connection_error": "Erro de conexão",
|
||||
"confirm_toggle_language": "Ativar/desativar este idioma?",
|
||||
"language_updated": "Idioma atualizado",
|
||||
"language_update_error": "Erro ao atualizar o idioma",
|
||||
"translating": "Traduzindo...",
|
||||
"json_parse_error": "Erro ao analisar JSON"
|
||||
}
|
||||
104
shared/translations/translate.php
Executable file
104
shared/translations/translate.php
Executable file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Habilitar logging para depuración
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
define('DEBUG_MODE', true); // Cambiar a false en producción
|
||||
|
||||
require_once __DIR__ . '/../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../shared/auth/jwt.php';
|
||||
|
||||
// Verificar autenticación
|
||||
try {
|
||||
$userData = JWTAuth::authenticate();
|
||||
if (!$userData) {
|
||||
jsonResponse(['success' => false, 'error' => 'No autenticado'], 401);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
jsonResponse(['success' => false, 'error' => 'Error de autenticación: ' . $e->getMessage()], 401);
|
||||
}
|
||||
|
||||
// Verificar método
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
jsonResponse(['success' => false, 'error' => 'Método no permitido'], 405);
|
||||
}
|
||||
|
||||
// Obtener datos de la petición
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$text = $input['text'] ?? '';
|
||||
$targetLang = $input['target'] ?? '';
|
||||
$sourceLang = $input['source'] ?? 'es';
|
||||
|
||||
// Validar parámetros
|
||||
if (empty($text) || empty($targetLang)) {
|
||||
jsonResponse(['success' => false, 'error' => 'Texto o idioma de destino no especificado'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
// URL de LibreTranslate (ajusta según tu configuración)
|
||||
$ltUrl = getenv('LIBRETRANSLATE_URL') ?: 'http://10.10.4.17:5000';
|
||||
|
||||
// Configurar la petición a LibreTranslate
|
||||
$ch = curl_init("$ltUrl/translate");
|
||||
|
||||
$postData = [
|
||||
'q' => $text,
|
||||
'source' => $sourceLang,
|
||||
'target' => $targetLang,
|
||||
'format' => 'html', // Para mantener formato HTML si existe
|
||||
'api_key' => getenv('LIBRETRANSLATE_API_KEY') ?: ''
|
||||
];
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode($postData),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json'
|
||||
]
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error) {
|
||||
throw new Exception("Error en la petición: $error");
|
||||
}
|
||||
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if ($httpCode !== 200 || !isset($result['translatedText'])) {
|
||||
$errorMsg = $result['error'] ?? 'Error desconocido al traducir';
|
||||
throw new Exception("Error en la traducción: $errorMsg");
|
||||
}
|
||||
|
||||
// Devolver la traducción
|
||||
jsonResponse([
|
||||
'success' => true,
|
||||
'translatedText' => $result['translatedText']
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Error en translate.php: " . $e->getMessage());
|
||||
|
||||
jsonResponse([
|
||||
'success' => false,
|
||||
'error' => 'Error al procesar la traducción',
|
||||
'debug' => DEBUG_MODE ? $e->getMessage() : null
|
||||
], 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Envía una respuesta JSON y termina la ejecución
|
||||
*/
|
||||
function jsonResponse($data, $statusCode = 200) {
|
||||
http_response_code($statusCode);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user