translate copy

This commit is contained in:
Deltacms 2024-01-17 09:07:05 +01:00
parent 041e774e31
commit eb6c240889
9 changed files with 175 additions and 14 deletions

View File

@ -522,7 +522,8 @@ class template {
'label' => '',
'name' => $nameId,
'selected' => '',
'fonts' => false
'fonts' => false,
'ksort' => true
], $attributes);
// Sauvegarde des données en cas d'erreur
if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) {
@ -548,7 +549,7 @@ class template {
$html .= sprintf('<select %s>',
helper::sprintAttributes($attributes)
);
ksort($options);
if( $attributes['ksort'] === true ) ksort($options);
foreach($options as $value => $text) {
$html .= $attributes['fonts'] === true ? sprintf(
'<option value="%s"%s style="font-family: %s;"> %s </option>',

View File

@ -6,6 +6,11 @@ $text['core_translate_view']['copy'][2] = 'Submit';
$text['core_translate_view']['copy'][3] = 'Site copy (written translations)';
$text['core_translate_view']['copy'][4] = 'Pages and modules of';
$text['core_translate_view']['copy'][5] = 'to';
$text['core_translate_view']['copy'][6] = 'All pages';
$text['core_translate_view']['copy'][7] = 'A page, subpage or bar';
$text['core_translate_view']['copy'][8] = 'Page type: title in menu (full title - identifier). Copying an existing page to the target folder overwrites this page, read help.';
$text['core_translate_view']['copy'][9] = 'Copy the bars associated with the page';
$text['core_translate_view']['copy'][10] = 'Copying the bars of a page is a delicate operation, read the help';
$text['core_translate_view']['index'][0] = 'Back';
$text['core_translate_view']['index'][1] = 'Help';
$text['core_translate_view']['index'][2] = 'Copy utility';
@ -22,6 +27,11 @@ $text['core_translate']['copy'][2] = 'Copy utility';
$text['core_translate']['copy'][3] = 'Data ';
$text['core_translate']['copy'][4] = ' copied to ';
$text['core_translate']['copy'][5] = 'Language of origin';
$text['core_translate']['copy'][7] = ' has been copied into the language site ';
$text['core_translate']['copy'][8] = 'Menu page: ';
$text['core_translate']['copy'][9] = 'Orphan page: ';
$text['core_translate']['copy'][10] = 'Subpage: ';
$text['core_translate']['copy'][11] = 'sidebar: ';
$text['core_translate']['index'][0] = 'Registered changes';
$text['core_translate']['index'][1] = 'Masked flag';
$text['core_translate']['index'][3] = 'Written translation';

View File

@ -6,6 +6,11 @@ $text['core_translate_view']['copy'][2] = 'Guardar';
$text['core_translate_view']['copy'][3] = 'Copia del sitio (traducciones redactadas)';
$text['core_translate_view']['copy'][4] = 'Páginas y módulos';
$text['core_translate_view']['copy'][5] = 'Para';
$text['core_translate_view']['copy'][6] = 'Todas las páginas';
$text['core_translate_view']['copy'][7] = 'Una página, subpágina o barra';
$text['core_translate_view']['copy'][8] = 'Tipo de página: título en el menú (título completo - identificador). Copiar una página existente a la carpeta de destino sobrescribe esta página, lea la ayuda.';
$text['core_translate_view']['copy'][9] = 'Copiar las barras asociadas con la página';
$text['core_translate_view']['copy'][10] = 'Copiar las barras de una página es una operación delicada, lea la ayuda';
$text['core_translate_view']['index'][0] = 'Atrás';
$text['core_translate_view']['index'][1] = 'Ayuda';
$text['core_translate_view']['index'][2] = 'Utilidad de copia';
@ -22,6 +27,11 @@ $text['core_translate']['copy'][2] = 'Utilidad de copia';
$text['core_translate']['copy'][3] = 'Datos';
$text['core_translate']['copy'][4] = ' copiado en ';
$text['core_translate']['copy'][5] = 'Idioma original';
$text['core_translate']['copy'][7] = ' se ha copiado en el sitio del idioma ';
$text['core_translate']['copy'][8] = 'Página de menú: ';
$text['core_translate']['copy'][9] = 'Página huérfana: ';
$text['core_translate']['copy'][10] = 'Subpágina: ';
$text['core_translate']['copy'][11] = 'barra lateral: ';
$text['core_translate']['index'][0] = 'Cambios guardados';
$text['core_translate']['index'][1] = 'Bandera oculta';
$text['core_translate']['index'][3] = 'Traducción escrita';

View File

@ -6,6 +6,13 @@ $text['core_translate_view']['copy'][2] = 'Enregistrer';
$text['core_translate_view']['copy'][3] = 'Copie de site (traductions rédigées)';
$text['core_translate_view']['copy'][4] = 'Pages et les modules de';
$text['core_translate_view']['copy'][5] = 'Vers';
$text['core_translate_view']['copy'][6] = 'Toutes les pages';
$text['core_translate_view']['copy'][7] = 'Une page, une sous-page ou une barre';
$text['core_translate_view']['copy'][8] = 'Type de page : titre dans le menu ( titre complet - identifiant). Copier une page existante dans le dossier cible écrase cette page, lire l\'aide.';
$text['core_translate_view']['copy'][9] = 'Copier les barres associées à la page';
$text['core_translate_view']['copy'][10] = 'Copier les barres d\'une page est une opération délicate, lire l\'aide';
$text['core_translate_view']['index'][0] = 'Retour';
$text['core_translate_view']['index'][1] = 'Aide';
$text['core_translate_view']['index'][2] = 'Utilitaire de copie';
@ -22,6 +29,14 @@ $text['core_translate']['copy'][2] = 'Utilitaire de copie';
$text['core_translate']['copy'][3] = 'Données ';
$text['core_translate']['copy'][4] = ' copiées vers ';
$text['core_translate']['copy'][5] = 'Langue d\'origine';
$text['core_translate']['copy'][7] = ' a été copiée dans le site en langue ';
$text['core_translate']['copy'][8] = 'Page du menu : ';
$text['core_translate']['copy'][9] = 'Page orpheline : ';
$text['core_translate']['copy'][10] = 'Sous-page : ';
$text['core_translate']['copy'][11] = 'barre latérale : ';
$text['core_translate']['index'][0] = 'Modifications enregistrées';
$text['core_translate']['index'][1] = 'Drapeau masqué';
$text['core_translate']['index'][3] = 'Traduction rédigée';

View File

@ -0,0 +1,3 @@
{
"module": []
}

View File

@ -0,0 +1,3 @@
{
"page": []
}

View File

@ -34,6 +34,8 @@ class translate extends common {
public static $languagesTarget = [];
// Activation du bouton de copie
public static $siteTranslate = true;
// Variable pour construire la liste des pages du site
public static $pagesList = [];
/**
* Configuration avancée des langues
@ -50,13 +52,24 @@ class translate extends common {
} else {
// Lexique
include('./core/module/translate/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_translate.php');
// Tableau des pages, sous-pages et barres
$pagesList = $this->getData(['page']);
foreach($pagesList as $page => $pageId) {
if ( $this->getData(['page',$page,'title']) === null ) unset($pagesList[$page]);
}
// Soumission du formulaire
if ($this->isPost()) {
// Initialisation
$success = false;
$copyFrom = $this->getInput('translateFormCopySource');
$toCreate = $this->getInput('translateFormCopyTarget');
// Tableau des langues installées
foreach ($i18nList as $key => $value) {
if ($this->getData(['config','i18n', $key]) === 'site') {
$tabLanguagesTarget[$key] = $value;
}
}
$langTarget = $tabLanguagesTarget[$toCreate];
if ($copyFrom !== $toCreate) {
// Création du dossier
if (is_dir(self::DATA_DIR . $toCreate) === false ) { // Si le dossier est déjà créé
@ -65,18 +78,63 @@ class translate extends common {
} 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;
$success = ($this->copyDir (self::DATA_DIR . $copyFrom . '/content', self::DATA_DIR . $toCreate . '/content') === true && $success === true) ? true : false;
// Enregistrer la langue
if ($success) {
$this->setData(['config', 'i18n', $toCreate, 'site' ]);
$i18nListBase = array_merge(['base' => $text['core_translate']['copy'][5] ],self::$i18nList);
$notification = $text['core_translate']['copy'][3] . $i18nListBase[$copyFrom] . $text['core_translate']['copy'][4] . self::$i18nList[$toCreate];
if( $this->getInput('translateCopyAllPages') === '1'){
// Copie de toutes les pages / 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;
$success = ($this->copyDir (self::DATA_DIR . $copyFrom . '/content', self::DATA_DIR . $toCreate . '/content') === true && $success === true) ? true : false;
// Enregistrer la langue
if ($success) {
$this->setData(['config', 'i18n', $toCreate, 'site' ]);
$i18nListBase = array_merge(['base' => $text['core_translate']['copy'][5] ],self::$i18nList);
$notification = $text['core_translate']['copy'][3] . $i18nListBase[$copyFrom] . $text['core_translate']['copy'][4] . self::$i18nList[$toCreate];
} else {
$notification = $text['core_translate']['copy'][0];
}
} else {
$notification = $text['core_translate']['copy'][0];
// Copie d'une seule page / Récupération de son id et du choix pour les barres
$pageId = $this->getInput('translateCopyPage');
$copyBarAuto = $this->getInput('translateCopyBarAuto');
// Si le dossier langue (es, en, de...) ne contient pas le fichier page.json l'initialiser avec module vide, page vide, locale de la langue d'origine
if( !file_exists( self::DATA_DIR . $toCreate . '/page.json')){
$success = (copy (self::DATA_DIR . $copyFrom . '/locale.json', self::DATA_DIR . $toCreate . '/locale.json') === true && $success === true) ? true : false;
$success = (copy ('core/module/translate/ressource/module.json', self::DATA_DIR . $toCreate . '/module.json') === true && $success === true) ? true : false;
$success = (copy ('core/module/translate/ressource/page.json', self::DATA_DIR . $toCreate . '/page.json') === true && $success === true) ? true : false;
}
// Si une page de même nom existe déjà elle sera écrasée
// Si une page est de nom différent mais de position identique, elle sera ajoutée au menu dans le bon ordre
// Ajouter les entrées $pageId dans page, module si existant et dans content
$pageAdd = $this->getData(['page',$pageId]);
$moduleAdd = $this->getData(['module',$pageId]);
$jsonPage = file_get_contents(self::DATA_DIR . $toCreate . '/page.json');
$jsonModule = file_get_contents(self::DATA_DIR . $toCreate . '/module.json');
// Ajout des données dans page.json
$fp= json_decode($jsonPage, true);
$fp['page'] = array_merge($fp['page'], array($pageId => $pageAdd));
// Si c'est une sous-page lire la valeur de parentPageId dans la langues d'origine et si il n'y a pas de page parent de même nom dans la langue cible positionner parentPageId à ""
if( ! array_key_exists( $this->getData(['page', $pageId, 'parentPageId']), $fp['page'])) $fp['page'][$pageId]['parentPageId'] = "";
// Si la page ou la sous-page possède 1 ou 2 barres les copier automatiquement si c'est autorisé, et copier leur contenu
if( $copyBarAuto === '1' && ($this->getData(['page', $pageId, 'barLeft']) !== '' || $this->getData(['page', $pageId, 'barRight']) !== '')){
$nameBar = $this->getData(['page', $pageId, 'barLeft']) !== '' ? $this->getData(['page', $pageId, 'barLeft']) : $this->getData(['page', $pageId, 'barRight']);
$fp['page'] = array_merge($fp['page'], array( $nameBar => $this->getData(['page',$nameBar]) ));
$success = (copy (self::DATA_DIR . $copyFrom . '/content/'.$nameBar.'.html', self::DATA_DIR . $toCreate . '/content/'.$nameBar.'.html') === true && $success === true) ? true : false;
}
$jsonmod = json_encode($fp);
file_put_contents(self::DATA_DIR . $toCreate . '/page.json',$jsonmod);
// Ajout des données dans module.json
if( $moduleAdd !== NULL && $moduleAdd !==''){
$fp= json_decode($jsonModule, true);
$fp['module'] = array_merge($fp['module'], array($pageId => $moduleAdd));
$jsonmod = json_encode($fp);
file_put_contents(self::DATA_DIR . $toCreate . '/module.json',$jsonmod);
}
// Ajout des données dans content
$success = (copy (self::DATA_DIR . $copyFrom . '/content/'.$pageId.'.html', self::DATA_DIR . $toCreate . '/content/'.$pageId.'.html') === true && $success === true) ? true : false;
// Notification du titre court de la page copiée
$notification = $this->getData(['page',$pageId,'shortTitle']).$text['core_translate']['copy'][7]. $langTarget;
}
} else {
$success = false;
@ -90,6 +148,32 @@ class translate extends common {
'state' => $success
]);
}
// Classement pages, sous-pages, pages orphelines, barres
foreach($pagesList as $page => $pageId) {
if ( $this->getData(['page',$page,'parentPageId']) === '' ) $pagesList[$page][$type] = 'page';
if ( $this->getData(['page',$page,'parentPageId']) !== '' ) $pagesList[$page][$type] = 'sous-page';
if ( $this->getData(['page',$page,'position']) === 0 ) $pagesList[$page][$type] = 'page orpheline';
if ( $this->getData(['page',$page,'block']) === 'bar' ) $pagesList[$page][$type] = 'barre';
}
//Affichage des pages et mémorisation dans le tableau de sortie self::$pagesList
// Type de page : titre court ( titre - identifiant )
foreach($pagesList as $page => $pageId) {
switch ($pagesList[$page][$type]){
case 'page' :
self::$pagesList[$page]= $text['core_translate']['copy'][8].$this->getData(['page',$page,'shortTitle']).' ( '. $this->getData(['page',$page,'title']).' - '.$page.' )';
break;
case 'sous-page' :
self::$pagesList[$page]= $text['core_translate']['copy'][10].$this->getData(['page',$page,'shortTitle']).' ( '. $this->getData(['page',$page,'title']).' - '.$page.' )';
break;
case 'page orpheline' :
self::$pagesList[$page]= $text['core_translate']['copy'][9]. $this->getData(['page',$page,'shortTitle']).' ( '. $this->getData(['page',$page,'title']).' - '.$page.' )';
break;
case 'barre' :
self::$pagesList[$page]= $text['core_translate']['copy'][11].$this->getData(['page',$page,'shortTitle']).' ( '. $this->getData(['page',$page,'title']).' - '.$page.' )';
break;
}
}
// Tableau des langues installées
foreach ($i18nList as $key => $value) {
if ($this->getData(['config','i18n', $key]) === 'site') {

View File

@ -0,0 +1,11 @@
/**
* Affiche/cache la liste des pages
*/
$('#translateCopyAllPages').on("change", function() {
if($(this).is(":checked")) {
$(".pagesList").css("display","none");
}
else {
$(".pagesList").css("display","");
}
}).trigger("change");

View File

@ -41,8 +41,32 @@ include('./core/module/translate/lang/'. $this->getData(['config', 'i18n', 'lang
'label' => $text['core_translate_view']['copy'][5]
]); ?>
</div>
</div>
<div class="row">
<div class="col3">
<?php echo template::checkbox('translateCopyAllPages', true, $text['core_translate_view']['copy'][6], [
'checked' => ''
]); ?>
</div>
<div class="col4 pagesList">
<?php
asort($module::$pagesList);
echo template::select('translateCopyPage', $module::$pagesList, [
'label' => $text['core_translate_view']['copy'][7],
'selected' => '',
'help' => $text['core_translate_view']['copy'][8],
'ksort' => false
]); ?>
</div>
<div class="col4 offset1 pagesList">
<?php echo template::checkbox('translateCopyBarAuto', true, $text['core_translate_view']['copy'][9], [
'checked' => '',
'help' => $text['core_translate_view']['copy'][10]
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>