From 01b9f8c1035d348d8a3f49623f430251c6023967 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Fri, 4 Jun 2021 13:57:44 +0200 Subject: [PATCH] Gestion des langues --- core/module/translate/translate.php | 172 +++++++++++++++---- core/module/translate/view/copy/copy.css | 1 + core/module/translate/view/copy/copy.php | 34 ++++ core/module/translate/view/index/index.php | 186 +++++++++++---------- 4 files changed, 273 insertions(+), 120 deletions(-) create mode 100644 core/module/translate/view/copy/copy.css create mode 100644 core/module/translate/view/copy/copy.php diff --git a/core/module/translate/translate.php b/core/module/translate/translate.php index 35c75b2a..10026850 100644 --- a/core/module/translate/translate.php +++ b/core/module/translate/translate.php @@ -17,10 +17,77 @@ class translate extends common { public static $actions = [ /*'config' => self::GROUP_MODERATOR,*/ - 'index' => self::GROUP_MODERATOR, + 'index' => self::GROUP_ADMIN, + 'copy' => self::GROUP_ADMIN, 'language' => self::GROUP_VISITOR ]; + public static $translateOptions = []; + + // Liste des langues installées + public static $languagesInstalled = []; + // Liste des langues cibles + public static $languagesTarget = []; + // Activation du bouton de copie + public static $siteTranslate = true; + + /** + * Configuration avancée des langues + */ + public function copy() { + + // Soumission du formulaire + if ($this->isPost()) { + // Initialisation + $success = false; + $copyFrom = $this->getInput('translateFormCopySource'); + $toCreate = $this->getInput('translateFormCopyTarget'); + if ($copyFrom !== $toCreate) { + // Création du dossier + if (is_dir(self::DATA_DIR . $toCreate) === false ) { // Si le dossier est déjà créé + $success = mkdir (self::DATA_DIR . $toCreate); + } else { + $success = true; + } + // Copier les données par défaut avec gestion des erreurs + $success = (copy (self::DATA_DIR . $copyFrom . '/locale.json', self::DATA_DIR . $toCreate . '/locale.json') === true && $success === true) ? true : false; + $success = (copy (self::DATA_DIR . $copyFrom . '/module.json', self::DATA_DIR . $toCreate . '/module.json') === true && $success === true) ? true : false; + $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', '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."; + } + } else { + $success = false; + $notification = 'Les langues doivent être différentes.'; + } + // Valeurs en sortie + $this->addOutput([ + 'notification' => $notification, + 'title' => 'Utilitaire de copie', + 'view' => 'index', + 'state' => $success + ]); + } + // Tableau des langues installées + foreach (self::$i18nList as $key => $value) { + if ($this->getData(['config','i18n', $key]) === 'site') { + self::$languagesTarget[$key] = $value; + } + } + // Langues cibles fr en plus + self::$languagesInstalled = array_merge(['fr' => 'Français (fr)'],self::$languagesTarget); + + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Utilitaire de copie', + 'view' => 'copy' + ]); + } + /** * Configuration */ @@ -28,19 +95,26 @@ class translate extends common { // Soumission du formulaire if($this->isPost()) { - // Edtion des langues + // Désactivation du script Google + if ($this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) === false) { + setrawcookie('googtrans', '/fr/fr', time() + 3600, helper::baseUrl(false,false)); + $_SESSION['googtrans'] = '/fr/fr'; + } + $script = $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN); + // 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)) === 'delete') { $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' + AND is_dir(self::DATA_DIR . $keyi18n) === false ) { - // Créer le dossier + // Créer les données absentes if (is_dir( self::DATA_DIR . $keyi18n ) === false ) { mkdir( self::DATA_DIR . $keyi18n); } @@ -58,29 +132,27 @@ class translate extends common { $e->save(); } } + // Active le script si une langue est en trad auto + if ($script === false + AND $this->getInput('translate'. strtoupper($keyi18n)) === 'script') { + $script = true; + } } - // Enregistrement des données $this->setData(['config','i18n', [ - 'scriptGoogle' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN), - '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) + '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, + 'admin' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) ? $this->getInput('translateAdmin', helper::FILTER_BOOLEAN) : false, + 'fr' => $this->getInput('translateFR'), + '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([ @@ -89,22 +161,54 @@ class translate extends common { 'state' => true ]); } + // Modification des options de suppression de la langue installée. + foreach (self::$i18nList as $key => $value) { + if ($this->getData(['config','i18n',$key]) === 'site') { + self::$translateOptions [$key] = [ + 'none' => 'Drapeau masqué', + 'script' => 'Traduction automatique', + 'site' => 'Traduction rédigée', + 'delete' => 'Supprimer la traduction' + ]; + self::$siteTranslate = $key !== 'fr' ? false : true; + } else { + self::$translateOptions [$key] = [ + 'none' => 'Drapeau masqué', + 'script' => 'Traduction automatique', + 'site' => 'Traduction rédigée' + ]; + } + } // Valeurs en sortie $this->addOutput([ - 'title' => 'Paramètres', + 'title' => 'Gestion des langues', 'view' => 'index' ]); } - /* - * Traitement du changement de langues - */ + + /* + * Traitement du changement de langue + * Fonction utilisée par le noyau + */ 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 + + // Activation du drapeau + if ( $this->getInput('ZWII_I18N_' . strtoupper($this->getUrl(3))) !== $this->getUrl(2) ) { + // Nettoyer et stocker le choix de l'utilisateur + helper::deleteCookie('ZWII_I18N_SITE'); + helper::deleteCookie('ZWII_I18N_SCRIPT'); + // Sélectionner + setcookie('ZWII_I18N_' . strtoupper($this->getUrl(3)) , $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true); + // Désactivation du drapeau, langue FR par défaut + } else { + setcookie('ZWII_I18N_SITE' , 'fr', time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true); + helper::deleteCookie('ZWII_I18N_SCRIPT'); + } + + // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(3) + 'redirect' => helper::baseUrl() ]); } } \ No newline at end of file diff --git a/core/module/translate/view/copy/copy.css b/core/module/translate/view/copy/copy.css new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/core/module/translate/view/copy/copy.css @@ -0,0 +1 @@ + diff --git a/core/module/translate/view/copy/copy.php b/core/module/translate/view/copy/copy.php new file mode 100644 index 00000000..4cb9e1fd --- /dev/null +++ b/core/module/translate/view/copy/copy.php @@ -0,0 +1,34 @@ + +
+
+ 'buttonGrey', + 'href' => helper::baseUrl() . 'translate', + 'ico' => 'left', + 'value' => 'Retour' + ]); ?> +
+
+ +
+
+
+
+
+

