translate auto

This commit is contained in:
Fred Tempez 2023-08-05 17:40:42 +02:00
parent 3c64e91db0
commit f4bc54c4aa

View File

@ -2,7 +2,15 @@
$langSource = 'fr_FR'; $langSource = 'fr_FR';
$langTarget = 'de'; $langTargetArray = [
'de',
'en_EN',
'es',
'gr_GR',
'it',
'pt_PT',
'tr_TR'
];
$folderTargetArray = [ $folderTargetArray = [
'../', '../',
/* /*
@ -14,21 +22,26 @@ $folderTargetArray = [
'../modules/search/', '../modules/search/',
*/ */
]; ];
foreach ($folderTargetArray as $keyFolder => $folderTarget) { foreach ($langTargetArray as $langTarget) {
echo $langTarget;
echo '<p>';
foreach ($folderTargetArray as $keyFolder => $folderTarget) {
if (file_exists($folderTarget . $langSource . '.json')) { if (file_exists($folderTarget . $langSource . '.json')) {
$sourceData = json_decode(file_get_contents($folderTarget . $langSource . '.json'), true); $sourceData = json_decode(file_get_contents($folderTarget . $langSource . '.json'), true);
foreach ($sourceData as $originText => $targetText) { foreach ($sourceData as $originText => $targetText) {
if (empty($targetText)) {
echo '<p>'; echo '<p>';
echo $originText; echo $originText;
echo '</p>'; 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); $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]; $targetData[$originText] = $arrayjson[0][0];
} }
echo '</p>';
} }
file_put_contents($folderTarget . $langTarget . '-2.json', json_encode($targetData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); file_put_contents($folderTarget . $langTarget . '-2.json', json_encode($targetData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
echo $folderTarget . ' Done...'; echo $folderTarget . ' Done...';
$targetData = []; $targetData = [];
} }
}
} }