traduction manuelle ok

This commit is contained in:
fredtempez 2020-11-25 18:25:16 +01:00
parent fee358a385
commit 1828d9c7a3
6 changed files with 123 additions and 152 deletions

8
.gitignore vendored
View File

@ -44,4 +44,10 @@ site/data/en/module.json
site/data/en/page.json site/data/en/page.json
site/data/de/locale.json site/data/de/locale.json
site/data/de/module.json site/data/de/module.json
site/data/de/page.json site/data/de/page.json
site/data/it/locale.json
site/data/it/module.json
site/data/it/page.json
site/data/nl/locale.json
site/data/nl/module.json
site/data/nl/page.json

View File

@ -152,7 +152,7 @@ class common {
'pt' => 'Portugais (pt)', 'pt' => 'Portugais (pt)',
]; ];
// Langue courante // Langue courante
public static $i18nCurrent = 'fr'; public static $i18nSite = 'fr';
public static $timezone; public static $timezone;
private $url = ''; private $url = '';
// Données de site // Données de site
@ -191,9 +191,11 @@ class common {
$this->input['_COOKIE'] = $_COOKIE; $this->input['_COOKIE'] = $_COOKIE;
} }
// Déterminer le dossier de langues // Déterminer la langue sélectionnée si traduction manuelle ('site')
if (isset($_POST['ZWII_USER_I18N'])) { if (isset($this->input['_COOKIE']['ZWII_I18N_SITE'])
self::$i18nCurrent = $_POST['ZWII_USER_I18N']; ) {
self::$i18nSite = $this->input['_COOKIE']['ZWII_I18N_SITE'];
setlocale (LC_TIME, self::$i18nSite . '_' . strtoupper (self::$i18nSite) );
} }
// Instanciation de la classe des entrées / sorties // Instanciation de la classe des entrées / sorties
@ -202,7 +204,7 @@ class common {
// Constructeur JsonDB // Constructeur JsonDB
$this->dataFiles[$keys] = new \Prowebcraft\JsonDb([ $this->dataFiles[$keys] = new \Prowebcraft\JsonDb([
'name' => $keys . '.json', 'name' => $keys . '.json',
'dir' => $this->dirData ($keys,self::$i18nCurrent) 'dir' => $this->dirData ($keys,self::$i18nSite)
]);; ]);;
} }
@ -222,9 +224,9 @@ class common {
// Installation fraîche, initialisation des modules manquants // Installation fraîche, initialisation des modules manquants
// La langue d'installation par défaut est fr // La langue d'installation par défaut est fr
foreach ($this->dataFiles as $stageId => $item) { foreach ($this->dataFiles as $stageId => $item) {
$folder = $this->dirData ($stageId, self::$i18nCurrent); $folder = $this->dirData ($stageId, self::$i18nSite);
if (file_exists($folder . $stageId .'.json') === false) { if (file_exists($folder . $stageId .'.json') === false) {
$this->initData($stageId,self::$i18nCurrent); $this->initData($stageId,self::$i18nSite);
common::$coreNotices [] = $stageId ; common::$coreNotices [] = $stageId ;
} }
} }
@ -237,8 +239,8 @@ class common {
// Traduction du site avec le script Google // Traduction du site avec le script Google
if ( $this->getData(['config','translate','scriptGoogle'])) { if ( $this->getData(['config','translate','scriptGoogle'])) {
// Lire la langue stockée dans le cookie (choix manuel) // Lire la langue stockée dans le cookie (choix manuel)
if ( isset($_COOKIE['ZWII_USER_I18N']) ) { if ( isset($_COOKIE['ZWII_I18N_SITE']) ) {
$lan_cookie = $_COOKIE['ZWII_USER_I18N']; $lan_cookie = $_COOKIE['ZWII_I18N_SITE'];
} }
// Lire la langue du navigateur // Lire la langue du navigateur
if ( $this->getData(['config','translate','autoDetect'])) { if ( $this->getData(['config','translate','autoDetect'])) {
@ -251,10 +253,6 @@ class common {
// Changer la locale // Changer la locale
if ( $lan !== 'fr') { if ( $lan !== 'fr') {
setlocale (LC_TIME, $lan . '_' . strtoupper ($lan) ); setlocale (LC_TIME, $lan . '_' . strtoupper ($lan) );
// Charge la librairie Google Translate
setrawcookie("googtrans", '/fr/'. $lan, time() + 3600, helper::baseUrl());
} else {
setrawcookie("googtrans", '/fr/fr', time() + 3600, helper::baseUrl());
} }
} }
@ -2183,7 +2181,7 @@ class core extends common {
} }
} }
// Chargement de la librairie googtrans // Chargement de la bibliothèque googtrans
// Le multi langue est actif // Le multi langue est actif
if ($this->getData(['config','translate','scriptGoogle']) === true ) { if ($this->getData(['config','translate','scriptGoogle']) === true ) {
// la traduction auto est active // la traduction auto est active
@ -2338,14 +2336,13 @@ class layout extends common {
* La traduction est active et le site n'est pas en français. * La traduction est active et le site n'est pas en français.
* La fonction est activée. * La fonction est activée.
*/ */
if ( ( if ( (
( $this->getData(['config','translate','scriptGoogle']) === true ( $this->getData(['config','translate','scriptGoogle']) === true
AND substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) !== 'fr' AND substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) !== 'fr'
) )
OR ( isset($_COOKIES['ZWII_USER_I18N']) OR ( isset($_COOKIES['ZWII_I18N_SITE'])
AND array_key_exists($_COOKIES['ZWII_USER_I18N'],$this->i18nList AND array_key_exists($_COOKIES['ZWII_I18N_SITE'],$this->i18nList
AND $_COOKIES['ZWII_USER_I18N'] !== 'fr' ) AND $_COOKIES['ZWII_I18N_SITE'] !== 'fr' )
) )
) )
AND $this->getData(['config','translate','showCredits']) === true AND $this->getData(['config','translate','showCredits']) === true
@ -3038,16 +3035,19 @@ class layout extends common {
* Affiche le cadre avec les drapeaux * Affiche le cadre avec les drapeaux
*/ */
public function showi18n() { public function showi18n() {
if ( $this->getData(['config','translate','scriptGoogle']) === true ) { echo '<div id="i18nContainer"><ul>';
echo '<div id="i18nContainer"><ul>'; foreach (self::$i18nList as $key => $value) {
foreach (self::$i18nList as $key => $value) { if ($this->getData(['config','translate',$key]) === 'site'
if ($this->getData(['config','translate','script' . strtoupper($key)]) ) { OR (
echo '<li>'; $this->getData(['config','translate','scriptGoogle']) === true
echo '<a href="' . helper::baseUrl() . 'translate/language/' . $key . '/' . $this->getUrl(0) . '"><img class= "flag" src="' . helper::baseUrl(false) . 'core/vendor/i18n/png/' . $key . '.png" /></a>'; AND $this->getData(['config','translate',$key]) === 'script'
echo '</li>'; )
} ) {
} echo '<li>';
echo '</ul></div>'; echo '<a href="' . helper::baseUrl() . 'translate/language/' . $key . '/' . $this->getData(['config','translate',$key]) . '/' . $this->getUrl(0) . '"><img class= "flag" src="' . helper::baseUrl(false) . 'core/vendor/i18n/png/' . $key . '.png" /></a>';
echo '</li>';
}
} }
echo '</ul></div>';
} }
} }

View File

@ -713,12 +713,12 @@ li .menuSideChild {
/* Container des drapeaux */ /* Container des drapeaux */
#i18nContainer { #i18nContainer {
z-index: 100; z-index: 18;
position: relative ; display: flex ;
float: right; float: right;
width: auto; width: auto;
height: auto; height: auto;
margin-top: -25px; margin-top: 40px;
} }
#i18nContainer ul { #i18nContainer ul {
@ -732,19 +732,10 @@ li .menuSideChild {
#i18nContainer img { #i18nContainer img {
width: 80%; width: 80%;
}
#i18nContainer img {
margin: 2px; margin: 2px;
} }
/* Corps */ /* Corps */
@media (min-width:768px) { @media (min-width:768px) {
section { section {

View File

@ -30,6 +30,7 @@ $lan = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>
<?php if($this->getUser('group') > self::GROUP_MEMBER): ?> <?php if($this->getUser('group') > self::GROUP_MEMBER): ?>
<?php $layout->showBar(); ?> <?php $layout->showBar(); ?>
<?php endif;?> <?php endif;?>
<?php $layout->showi18n();?>
<?php $layout->showNotification(); ?> <?php $layout->showNotification(); ?>
<?php if($this->getData(['theme', 'menu', 'position']) === 'body-first' || $this->getData(['theme', 'menu', 'position']) === 'top' ): ?> <?php if($this->getData(['theme', 'menu', 'position']) === 'body-first' || $this->getData(['theme', 'menu', 'position']) === 'top' ): ?>
<!-- Menu dans le fond du site avant la bannière --> <!-- Menu dans le fond du site avant la bannière -->
@ -37,7 +38,7 @@ $lan = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>
<?php <?php
if ( $this->getData(['theme', 'menu', 'position']) === 'top' if ( $this->getData(['theme', 'menu', 'position']) === 'top'
AND $this->getData(['theme', 'menu', 'fixed']) === true AND $this->getData(['theme', 'menu', 'fixed']) === true
AND $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD',true) AND $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD',true)
AND $this->getUser('group') > self::GROUP_MEMBER) { AND $this->getUser('group') > self::GROUP_MEMBER) {
echo '<nav id="navfixedconnected" >'; echo '<nav id="navfixedconnected" >';
} else { } else {
@ -60,7 +61,6 @@ $lan = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>
<?php if($this->getData(['theme', 'header', 'position']) === 'body'): ?> <?php if($this->getData(['theme', 'header', 'position']) === 'body'): ?>
<!-- Bannière dans le fond du site --> <!-- Bannière dans le fond du site -->
<header> <header>
<?php $layout->showi18n();?>
<?php <?php
if ($this->getData(['theme','header','linkHomePage'])){ if ($this->getData(['theme','header','linkHomePage'])){
echo "<a href='" . helper::baseUrl(false) . "'>" ;} ?> echo "<a href='" . helper::baseUrl(false) . "'>" ;} ?>
@ -154,7 +154,6 @@ $lan = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>
<?php endif; ?> <?php endif; ?>
<!-- Corps de page --> <!-- Corps de page -->
<section> <section>
<?php $layout->showi18n();?>
<?php <?php
// Gabarit : // Gabarit :
// Récupérer la config de la page courante // Récupérer la config de la page courante

View File

@ -19,6 +19,12 @@ class translate extends common {
'index' => self::GROUP_MODERATOR, 'index' => self::GROUP_MODERATOR,
'language' => self::GROUP_VISITOR 'language' => self::GROUP_VISITOR
]; ];
public static $typeTranslate = [
'none' => 'Masqué',
'script' => 'Automatique',
'site' => 'Rédigée'
];
/** /**
* Configuration * Configuration
@ -27,17 +33,17 @@ class translate extends common {
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if($this->isPost()) {
// Edtion des langues // Edition des langues
foreach (self::$i18nList as $keyi18n => $value) { foreach (self::$i18nList as $keyi18n => $value) {
if ($keyi18n === 'fr') {continue;} if ($keyi18n === 'fr') {continue;}
// Effacement d'une langue installée (dossier plus option désactivée précédemment) // Effacement d'une langue installée
if ( is_dir( self::DATA_DIR . $keyi18n ) === true if ( is_dir( self::DATA_DIR . $keyi18n ) === true
AND $this->getInput('translateSiteFlag' . strtoupper($keyi18n) , helper::FILTER_BOOLEAN) === false ) AND $this->getInput('translate' . strtoupper($keyi18n)) === 'none')
{ {
$this->removeDir( self::DATA_DIR . $keyi18n); $this->removeDir( self::DATA_DIR . $keyi18n);
} }
// Installation d'une langue // Installation d'une langue
if ( $this->getInput('translateSiteFlag' . strtoupper($keyi18n) , helper::FILTER_BOOLEAN) === true ) if ( $this->getInput('translate' . strtoupper($keyi18n)) === 'site')
{ {
// Créer le dossier // Créer le dossier
if (is_dir( self::DATA_DIR . $keyi18n ) === false ) { if (is_dir( self::DATA_DIR . $keyi18n ) === false ) {
@ -45,7 +51,7 @@ class translate extends common {
} }
// Charger les modèles // Charger les modèles
require_once('core/module/install/ressource/defaultdata.php'); require_once('core/module/install/ressource/defaultdata.php');
// Nouvelle instance des pages, module, locale // Nouvelle instance page, module, locale
$files = ['page','module','locale']; $files = ['page','module','locale'];
foreach ($files as $keyFile) { foreach ($files as $keyFile) {
echo $keyFile; echo $keyFile;
@ -65,21 +71,14 @@ class translate extends common {
'showCredits' => $this->getInput('translateCredits', helper::FILTER_BOOLEAN) ? $this->getInput('translateCredits', helper::FILTER_BOOLEAN) : false, 'showCredits' => $this->getInput('translateCredits', helper::FILTER_BOOLEAN) ? $this->getInput('translateCredits', helper::FILTER_BOOLEAN) : false,
'autoDetect' => $this->getInput('translateAutoDetect', helper::FILTER_BOOLEAN), 'autoDetect' => $this->getInput('translateAutoDetect', helper::FILTER_BOOLEAN),
'admin' => $this->getInput('translateAdmin', helper::FILTER_BOOLEAN), 'admin' => $this->getInput('translateAdmin', helper::FILTER_BOOLEAN),
'scriptFR' => $this->getInput('translateScriptFlagFR', helper::FILTER_BOOLEAN), 'fr' => 'site',
'scriptDE' => $this->getInput('translateScriptFlagDE', helper::FILTER_BOOLEAN), 'de' => $this->getInput('translateDE'),
'scriptEN' => $this->getInput('translateScriptFlagEN', helper::FILTER_BOOLEAN), 'en' => $this->getInput('translateEN'),
'scriptES' => $this->getInput('translateScriptFlagES', helper::FILTER_BOOLEAN), 'es' => $this->getInput('translateES'),
'scriptIT' => $this->getInput('translateScriptFlagIT', helper::FILTER_BOOLEAN), 'it' => $this->getInput('translateIT'),
'scriptNL' => $this->getInput('translateScriptFlagNL', helper::FILTER_BOOLEAN), 'nl' => $this->getInput('translateNL'),
'scriptPT' => $this->getInput('translateScriptFlagPT', helper::FILTER_BOOLEAN), 'pt' => $this->getInput('translatePT')
'site' => $this->getInput('translateSite', helper::FILTER_BOOLEAN),
'siteFR' => $this->getInput('translateSiteFlagFR', helper::FILTER_BOOLEAN),
'siteDE' => $this->getInput('translateSiteFlagDE', helper::FILTER_BOOLEAN),
'siteEN' => $this->getInput('translateSiteFlagEN', helper::FILTER_BOOLEAN),
'siteES' => $this->getInput('translateSiteFlagES', helper::FILTER_BOOLEAN),
'siteIT' => $this->getInput('translateSiteFlagIT', helper::FILTER_BOOLEAN),
'siteNL' => $this->getInput('translateSiteFlagNL', helper::FILTER_BOOLEAN),
'sitePT' => $this->getInput('translateSiteFlagPT', helper::FILTER_BOOLEAN)
]]); ]]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -100,10 +99,13 @@ class translate extends common {
*/ */
public function language() { public function language() {
// Transmettre le choix au noyau // Transmettre le choix au noyau
setcookie('ZWII_USER_I18N', $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true); setcookie('ZWII_I18N_SITE', $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
// Valeurs en sortie sans post if ($this->getUrl(3) === 'script') {
setrawcookie("googtrans", '/fr/'. $this->getUrl(2), time() + 3600, helper::baseUrl());
}
// Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(3) 'redirect' => helper::baseUrl()
]); ]);
} }
} }

