public static function translate($code, $language) { $converters = \Ptut\App\Model\Connection::getConnection()->query("" . "Select layout.code as layout, translation.code as translation " . "from layout, translation " . "where layout.id = translation.layoutId and translation.language = (?)", [$language]); $converters = $converters->fetchAll(PDO::FETCH_OBJ); foreach ($converters as $converter) { $converter->layout = Translator::interpret($converter->layout); //debug($converter->layout); } foreach ($converters as $converter) { $code = preg_replace($converter->layout, $converter->translation, $code); } //$code = preg_replace('#(^|\n)(?!/{3})(.*)\n#m', "Erreur de syntaxe\n", $code); //$code = preg_replace('#///#m', '', $code); return $code; }
$ownerId = 1; $pseudoCode = htmlentities($_POST['pseudoCode']); \Ptut\App\Model\LayoutCollection::add($ownerId, $pseudoCode); $layoutId = Ptut\App\Model\Connection::getConnection()->lastInsertId(); $c = $_POST['c']; $php = $_POST['php']; $javascript = $_POST['javascript']; $java = $_POST['java']; $python = $_POST['python']; \Ptut\App\Model\TranslationCollection::add($layoutId, 'c', $c); \Ptut\App\Model\TranslationCollection::add($layoutId, 'php', $php); \Ptut\App\Model\TranslationCollection::add($layoutId, 'javascript', $javascript); \Ptut\App\Model\TranslationCollection::add($layoutId, 'java', $java); \Ptut\App\Model\TranslationCollection::add($layoutId, 'python', $python); } $algo = \Ptut\App\Model\Library::find(['*'], ['id' => 2]); $traduction = \Ptut\App\Controler\Translator::translate(htmlentities($algo->content), 'python'); ?> <div class="row"> <div class="col l6"> <?php echo nl2br($algo->content); ?> </div> <div class="col l6"> <?php echo \Ptut\App\Controler\Translator::layOut($traduction); ?> </div> </div>