Feature: Agregar selección de idiomas por plataforma (Telegram/Discord)
- Agregar columnas telegram_enabled y discord_enabled a supported_languages - Nueva interfaz en admin/languages.php con checkboxes para Telegram y Discord - Los bots ahora solo muestran botones de traducción para los idiomas seleccionados por plataforma
This commit is contained in:
@@ -83,6 +83,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||
} catch (Exception $e) {
|
||||
$syncError = "Error al conectar con LibreTranslate: " . $e->getMessage() . ". Verifica que el servicio esté configurado correctamente en el archivo .env";
|
||||
}
|
||||
|
||||
} elseif ($action === 'toggle_telegram') {
|
||||
$id = (int) $_POST['id'];
|
||||
$stmt = $pdo->prepare("UPDATE supported_languages SET telegram_enabled = NOT telegram_enabled WHERE id = ? AND is_active = TRUE");
|
||||
$stmt->execute([$id]);
|
||||
logActivity(getCurrentUserId(), 'toggle_telegram_language', "Idioma Telegram ID: $id");
|
||||
header('Location: languages.php');
|
||||
exit;
|
||||
|
||||
} elseif ($action === 'toggle_discord') {
|
||||
$id = (int) $_POST['id'];
|
||||
$stmt = $pdo->prepare("UPDATE supported_languages SET discord_enabled = NOT discord_enabled WHERE id = ? AND is_active = TRUE");
|
||||
$stmt->execute([$id]);
|
||||
logActivity(getCurrentUserId(), 'toggle_discord_language', "Idioma Discord ID: $id");
|
||||
header('Location: languages.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,6 +310,8 @@ require_once __DIR__ . '/../templates/header.php';
|
||||
<th><?= t('Código') ?></th>
|
||||
<th><?= t('Nombre') ?></th>
|
||||
<th><?= t('Estado') ?></th>
|
||||
<th><?= t('Telegram') ?></th>
|
||||
<th><?= t('Discord') ?></th>
|
||||
<th><?= t('Acciones') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -310,6 +328,32 @@ require_once __DIR__ . '/../templates/header.php';
|
||||
<span class="badge bg-secondary"><?= t('Inactivo') ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($lang['is_active']): ?>
|
||||
<form method="POST" class="d-inline">
|
||||
<input type="hidden" name="action" value="toggle_telegram">
|
||||
<input type="hidden" name="id" value="<?= $lang['id'] ?>">
|
||||
<button type="submit" class="btn btn-sm btn-outline-<?= $lang['telegram_enabled'] ? 'info' : 'secondary' ?>">
|
||||
<i class="bi bi-<?= $lang['telegram_enabled'] ? 'check-circle-fill' : 'circle' ?>"></i>
|
||||
</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="text-muted"><i class="bi bi-circle"></i></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($lang['is_active']): ?>
|
||||
<form method="POST" class="d-inline">
|
||||
<input type="hidden" name="action" value="toggle_discord">
|
||||
<input type="hidden" name="id" value="<?= $lang['id'] ?>">
|
||||
<button type="submit" class="btn btn-sm btn-outline-<?= $lang['discord_enabled'] ? 'primary' : 'secondary' ?>">
|
||||
<i class="bi bi-<?= $lang['discord_enabled'] ? 'check-circle-fill' : 'circle' ?>"></i>
|
||||
</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="text-muted"><i class="bi bi-circle"></i></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<form method="POST" class="d-inline">
|
||||
<input type="hidden" name="action" value="toggle_status">
|
||||
|
||||
@@ -10,16 +10,19 @@ requireAdmin();
|
||||
|
||||
function getTranslationButtons(PDO $pdo, string $text): array
|
||||
{
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
$languages = $stmt->fetchAll();
|
||||
$stmtTelegram = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1");
|
||||
$telegramLanguages = $stmtTelegram->fetchAll();
|
||||
|
||||
if (count($languages) <= 1) {
|
||||
$stmtDiscord = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1");
|
||||
$discordLanguages = $stmtDiscord->fetchAll();
|
||||
|
||||
if (count($telegramLanguages) <= 1 && count($discordLanguages) <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'telegram' => buildTelegramTranslationButtons($pdo, $languages, $text),
|
||||
'discord' => buildDiscordTranslationButtons($languages, $text)
|
||||
'telegram' => count($telegramLanguages) > 1 ? buildTelegramTranslationButtons($pdo, $telegramLanguages, $text) : [],
|
||||
'discord' => count($discordLanguages) > 1 ? buildDiscordTranslationButtons($discordLanguages, $text) : []
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,19 @@ require_once __DIR__ . '/includes/i18n.php';
|
||||
|
||||
function getTranslationButtons(PDO $pdo, string $text): array
|
||||
{
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
$languages = $stmt->fetchAll();
|
||||
$stmtTelegram = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1");
|
||||
$telegramLanguages = $stmtTelegram->fetchAll();
|
||||
|
||||
if (count($languages) <= 1) {
|
||||
$stmtDiscord = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1");
|
||||
$discordLanguages = $stmtDiscord->fetchAll();
|
||||
|
||||
if (count($telegramLanguages) <= 1 && count($discordLanguages) <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'telegram' => buildTelegramTranslationButtons($pdo, $languages, $text),
|
||||
'discord' => buildDiscordTranslationButtons($languages, $text)
|
||||
'telegram' => count($telegramLanguages) > 1 ? buildTelegramTranslationButtons($pdo, $telegramLanguages, $text) : [],
|
||||
'discord' => count($discordLanguages) > 1 ? buildDiscordTranslationButtons($discordLanguages, $text) : []
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ function handleTemplateCommand(PDO $pdo, Message $message, string $command): voi
|
||||
|
||||
function getDiscordTranslationButtons(PDO $pdo, string $text): array
|
||||
{
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1");
|
||||
$languages = $stmt->fetchAll();
|
||||
|
||||
if (count($languages) <= 1) {
|
||||
@@ -351,7 +351,7 @@ function handleAutoTranslationWithButtons(PDO $pdo, Message $message, string $te
|
||||
$detectedLang = $translator->detectLanguage($textForDetection) ?? $defaultLang;
|
||||
|
||||
// Obtener idiomas activos de la base de datos
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1");
|
||||
$activeLanguages = $stmt->fetchAll();
|
||||
|
||||
if (count($activeLanguages) <= 1) {
|
||||
|
||||
@@ -13,16 +13,19 @@ define('SLEEP_INTERVAL', 5);
|
||||
|
||||
function getTranslationButtons(PDO $pdo, string $text): array
|
||||
{
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
$languages = $stmt->fetchAll();
|
||||
$stmtTelegram = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1");
|
||||
$telegramLanguages = $stmtTelegram->fetchAll();
|
||||
|
||||
if (count($languages) <= 1) {
|
||||
$stmtDiscord = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1");
|
||||
$discordLanguages = $stmtDiscord->fetchAll();
|
||||
|
||||
if (count($telegramLanguages) <= 1 && count($discordLanguages) <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'telegram' => buildTelegramTranslationButtons($pdo, $languages, $text),
|
||||
'discord' => buildDiscordTranslationButtons($languages, $text)
|
||||
'telegram' => count($telegramLanguages) > 1 ? buildTelegramTranslationButtons($pdo, $telegramLanguages, $text) : [],
|
||||
'discord' => count($discordLanguages) > 1 ? buildDiscordTranslationButtons($discordLanguages, $text) : []
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ function handleAutoTranslation(PDO $pdo, Telegram\TelegramSender $sender, src\Tr
|
||||
function getTelegramTranslationButtons(PDO $pdo, string $text): ?array
|
||||
{
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1");
|
||||
$activeLanguages = $stmt->fetchAll();
|
||||
|
||||
if (count($activeLanguages) <= 1) {
|
||||
|
||||
Reference in New Issue
Block a user