View File

@ -15,105 +15,78 @@
<div class="row"> <div class="row">
<div class="col12"> <div class="col12">
<div class="block"> <div class="block">
<h4>Langues supportées</h4> <h4>Traduction automatique</h4>
<div class="row"> <div class="row">
<div class="col6"> <div class="col6">
<b>Traduction automatique :</b> <?php echo template::checkbox('translateScriptGoogle', true, 'Active le script de traduction automatique', [
<div class="col12"> 'checked' => $this->getData(['config','translate', 'scriptGoogle'])
<?php echo template::checkbox('translateScriptFlagDE', true, 'Allemand', [
'checked' => $this->getData(['config','translate', 'scriptDE'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateScriptFlagEN', true, 'Anglais', [
'checked' => $this->getData(['config','translate', 'scriptEN'])
]); ?> ]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateScriptFlagES', true, 'Espagnol', [
'checked' => $this->getData(['config','translate', 'scriptES'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateScriptFlagIT', true, 'Italien', [
'checked' => $this->getData(['config','translate', 'scriptIT'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateScriptFlagNL', true, 'Néerlandais', [
'checked' => $this->getData(['config','translate', 'scriptNL'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateScriptFlagPT', true, 'Portugais', [
'checked' => $this->getData(['config','translate', 'scriptPT'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateAutoDetect', true, 'Détection automatique', [
'checked' => $this->getData(['config','translate', 'autoDetect']),
'help' => 'Détecte la langue du navigateur.'
]); ?>
</div>
</div> </div>
<div class="col6"> <div class="col6">
<b>Traduction rédigée :</b> <?php echo template::checkbox('translateAutoDetect', true, 'Détection automatique de la langue', [
<div class="col12"> 'checked' => $this->getData(['config','translate', 'autoDetect']),
<?php echo template::checkbox('translateSiteFlagEN', true, 'Anglais', [ 'help' => 'Détecte la langue du navigateur.'
'checked' => $this->getData(['config', 'translate', 'siteEN']) ]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::checkbox('translateAdmin', true, 'Traduction de l\'interface du CMS', [
'checked' => $this->getData(['config','translate', 'admin'])
]); ?> ]); ?>
</div> </div>
<div class="col12"> <div class="col6">
<?php echo template::checkbox('translateSiteFlagDE', true, 'Allemand', [ <?php echo template::checkbox('translateCredits', true, 'Afficher les crédits du script Google', [
'checked' => $this->getData(['config', 'translate', 'siteDE']) 'checked' => $this->getData(['config','translate', 'showCredits']),
]); ?> 'help' => 'Option vivement recommandée pour le respect du droit d\'auteur'
</div> ]); ?>
<div class="col12">
<?php echo template::checkbox('translateSiteFlagES', true, 'Espagnol', [
'checked' => $this->getData(['config', 'translate', 'siteES'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateSiteFlagIT', true, 'Italien', [
'checked' => $this->getData(['config', 'translate', 'siteIT'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateSiteFlagNL', true, 'Néerlandais', [
'checked' => $this->getData(['config', 'translate', 'siteNL'])
]); ?>
</div>
<div class="col12">
<?php echo template::checkbox('translateSiteFlagPT', true, 'Portugais', [
'checked' => $this->getData(['config', 'translate', 'sitePT'])
]); ?>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col12"> <div class="col12">
<div class="block"> <div class="block">
<h4>Paramètres de traduction automatique</h4> <h4>Drapeaux des langues supportées</h4>
<div class="row"> <div class="row">
<div class="col4"> <div class="col6">
<?php echo template::checkbox('translateScriptGoogle', true, 'Active le script de traduction automatique', [ <div class="col8 offset2">
'checked' => $this->getData(['config','translate', 'scriptGoogle']) <?php echo template::select('translateDE', $module::$typeTranslate, [
]); ?> 'label' => 'Allemand',
'selected' => $this->getData(['config', 'translate' , 'de'])
]); ?>
</div> </div>
<div class="col4"> <div class="col8 offset2">
<?php echo template::checkbox('translateAdmin', true, 'Mode connexion', [ <?php echo template::select('translateEN', $module::$typeTranslate, [
'checked' => $this->getData(['config','translate', 'admin']), 'label' => 'Anglais',
'help' => 'Traduction automatique du site et de l\'interface du CMS' 'selected' => $this->getData(['config', 'translate' , 'en'])
]); ?> ]); ?>
</div> </div>
<div class="col4"> <div class="col8 offset2">
<?php echo template::checkbox('translateCredits', true, 'Afficher les crédits du script Google', [ <?php echo template::select('translateES', $module::$typeTranslate, [
'checked' => $this->getData(['config','translate', 'showCredits']), 'label' => 'Espagnol',
'help' => 'Option vivement recommandée pour le respect du droit d\'auteur' 'selected' => $this->getData(['config', 'translate' , 'es'])
]); ?>
</div>
</div>
<div class="col6">
<div class="col8 offset2">
<?php echo template::select('translateIT', $module::$typeTranslate, [
'label' => 'Italien',
'selected' => $this->getData(['config', 'translate' , 'it'])
]); ?>
</div>
<div class="col8 offset2">
<?php echo template::select('translateNL', $module::$typeTranslate, [
'label' => 'Néerlandais',
'selected' => $this->getData(['config', 'translate' , 'nl'])
]); ?>
</div>
<div class="col8 offset2">
<?php echo template::select('translatePT', $module::$typeTranslate, [
'label' => 'Portugais',
'selected' => $this->getData(['config', 'translate' , 'pt'])
]); ?> ]); ?>
</div> </div>
</div> </div>