zwiicms-translations/tools/translate.php

47 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-04-13 10:49:34 +02:00
<?php
$langSource = 'fr_FR';
2023-08-05 17:40:42 +02:00
$langTargetArray = [
'de',
'en_EN',
'es',
'gr_GR',
'it',
'pt_PT',
'tr_TR'
];
2023-04-13 10:49:34 +02:00
$folderTargetArray = [
'../',
/*
'../modules/blog/',
'../modules/news/',
'../modules/form/',
'../modules/gallery/',
'../modules/redirection/',
'../modules/search/',
*/
];
2023-08-05 17:40:42 +02:00
foreach ($langTargetArray as $langTarget) {
echo $langTarget;
echo '<p>';
foreach ($folderTargetArray as $keyFolder => $folderTarget) {
if (file_exists($folderTarget . $langSource . '.json')) {
$sourceData = json_decode(file_get_contents($folderTarget . $langSource . '.json'), true);
foreach ($sourceData as $originText => $targetText) {
2023-04-13 10:49:34 +02:00
echo '<p>';
echo $originText;
2023-08-05 17:40:42 +02:00
echo ' - ';
if (empty($targetText)) {
echo $targetText;
$arrayjson = json_decode(file_get_contents('https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=' . $langTarget . '&q=' . rawurlencode($originText)), true);
$targetData[$originText] = $arrayjson[0][0];
}
2023-04-13 10:49:34 +02:00
echo '</p>';
}
2023-08-05 17:40:42 +02:00
file_put_contents($folderTarget . $langTarget . '-2.json', json_encode($targetData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
echo $folderTarget . ' Done...';
$targetData = [];
2023-04-13 10:49:34 +02:00
}
}
}