tableau 'translate' devient 'i18n'

This commit is contained in:
Fred Tempez 2021-05-04 18:17:33 +02:00
parent bd0062ecd2
commit cbd3deede9
6 changed files with 82 additions and 93 deletions

View File

@ -252,8 +252,8 @@ class common {
*/
if ( $this->getData(['config', 'i18n', 'enabled']) === true
AND $this->getData(['config','translate','scriptGoogle']) === true
AND $this->getData(['config','translate','autoDetect']) === true
AND $this->getData(['config', 'i18n','scriptGoogle']) === true
AND $this->getData(['config', 'i18n','autoDetect']) === true
AND $this->getInput('ZWII_I18N_SITE') !== ''
AND !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) )
{
@ -1659,17 +1659,17 @@ class common {
$this->setData(['config','autoDisconnect',true]);
// Mettre à jour les données de langue
$this->setData(['config','translate','scriptGoogle', false ]);
$this->setData(['config','translate','showCredits', false ]);
$this->setData(['config','translate','autoDetect', false ]);
$this->setData(['config','translate','admin', false ]);
$this->setData(['config','translate','fr', false ]);
$this->setData(['config','translate','de', false ]);
$this->setData(['config','translate','en', false ]);
$this->setData(['config','translate','es', false ]);
$this->setData(['config','translate','it', false ]);
$this->setData(['config','translate','nl', false ]);
$this->setData(['config','translate','pt', false ]);
$this->setData(['config', 'i18n','scriptGoogle', false ]);
$this->setData(['config', 'i18n','showCredits', false ]);
$this->setData(['config', 'i18n','autoDetect', false ]);
$this->setData(['config', 'i18n','admin', false ]);
$this->setData(['config', 'i18n','fr', false ]);
$this->setData(['config', 'i18n','de', false ]);
$this->setData(['config', 'i18n','en', false ]);
$this->setData(['config', 'i18n','es', false ]);
$this->setData(['config', 'i18n','it', false ]);
$this->setData(['config', 'i18n','nl', false ]);
$this->setData(['config', 'i18n','pt', false ]);
$this->setData(['core', 'dataVersion', 11000]);
}
@ -2299,11 +2299,11 @@ class core extends common {
// Le script de traduction est sélectionné
if ($this->getData(['config', 'i18n', 'enabled']) === true) {
if ( $this->getData(['config','translate','scriptGoogle']) === true
if ( $this->getData(['config', 'i18n','scriptGoogle']) === true
// et la traduction de la langue courante est automatique
AND ( $this->getInput('ZWII_I18N_SCRIPT') !== ''
// Ou traduction automatique
OR $this->getData(['config','translate','autoDetect']) === true
OR $this->getData(['config', 'i18n','autoDetect']) === true
)
// Cas des pages d'administration
// Pas connecté
@ -2311,7 +2311,7 @@ class core extends common {
AND $this->getUrl(1) !== 'login'
// Ou connecté avec option active
OR ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getData(['config','translate','admin']) === true
AND $this->getData(['config', 'i18n','admin']) === true
)
) {
@ -2467,12 +2467,12 @@ class layout extends common {
* La fonction est activée.
*/
if ( $this->getData(['config', 'i18n', 'enabled']) === true
AND $this->getData(['config','translate','scriptGoogle']) === true
AND $this->getData(['config','translate','showCredits']) === true
AND $this->getData(['config', 'i18n','scriptGoogle']) === true
AND $this->getData(['config', 'i18n','showCredits']) === true
AND
// et la traduction n'est pas manuelle
( $this->getInput('ZWII_I18N_SCRIPT')
AND $this->getData(['config','translate', $this->getInput('ZWII_I18N_SCRIPT')]) === 'script'
AND $this->getData(['config', 'i18n', $this->getInput('ZWII_I18N_SCRIPT')]) === 'script'
)
)
{
@ -3182,10 +3182,10 @@ class layout extends common {
public function showi18n($id) {
echo '<div id="i18nContainer' . $id . '"><ul>';
foreach (self::$i18nList as $key => $value) {
if ($this->getData(['config','translate',$key]) === 'site'
if ($this->getData(['config', 'i18n',$key]) === 'site'
OR (
$this->getData(['config','translate','scriptGoogle']) === true
AND $this->getData(['config','translate',$key]) === 'script'
$this->getData(['config', 'i18n','scriptGoogle']) === true
AND $this->getData(['config', 'i18n',$key]) === 'script'
)
) {
if (
@ -3202,7 +3202,7 @@ class layout extends common {
}
echo '<li>';
echo '<a href="' . helper::baseUrl() . 'translate/language/' . $key . '/' . $this->getData(['config','translate',$key]) . '"><img ' . $select . ' class="flag" src="' . helper::baseUrl(false) . 'core/vendor/i18n/png/' . $key . '.png" /></a>';
echo '<a href="' . helper::baseUrl() . 'translate/language/' . $key . '/' . $this->getData(['config', 'i18n',$key]) . '"><img ' . $select . ' class="flag" src="' . helper::baseUrl(false) . 'core/vendor/i18n/png/' . $key . '.png" /></a>';
echo '</li>';
}
}

View File

@ -51,6 +51,21 @@
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Langues étrangères</h4>
<div class="row">
<div class="col12">
<?php echo template::checkbox('configI18n', true, 'Activer la gestion des langues étrangères', [
'checked' => $this->getData(['config', 'i18n', 'enabled']),
'help'=> 'Une nouvelle icône apparaîtra dans la barre d\'administration. Consultez l\'aide de la page concernée pour en apprendre plus.'
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
@ -120,22 +135,7 @@
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Langues étrangères</h4>
<div class="row">
<div class="col12">
<?php echo template::checkbox('configI18n', true, 'Activer la gestion des langues étrangères', [
'checked' => $this->getData(['config', 'i18n', 'enabled']),
'help'=> 'Une nouvelle icône apparaîtra dans la barre d\'administration. Consultez l\'aide de la page concernée pour en apprendre plus.'
]); ?>
</div>
</div>
</div>
<p>Lorsque les langues étrangères sont activées, il convient d'adapter les pages spéciales.</p>
</div>
</div>
</div>

View File

@ -98,19 +98,6 @@ class init extends common {
],
'module' => [],
'user' => [],
'translate' => [
'scriptGoogle' => false,
'showCredits' => false,
'autoDetect' => false,
'admin' => false,
'fr' => 'none',
'de' => 'none',
'en' => 'none',
'es' => 'none',
'it' => 'none',
'nl' => 'none',
'pt' => 'none'
],
'theme' => [
'body' => [
'backgroundColor' => 'rgba(236, 239, 241, 1)',

View File

@ -52,7 +52,7 @@ class translate extends common {
$success = (copy (self::DATA_DIR . $copyFrom . '/page.json', self::DATA_DIR . $toCreate . '/page.json') === true && $success === true) ? true : false;
// Enregistrer la langue
if ($success) {
$this->setData(['config', 'translate', $toCreate, 'site' ]);
$this->setData(['config', 'i18n', $toCreate, 'site' ]);
$notification = 'Données ' . self::$i18nList[$copyFrom] . ' copiées vers ' . self::$i18nList[$toCreate];
} else {
$notification = "Quelque chose n\'a pas fonctionné, vérifiez les permissions.";
@ -67,7 +67,7 @@ class translate extends common {
}
// Tableau des langues installées
foreach (self::$i18nList as $key => $value) {
if ($this->getData(['config','translate',$key]) === 'site') {
if ($this->getData(['config','i18n', $key]) === 'site') {
self::$languagesTarget[$key] = $value;
}
}
@ -132,7 +132,8 @@ class translate extends common {
}
}
// Enregistrement des données
$this->setData(['config','translate', [
$this->setData(['config','i18n', [
'enabled' => $this->getData(['config', 'i18n', 'enabled']),
'scriptGoogle' => $script,
'showCredits' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) ? $this->getInput('translateCredits', helper::FILTER_BOOLEAN) : false,
'autoDetect' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) ? $this->getInput('translateAutoDetect', helper::FILTER_BOOLEAN) : false,
@ -155,7 +156,7 @@ class translate extends common {
}
// Modification de option de suppression de la langue installée.
foreach (self::$i18nList as $key => $value) {
if ($this->getData(['config','translate',$key]) === 'site') {
if ($this->getData(['config','i18n',$key]) === 'site') {
self::$translateOptions [$key] = [
'none' => 'Drapeau masqué',
'script' => 'Traduction automatique',

View File

@ -8,10 +8,10 @@
'value' => 'Retour'
]); ?>
</div>
<div class="col2 offset6">
<div class="col3 offset5">
<?php echo template::button('configAdvancedButton', [
'href' => helper::baseUrl() . 'translate/advanced',
'value' => 'Avancée',
'value' => 'Gestion avancée',
'ico' => 'cog-alt',
]); ?>
</div>
@ -30,13 +30,13 @@
<div class="row">
<div class="col6">
<?php echo template::checkbox('translateScriptGoogle', true, 'Active le script de traduction automatique', [
'checked' => $this->getData(['config','translate', 'scriptGoogle']),
'checked' => $this->getData(['config','i18n', 'scriptGoogle']),
'help' => 'Le script Google Translate assure la traduction automatique du site.'
]); ?>
</div>
<div class="col6">
<?php echo template::checkbox('translateAutoDetect', true, 'Détection automatique de la langue du navigateur', [
'checked' => $this->getData(['config','translate', 'autoDetect']),
'checked' => $this->getData(['config','i18n', 'autoDetect']),
'class' => 'translateGoogleScriptOption',
'help' => 'Détecte la langue du navigateur, dans ce mode il n\'est pas nécessaire d\'afficher les drapeaux.'
]); ?>
@ -45,14 +45,14 @@
<div class="row">
<div class="col6">
<?php echo template::checkbox('translateCredits', true, 'Afficher les crédits du script Google', [
'checked' => $this->getData(['config','translate', 'showCredits']),
'checked' => $this->getData(['config','i18n', 'showCredits']),
'class' => 'translateGoogleScriptOption',
'help' => 'Option recommandée pour le respect du droit d\'auteur'
]); ?>
</div>
<div class="col6">
<?php echo template::checkbox('translateAdmin', true, 'Traduction en mode connecté', [
'checked' => $this->getData(['config','translate', 'admin']),
'checked' => $this->getData(['config','i18n', 'admin']),
'class' => 'translateGoogleScriptOption',
'help' => 'Traduit le site et l\'interface de ZwiiCMS quand un utilisateur est connecté'
]); ?>

View File

@ -19,7 +19,7 @@
class search extends common {
const VERSION = '2.0';
const VERSION = '2.1';
const REALNAME = 'Recherche';
const DELETE = true;
const UPDATE = '0.0';
@ -196,41 +196,42 @@ class search extends common {
// Traduction du mot clé si le script Google Trad est actif
// Le multi langue est sélectionné
if ( $this->getData(['config','translate','scriptGoogle']) === true
AND
// et la traduction de la langue courante est automatique
( isset($_COOKIE['googtrans'])
AND ( $this->getData(['config','translate', substr($_COOKIE['googtrans'],4,2)]) === 'script'
// Ou traduction automatique
OR $this->getData(['config','translate','autoDetect']) === true )
)
// Cas des pages d'administration
// Pas connecté
AND ( $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
// Ou connecté avec option active
OR ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getData(['config','translate','admin']) === true
if ($this->getData(['config', 'i18n', 'enabled']) === true) {
if ( $this->getData(['config','i18n','scriptGoogle']) === true
AND
// et la traduction de la langue courante est automatique
( isset($_COOKIE['googtrans'])
AND ( $this->getData(['config','i18n', substr($_COOKIE['googtrans'],4,2)]) === 'script'
// Ou traduction automatique
OR $this->getData(['config','i18n','autoDetect']) === true )
)
// Cas des pages d'administration
// Pas connecté
AND ( $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
// Ou connecté avec option active
OR ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getData(['config','i18n','admin']) === true
)
)
AND !isset($_COOKIE['ZWII_I18N_SITE'])
)
AND !isset($_COOKIE['ZWII_I18N_SITE'])
)
{
// Découper la chaîne
$f = str_getcsv($motclef, ' ');
// Supprimer les espaces et les guillemets
$f = str_replace(' ','',$f);
$f = str_replace('"','',$f);
// Lire le cookie GoogTrans et déterminer les langues cibles
$language['origin'] = substr($_COOKIE['googtrans'],4,2);
$language['target'] = substr($_COOKIE['googtrans'],1,2);
if ($language['target'] !== $language['origin']) {
foreach ($f as $key => $value) {
$e = $this->translate($language['origin'],$language['target'],$value);
$motclef = str_replace($value,$e,$motclef);
{
// Découper la chaîne
$f = str_getcsv($motclef, ' ');
// Supprimer les espaces et les guillemets
$f = str_replace(' ','',$f);
$f = str_replace('"','',$f);
// Lire le cookie GoogTrans et déterminer les langues cibles
$language['origin'] = substr($_COOKIE['googtrans'],4,2);
$language['target'] = substr($_COOKIE['googtrans'],1,2);
if ($language['target'] !== $language['origin']) {
foreach ($f as $key => $value) {
$e = $this->translate($language['origin'],$language['target'],$value);
$motclef = str_replace($value,$e,$motclef);
}
}
}
}
// Suppression des mots < 3 caractères et des articles > 2 caractères de la chaîne $motclef
$arraymotclef = explode(' ', $motclef);
$motclef = '';