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/de/locale.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)',
];
// Langue courante
public static $i18nCurrent = 'fr';
public static $i18nSite = 'fr';
public static $timezone;
private $url = '';
// Données de site
@ -191,9 +191,11 @@ class common {
$this->input['_COOKIE'] = $_COOKIE;
}
// Déterminer le dossier de langues
if (isset($_POST['ZWII_USER_I18N'])) {
self::$i18nCurrent = $_POST['ZWII_USER_I18N'];
// Déterminer la langue sélectionnée si traduction manuelle ('site')
if (isset($this->input['_COOKIE']['ZWII_I18N_SITE'])
) {
self::$i18nSite = $this->input['_COOKIE']['ZWII_I18N_SITE'];
setlocale (LC_TIME, self::$i18nSite . '_' . strtoupper (self::$i18nSite) );
}
// Instanciation de la classe des entrées / sorties
@ -202,7 +204,7 @@ class common {
// Constructeur JsonDB
$this->dataFiles[$keys] = new \Prowebcraft\JsonDb([
'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
// La langue d'installation par défaut est fr
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) {
$this->initData($stageId,self::$i18nCurrent);
$this->initData($stageId,self::$i18nSite);
common::$coreNotices [] = $stageId ;
}
}
@ -237,8 +239,8 @@ class common {
// Traduction du site avec le script Google
if ( $this->getData(['config','translate','scriptGoogle'])) {
// Lire la langue stockée dans le cookie (choix manuel)
if ( isset($_COOKIE['ZWII_USER_I18N']) ) {
$lan_cookie = $_COOKIE['ZWII_USER_I18N'];
if ( isset($_COOKIE['ZWII_I18N_SITE']) ) {
$lan_cookie = $_COOKIE['ZWII_I18N_SITE'];
}
// Lire la langue du navigateur
if ( $this->getData(['config','translate','autoDetect'])) {
@ -251,10 +253,6 @@ class common {
// Changer la locale
if ( $lan !== 'fr') {
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
if ($this->getData(['config','translate','scriptGoogle']) === true ) {
// 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 fonction est activée.
*/
if ( (
( $this->getData(['config','translate','scriptGoogle']) === true
AND substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) !== 'fr'
)
OR ( isset($_COOKIES['ZWII_USER_I18N'])
AND array_key_exists($_COOKIES['ZWII_USER_I18N'],$this->i18nList
AND $_COOKIES['ZWII_USER_I18N'] !== 'fr' )
OR ( isset($_COOKIES['ZWII_I18N_SITE'])
AND array_key_exists($_COOKIES['ZWII_I18N_SITE'],$this->i18nList
AND $_COOKIES['ZWII_I18N_SITE'] !== 'fr' )
)
)
AND $this->getData(['config','translate','showCredits']) === true
@ -3038,16 +3035,19 @@ class layout extends common {
* Affiche le cadre avec les drapeaux
*/
public function showi18n() {
if ( $this->getData(['config','translate','scriptGoogle']) === true ) {
echo '<div id="i18nContainer"><ul>';
foreach (self::$i18nList as $key => $value) {
if ($this->getData(['config','translate','script' . strtoupper($key)]) ) {
echo '<li>';
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>';
echo '</li>';
}
}
echo '</ul></div>';
echo '<div id="i18nContainer"><ul>';
foreach (self::$i18nList as $key => $value) {
if ($this->getData(['config','translate',$key]) === 'site'
OR (
$this->getData(['config','translate','scriptGoogle']) === true
AND $this->getData(['config','translate',$key]) === 'script'
)
) {
echo '<li>';
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 */
#i18nContainer {
z-index: 100;
position: relative ;
z-index: 18;
display: flex ;
float: right;
width: auto;
height: auto;
margin-top: -25px;
margin-top: 40px;
}
#i18nContainer ul {
@ -732,19 +732,10 @@ li .menuSideChild {
#i18nContainer img {
width: 80%;
}
#i18nContainer img {
margin: 2px;
}
/* Corps */
@media (min-width:768px) {
section {

View File

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

View File

@ -19,6 +19,12 @@ class translate extends common {
'index' => self::GROUP_MODERATOR,
'language' => self::GROUP_VISITOR
];
public static $typeTranslate = [
'none' => 'Masqué',
'script' => 'Automatique',
'site' => 'Rédigée'
];
/**
* Configuration
@ -27,17 +33,17 @@ class translate extends common {
// Soumission du formulaire
if($this->isPost()) {
// Edtion des langues
// Edition des langues
foreach (self::$i18nList as $keyi18n => $value) {
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
AND $this->getInput('translateSiteFlag' . strtoupper($keyi18n) , helper::FILTER_BOOLEAN) === false )
AND $this->getInput('translate' . strtoupper($keyi18n)) === 'none')
{
$this->removeDir( self::DATA_DIR . $keyi18n);
}
// 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
if (is_dir( self::DATA_DIR . $keyi18n ) === false ) {
@ -45,7 +51,7 @@ class translate extends common {
}
// Charger les modèles
require_once('core/module/install/ressource/defaultdata.php');
// Nouvelle instance des pages, module, locale
// Nouvelle instance page, module, locale
$files = ['page','module','locale'];
foreach ($files as $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,
'autoDetect' => $this->getInput('translateAutoDetect', helper::FILTER_BOOLEAN),
'admin' => $this->getInput('translateAdmin', helper::FILTER_BOOLEAN),
'scriptFR' => $this->getInput('translateScriptFlagFR', helper::FILTER_BOOLEAN),
'scriptDE' => $this->getInput('translateScriptFlagDE', helper::FILTER_BOOLEAN),
'scriptEN' => $this->getInput('translateScriptFlagEN', helper::FILTER_BOOLEAN),
'scriptES' => $this->getInput('translateScriptFlagES', helper::FILTER_BOOLEAN),
'scriptIT' => $this->getInput('translateScriptFlagIT', helper::FILTER_BOOLEAN),
'scriptNL' => $this->getInput('translateScriptFlagNL', helper::FILTER_BOOLEAN),
'scriptPT' => $this->getInput('translateScriptFlagPT', helper::FILTER_BOOLEAN),
'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)
'fr' => 'site',
'de' => $this->getInput('translateDE'),
'en' => $this->getInput('translateEN'),
'es' => $this->getInput('translateES'),
'it' => $this->getInput('translateIT'),
'nl' => $this->getInput('translateNL'),
'pt' => $this->getInput('translatePT')
]]);
// Valeurs en sortie
$this->addOutput([
@ -100,10 +99,13 @@ class translate extends common {
*/
public function language() {
// Transmettre le choix au noyau
setcookie('ZWII_USER_I18N', $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
// Valeurs en sortie sans post
setcookie('ZWII_I18N_SITE', $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
if ($this->getUrl(3) === 'script') {
setrawcookie("googtrans", '/fr/'. $this->getUrl(2), time() + 3600, helper::baseUrl());
}
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(3)
'redirect' => helper::baseUrl()
]);
}
}

View File

@ -15,105 +15,78 @@
<div class="row">
<div class="col12">
<div class="block">
<h4>Langues supportées</h4>
<h4>Traduction automatique</h4>
<div class="row">
<div class="col6">
<b>Traduction automatique :</b>
<div class="col12">
<?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'])
<?php echo template::checkbox('translateScriptGoogle', true, 'Active le script de traduction automatique', [
'checked' => $this->getData(['config','translate', 'scriptGoogle'])
]); ?>
</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 class="col6">
<b>Traduction rédigée :</b>
<div class="col12">
<?php echo template::checkbox('translateSiteFlagEN', true, 'Anglais', [
'checked' => $this->getData(['config', 'translate', 'siteEN'])
<?php echo template::checkbox('translateAutoDetect', true, 'Détection automatique de la langue', [
'checked' => $this->getData(['config','translate', 'autoDetect']),
'help' => 'Détecte la langue du navigateur.'
]); ?>
</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 class="col12">
<?php echo template::checkbox('translateSiteFlagDE', true, 'Allemand', [
'checked' => $this->getData(['config', 'translate', 'siteDE'])
]); ?>
</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 class="col6">
<?php echo template::checkbox('translateCredits', true, 'Afficher les crédits du script Google', [
'checked' => $this->getData(['config','translate', 'showCredits']),
'help' => 'Option vivement recommandée pour le respect du droit d\'auteur'
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Paramètres de traduction automatique</h4>
<div class="row">
<div class="col4">
<?php echo template::checkbox('translateScriptGoogle', true, 'Active le script de traduction automatique', [
'checked' => $this->getData(['config','translate', 'scriptGoogle'])
]); ?>
<div class="col12">
<div class="block">
<h4>Drapeaux des langues supportées</h4>
<div class="row">
<div class="col6">
<div class="col8 offset2">
<?php echo template::select('translateDE', $module::$typeTranslate, [
'label' => 'Allemand',
'selected' => $this->getData(['config', 'translate' , 'de'])
]); ?>
</div>
<div class="col4">
<?php echo template::checkbox('translateAdmin', true, 'Mode connexion', [
'checked' => $this->getData(['config','translate', 'admin']),
'help' => 'Traduction automatique du site et de l\'interface du CMS'
]); ?>
<div class="col8 offset2">
<?php echo template::select('translateEN', $module::$typeTranslate, [
'label' => 'Anglais',
'selected' => $this->getData(['config', 'translate' , 'en'])
]); ?>
</div>
<div class="col4">
<?php echo template::checkbox('translateCredits', true, 'Afficher les crédits du script Google', [
'checked' => $this->getData(['config','translate', 'showCredits']),
'help' => 'Option vivement recommandée pour le respect du droit d\'auteur'
<div class="col8 offset2">
<?php echo template::select('translateES', $module::$typeTranslate, [
'label' => 'Espagnol',
'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>