Français // Copyleft 2004-05 BohwaZ. Art Libre. // v0.1.0 class Traducteur { // Dictionnaire des mots SMS (format texte, formatté comme ceci: // mot sms = mot français // (un mot par ligne) var $fichierDico = "traducteur-dico.txt"; var $orthographe = TRUE; var $dico = array(); function Traducteur() { $texte = file($this->fichierDico); $dico = array(); foreach($texte as $ligne) { $tmp = explode("=",$ligne); $smsName = trim($tmp[0]); $frenchName = trim($tmp[1]); $dico[$smsName] = $frenchName; } $this->dico = $dico; } function Traduire($texte) { $texte = ereg_replace("[ ]{2,}"," ",$texte); # Pas propre, à changer, mais pour le moment... $texte = eregi_replace("[^a-z0-9éàèùêûôâç ]","",$texte); $mots = explode(" ",$texte); foreach($mots as $i=>$mot) { if(array_key_exists($mot,$this->dico)) $mots[$i] = $this->dico[$mot]; } $texte = implode(" ",$mots); if($this->orthographe) { exec('echo "'.$texte.'" | ispell -d french -a',$retour); $interdits = array(); foreach($retour as $ligne) { unset($mot,$suggestions); $ligne = str_replace(",","",$ligne); $ligne = explode(" ",$ligne); if($ligne[0] == "&") $suggestions = array_slice($ligne,4); elseif($ligne[0] == "#") $suggestions = array(); if(is_array($suggestions)) { $mot = $ligne[1]; if(in_array($mot,$interdits)) break; $texte = str_replace($mot,'[?'.$mot.(count($suggestions) > 0 ? '=('.implode(",",$suggestions).')': '').']',$texte); $interdits[] = $mot; } } } return $texte; } } if($_POST['texte']) { $trad = new Traducteur(); $texte = $trad->Traduire($_POST['texte']); $texte_propre = eregi_replace("\[\?([^]=]+)(=([^],]+,?)+)?\]","\\1",$texte); } echo ' Traducteur SMS <-> français

Traducteur SMS <-> français

Texte à traduire

Texte modifié.

Texte traduit

'; if($_POST['texte']) { while(eregi("\[\?([^]=]+)(=([^],]+,?)+)?\]",$texte,$out)) { $suggestions = substr($out[2],2,-1); if(strlen($suggestions) > 1) $suggestions = explode(",",$suggestions); $mot = $out[1]; $html = ' '; $texte = str_replace($out[0],$html,$texte); } echo "

"; print_r($existants); echo "
"; #eregi("\[\?([^]=]+)(=([^],]+,?)+)?\]",$texte,$out); #echo "
"; print_r($out);
    #echo "

"; echo $texte; } echo '

'; ?>