From 8e437f0aaff67761964c5cadd6dc7f184427d823 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Mon, 10 Oct 2022 10:33:29 +0200 Subject: [PATCH] helper translate --- core/class/helper.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 134c9583..dfaf36d3 100644 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -27,7 +27,7 @@ class helper public static function translate($text) { - //helper::googleTranslate('fr_FR', 'fr_FR', $text); + //helper::googleTranslate('fr_FR', 'fr_FR', $text, 'form'); return (array_key_exists($text, core::$dialog) && !empty(core::$dialog[$text]) ? core::$dialog[$text] : $text); } @@ -48,10 +48,13 @@ class helper /** * Fonction pour assurer la traduction des messages */ - public static function googleTranslate($from, $to, $text){ + public static function googleTranslate($from, $to, $text, $target){ + if (!file_exists('site/i18n/' . $target . '.json')) { + file_put_contents ('site/i18n/' . $target . '.json', json_encode([])); + } if (!empty($text)) { //Lecture des données en ligne - $data = json_decode(file_get_contents('site/i18n/' . $to . '.json'), true); + $data = json_decode(file_get_contents('site/i18n/' . $target . '.json'), true); // Mode traduction if ($to !== 'fr_FR') { $arrayjson = json_decode(file_get_contents('https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=' . $to . '&q=' . rawurlencode($text)),true); @@ -69,7 +72,7 @@ class helper // Créer la variable $data = array_merge($data,[$text => '']); } - file_put_contents ('site/i18n/' . $to . '.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX); + file_put_contents ('site/i18n/' . $target . '.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX); } }