Copie de site (traductions rédigées)

+
+
+ 'Pages et les modules de' + ]); ?> +
+
+ 'Vers' + ]); ?> +
+
+
+
+
+ \ No newline at end of file diff --git a/core/module/translate/view/index/index.php b/core/module/translate/view/index/index.php index 0982bad0..8ba18662 100644 --- a/core/module/translate/view/index/index.php +++ b/core/module/translate/view/index/index.php @@ -8,112 +8,116 @@ 'value' => 'Retour' ]); ?> -
+
+ helper::baseUrl() . 'translate/copy', + 'value' => 'Utilitaire de copie', + 'ico' => 'cog-alt', + 'disabled' => $module::$siteTranslate + ]); ?> +
+
-

Langues supportées

+

Traduction automatique + + + +

- Traduction automatique : -
- $this->getData(['config','i18n', 'scriptDE']) - ]); ?> -
-
- $this->getData(['config','i18n', 'scriptEN']) + $this->getData(['config','i18n', 'scriptGoogle']), + 'help' => 'Le script Google Translate assure la traduction automatique du site.' ]); ?> -
-
- $this->getData(['config','i18n', 'scriptES']) - ]); ?> -
-
- $this->getData(['config','i18n', 'scriptIT']) - ]); ?> -
-
- $this->getData(['config','i18n', 'scriptNL']) - ]); ?> -
-
- $this->getData(['config','i18n', 'scriptPT']) - ]); ?> -
-
- $this->getData(['config','i18n', 'autoDetect']), - 'help' => 'Détecte la langue du navigateur.' - ]); ?> - -
- Traduction rédigée : -
- $this->getData(['config', 'i18n', 'siteEN']) + $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.' + ]); ?> +
+
+
+
+ $this->getData(['config','i18n', 'showCredits']), + 'class' => 'translateGoogleScriptOption', + 'help' => 'Option recommandée pour le respect du droit d\'auteur' + ]); ?> +
+
+ $this->getData(['config','i18n', 'admin']), + 'class' => 'translateGoogleScriptOption', + 'help' => 'Traduit le site et l\'interface de ZwiiCMS quand un utilisateur est connecté' ]); ?> -
-
- $this->getData(['config', 'i18n', 'siteDE']) - ]); ?> -
-
- $this->getData(['config', 'i18n', 'siteES']) - ]); ?> -
-
- $this->getData(['config', 'i18n', 'siteIT']) - ]); ?> -
-
- $this->getData(['config', 'i18n', 'siteNL']) - ]); ?> -
-
- $this->getData(['config', 'i18n', 'sitePT']) - ]); ?> -
-
-
-

