Traduction de la recherche ok

This commit is contained in:
fredtempez 2020-12-05 15:51:53 +01:00
parent 7b4bfcc484
commit e7b320e5ad
2 changed files with 19 additions and 25 deletions

View File

@ -39,7 +39,7 @@ class search extends common {
]; ];
// Message par défaut // Message par défaut
public static $messagePlaceHolder = 'Un ou plusieurs mots-clés séparés par des espaces ou des guillemets'; public static $messagePlaceHolder = '<span class="notranslate">Un ou plusieurs mots-clés séparés par des espaces ou des guillemets</span>';
public static $messageButtontext = 'Rechercher'; public static $messageButtontext = 'Rechercher';
const SEARCH_VERSION = '1.1'; const SEARCH_VERSION = '1.1';
@ -104,7 +104,8 @@ class search extends common {
// Récupération du mot clef passé par le formulaire de ...view/index.php, avec caractères accentués // Récupération du mot clef passé par le formulaire de ...view/index.php, avec caractères accentués
self::$motclef=$this->getInput('searchMotphraseclef'); self::$motclef=$this->getInput('searchMotphraseclef');
// Variable de travail, on conserve la variable globale pour l'affichage du résultat
$motclef = self::$motclef;
// Traduction du mot clé si le script Google Trad est actif // Traduction du mot clé si le script Google Trad est actif
// Le multi langue est sélectionné // Le multi langue est sélectionné
@ -126,29 +127,22 @@ class search extends common {
) )
{ {
// Découper la chaîne // Découper la chaîne
$f = str_getcsv(self::$motclef, ' '); $f = str_getcsv($motclef, ' ');
$f = str_replace(' ','',$f);
$f = str_replace('"','',$f);
// Lire le cookie GoogTrans et déterminer les langues cibles // Lire le cookie GoogTrans et déterminer les langues cibles
$language['target'] = substr($_COOKIE['googtrans'],4,2); $language['origin'] = substr($_COOKIE['googtrans'],4,2);
$language['origin'] = substr($_COOKIE['googtrans'],1,2); $language['target'] = substr($_COOKIE['googtrans'],1,2);
if ($language['target'] !== $language['origin']) { if ($language['target'] !== $language['origin']) {
foreach ($f as $key => $value) { foreach ($f as $key => $value) {
echo $value. "<br>"; $e = $this->translate($language['origin'],$language['target'],$value);
/*$e = $this->translate($language['target'],$language['origin'],$value); $motclef = str_replace($value,$e,$motclef);
self::$motclef = str_replace($value,$e[0][1],self::$motclef);*/
} }
echo self::$motclef;
} }
} }
// Récupération de l'état de l'option mot entier passé par le même formulaire // Récupération de l'état de l'option mot entier passé par le même formulaire
self::$motentier=$this->getInput('searchMotentier', helper::FILTER_BOOLEAN); self::$motentier=$this->getInput('searchMotentier', helper::FILTER_BOOLEAN);
if (self::$motclef !== '' ) { if ($motclef !== '' ) {
foreach($this->getHierarchy(null,false,null) as $parentId => $childIds) { foreach($this->getHierarchy(null,false,null) as $parentId => $childIds) {
if ($this->getData(['page', $parentId, 'disable']) === false && if ($this->getData(['page', $parentId, 'disable']) === false &&
$this->getUser('group') >= $this->getData(['page', $parentId, 'group']) && $this->getUser('group') >= $this->getData(['page', $parentId, 'group']) &&
@ -157,7 +151,7 @@ class search extends common {
$titre = $this->getData(['page', $parentId, 'title']); $titre = $this->getData(['page', $parentId, 'title']);
$contenu = ' ' . $titre . ' ' . $this->getData(['page', $parentId, 'content']); $contenu = ' ' . $titre . ' ' . $this->getData(['page', $parentId, 'content']);
// Pages sauf pages filles et articles de blog // Pages sauf pages filles et articles de blog
$tempData = $this->occurrence($url, $titre, $contenu, self::$motclef, self::$motentier); $tempData = $this->occurrence($url, $titre, $contenu, $motclef, self::$motentier);
if (is_array($tempData) ) { if (is_array($tempData) ) {
$result [] = $tempData; $result [] = $tempData;
} }
@ -172,7 +166,7 @@ class search extends common {
$titre = $this->getData(['page', $childId, 'title']); $titre = $this->getData(['page', $childId, 'title']);
$contenu = ' ' . $titre . ' ' . $this->getData(['page', $childId, 'content']); $contenu = ' ' . $titre . ' ' . $this->getData(['page', $childId, 'content']);
//Pages filles //Pages filles
$tempData = $this->occurrence($url, $titre, $contenu, self::$motclef, self::$motentier); $tempData = $this->occurrence($url, $titre, $contenu, $motclef, self::$motentier);
if (is_array($tempData) ) { if (is_array($tempData) ) {
$result [] = $tempData; $result [] = $tempData;
} }
@ -187,7 +181,7 @@ class search extends common {
$titre = $article['title']; $titre = $article['title'];
$contenu = ' ' . $titre . ' ' . $article['content']; $contenu = ' ' . $titre . ' ' . $article['content'];
// Articles de sous-page de type blog // Articles de sous-page de type blog
$tempData = $this->occurrence($url, $titre, $contenu, self::$motclef, self::$motentier); $tempData = $this->occurrence($url, $titre, $contenu, $motclef, self::$motentier);
if (is_array($tempData) ) { if (is_array($tempData) ) {
$result [] = $tempData; $result [] = $tempData;
} }
@ -205,7 +199,7 @@ class search extends common {
$titre = $article['title']; $titre = $article['title'];
$contenu = ' ' . $titre . ' ' . $article['content']; $contenu = ' ' . $titre . ' ' . $article['content'];
// Articles de Blog // Articles de Blog
$tempData = $this->occurrence($url, $titre, $contenu, self::$motclef, self::$motentier); $tempData = $this->occurrence($url, $titre, $contenu, $motclef, self::$motentier);
if (is_array($tempData) ) { if (is_array($tempData) ) {
$result [] = $tempData; $result [] = $tempData;
} }
@ -298,7 +292,7 @@ class search extends common {
// Requête de traduction avec le script Google // Requête de traduction avec le script Google
private function translate($from_lan, $to_lan, $text) { private function translate($from_lan, $to_lan, $text) {
$arrayjson = json_decode(file_get_contents('https://translate.googleapis.com/translate_a/single?client=gtx&sl='.$from_lan.'&tl='.$to_lan.'&dt=t&q='.$text)); $arrayjson = json_decode(file_get_contents('https://translate.googleapis.com/translate_a/single?client=gtx&sl='.$from_lan.'&tl=fr&dt=t&q='.$text),true);
return $arrayjson; return $arrayjson[0][0][0];
} }
} }

View File

@ -3,10 +3,10 @@
<div class="col10 offset1"> <div class="col10 offset1">
<div class="row"> <div class="row">
<div class="col9 verticalAlignMiddle"> <div class="col9 verticalAlignMiddle">
<?php echo template::text('searchMotphraseclef', [ <?php echo template::text('searchMotphraseclef', [
'placeholder' => $this->getData(['module', $this->getUrl(0), 'placeHolder']) ? $this->getData(['module', $this->getUrl(0), 'placeHolder']) : $module::$messagePlaceHolder, 'placeholder' => $this->getData(['module', $this->getUrl(0), 'placeHolder']) ? $this->getData(['module', $this->getUrl(0), 'placeHolder']) : $module::$messagePlaceHolder,
'value' => $module::$motclef 'value' => $module::$motclef
]); ?> ]); ?>
</div> </div>
<div class="col3 verticalAlignMiddle"> <div class="col3 verticalAlignMiddle">
<?php echo template::submit('pageEditSubmit', [ <?php echo template::submit('pageEditSubmit', [