up autotraduction de toutes les pages manquantes en français listées

This commit is contained in:
Tykayn 2025-09-04 00:15:25 +02:00 committed by tykayn
parent eb662fab5a
commit 920cf3af33
34 changed files with 26563 additions and 13 deletions

View file

@ -1128,6 +1128,16 @@ EOT;
}
}
// Load machine translations
$availableTranslations = [];
$translationsFile = $this->getParameter('kernel.project_dir') . '/wiki_compare/translations.json';
if (file_exists($translationsFile)) {
$translationsData = json_decode(file_get_contents($translationsFile), true);
if (isset($translationsData['translations']) && is_array($translationsData['translations'])) {
$availableTranslations = $translationsData['translations'];
}
}
return $this->render('admin/wiki.html.twig', [
'wiki_pages' => $wikiPages,
'missing_translations' => $missingTranslations,
@ -1136,10 +1146,71 @@ EOT;
'specific_pages' => $specificPages,
'newly_created_pages' => $newlyCreatedPages,
'staleness_stats' => $stalenessStats,
'wiki_pages_stats' => $wikiPagesStats
'wiki_pages_stats' => $wikiPagesStats,
'available_translations' => $availableTranslations
]);
}
#[Route('/wiki/translate/{key}', name: 'app_admin_wiki_translate', requirements: ['key' => '.+'])]
public function translate(string $key): Response
{
$this->addFlash('info', 'Traduction en cours pour la page ' . $key);
try {
$scriptPath = $this->getParameter('kernel.project_dir') . '/wiki_compare/wiki_translate.py';
if (file_exists($scriptPath)) {
// Execute the translation script with virtual environment
$command = 'cd ' . $this->getParameter('kernel.project_dir') . ' && source venv/bin/activate && python ' . $scriptPath . ' "' . $key . '"';
$output = [];
$returnVar = 0;
exec($command, $output, $returnVar);
if ($returnVar === 0) {
$this->addFlash('success', 'Traduction réussie pour la page ' . $key);
} else {
$this->addFlash('warning', 'Problème lors de la traduction: ' . implode("\n", $output));
}
} else {
$this->addFlash('error', 'Le script wiki_translate.py n\'existe pas.');
}
} catch (\Exception $e) {
$this->addFlash('error', 'Erreur lors de l\'exécution du script: ' . $e->getMessage());
}
return $this->redirectToRoute('app_admin_wiki');
}
#[Route('/wiki/update-translation/{key}', name: 'app_admin_wiki_update_translation', requirements: ['key' => '.+'])]
public function updateTranslation(string $key): Response
{
$this->addFlash('info', 'Mise à jour de la traduction en cours pour la page ' . $key);
try {
$scriptPath = $this->getParameter('kernel.project_dir') . '/wiki_compare/wiki_translate.py';
if (file_exists($scriptPath)) {
// Execute the translation script with the update flag and virtual environment
$command = 'cd ' . $this->getParameter('kernel.project_dir') . ' && source venv/bin/activate && python ' . $scriptPath . ' "' . $key . '"';
$output = [];
$returnVar = 0;
exec($command, $output, $returnVar);
if ($returnVar === 0) {
$this->addFlash('success', 'Mise à jour de la traduction réussie pour la page ' . $key);
} else {
$this->addFlash('warning', 'Problème lors de la mise à jour de la traduction: ' . implode("\n", $output));
}
} else {
$this->addFlash('error', 'Le script wiki_translate.py n\'existe pas.');
}
} catch (\Exception $e) {
$this->addFlash('error', 'Erreur lors de l\'exécution du script: ' . $e->getMessage());
}
return $this->redirectToRoute('app_admin_wiki');
}
#[Route('/wiki/compare/{key}', name: 'app_admin_wiki_compare', requirements: ['key' => '.+'])]
public function compare(string $key): Response
{
@ -1178,10 +1249,67 @@ EOT;
// Get detailed content comparison from JSON file
$detailedComparison = null;
$mediaDiff = 0;
$historyData = null;
if (file_exists($jsonFile)) {
$jsonData = json_decode(file_get_contents($jsonFile), true);
// Extract history data if available
$historyData = [];
if (isset($jsonData['history']) && is_array($jsonData['history'])) {
// Process history data for the current key
foreach ($jsonData['history'] as $timestamp => $entry) {
$historyEntry = [
'timestamp' => $timestamp,
'date' => (new \DateTime($timestamp))->format('Y-m-d'),
'metrics' => []
];
// Check regular_pages
if (isset($entry['regular_pages']) && is_array($entry['regular_pages'])) {
foreach ($entry['regular_pages'] as $page) {
if (isset($page['key']) && $page['key'] === $key) {
// Extract metrics
$historyEntry['metrics'] = [
'staleness_score' => $page['staleness_score'] ?? 0,
'date_diff' => $page['date_diff'] ?? 0,
'word_diff' => $page['word_diff'] ?? 0,
'section_diff' => $page['section_diff'] ?? 0,
'link_diff' => $page['link_diff'] ?? 0,
'media_diff' => $page['media_diff'] ?? 0
];
$historyData[] = $historyEntry;
break;
}
}
}
// If not found in regular_pages, check specific_pages
if (empty($historyEntry['metrics']) && isset($entry['specific_pages']) && is_array($entry['specific_pages'])) {
foreach ($entry['specific_pages'] as $page) {
if (isset($page['key']) && $page['key'] === $key) {
// Extract metrics
$historyEntry['metrics'] = [
'staleness_score' => $page['staleness_score'] ?? 0,
'date_diff' => $page['date_diff'] ?? 0,
'word_diff' => $page['word_diff'] ?? 0,
'section_diff' => $page['section_diff'] ?? 0,
'link_diff' => $page['link_diff'] ?? 0,
'media_diff' => $page['media_diff'] ?? 0
];
$historyData[] = $historyEntry;
break;
}
}
}
}
// Sort history data by timestamp
usort($historyData, function($a, $b) {
return strtotime($a['timestamp']) - strtotime($b['timestamp']);
});
}
// Check both regular_pages and specific_pages sections
$allPages = [];
if (isset($jsonData['regular_pages']) && is_array($jsonData['regular_pages'])) {
@ -1604,7 +1732,8 @@ EOT;
'en_sections' => $enSections,
'fr_sections' => $frSections,
'en_links' => $enLinks,
'fr_links' => $frLinks
'fr_links' => $frLinks,
'history_data' => $historyData
]);
}