Paramètres de traduction automatique

-
-
- $this->getData(['config','i18n', 'scriptGoogle']) - ]); ?> +
+
+

Mode de traduction et affichage des drapeaux

+
+
+ 'Drapeau masqué','site'=>'Drapeau affiché'], [ + 'label' => 'Français', + 'selected' => $this->getData(['config', 'i18n' , 'fr']) + ]); ?> +
+
+
+
+
+ 'Allemand', + 'class' => 'translateFlagSelect', + 'selected' => $this->getData(['config', 'i18n' , 'de']) + ]); ?>
-
- $this->getData(['config','i18n', 'admin']), - 'help' => 'Traduction automatique du site et de l\'interface du CMS' - ]); ?> +
+ 'Anglais', + 'class' => 'translateFlagSelect', + 'selected' => $this->getData(['config', 'i18n' , 'en']) + ]); ?>
-
- $this->getData(['config','i18n', 'showCredits']), - 'help' => 'Option vivement recommandée pour le respect du droit d\'auteur' +
+ 'Espagnol', + 'class' => 'translateFlagSelect', + 'selected' => $this->getData(['config', 'i18n' , 'es']) + ]); ?> +
+
+
+
+ 'Italien', + 'class' => 'translateFlagSelect', + 'selected' => $this->getData(['config', 'i18n' , 'it']) + ]); ?> +
+
+ 'Néerlandais', + 'class' => 'translateFlagSelect', + 'selected' => $this->getData(['config', 'i18n' , 'nl']) + ]); ?> +
+
+ 'Portugais', + 'class' => 'translateFlagSelect', + 'selected' => $this->getData(['config', 'i18n' , 'pt']) ]); ?>
@@ -121,4 +125,14 @@
+ +
+

Vous avez le choix entre une traduction automatique réalisée avec le script Google Traduction ou une traduction rédigée. La traduction automatique offre deux possibilités, la détection automatique de la langue du navigateur même celle-ci n'est pas + matérialisée par un drapeau. Le clic sur un drapeau forcera la traduction dans cette langue, pour cela sélectionnez le drapeau puis l'option de "Traduction automatique". + La traduction automatique est réalisée à partir du site en version française.

+

Avec l'option "Traduction rédigée", une nouveau sité est généré, seule la page d'accueil est crée, il faut alors rédiger les pages dans la langue sélectionnée. + Il est possible de copier les pages et les modules d'une langue vers une autre à l'aide de l'utilitaire de copie. + Quand un drapeau est masqué, la traduction est effacée, pensez à sauvegarder. + Afficher le drapeau français pour revenir à la traduction dans la langue originale.

+
\ No newline at end of file