From ac69ae589e19d7423ef43c3880522d7c9adc6209 Mon Sep 17 00:00:00 2001 From: "kent1@arscenic.info" <> Date: Fri, 6 May 2016 13:31:54 +0000 Subject: [PATCH] PSR SPIP --- export_lang/csv.php | 47 ++++++++--------- export_lang/po.php | 120 ++++++++++++++++++++++--------------------- export_lang/spip.php | 77 +++++++++++++++------------ 3 files changed, 128 insertions(+), 116 deletions(-) diff --git a/export_lang/csv.php b/export_lang/csv.php index 5555ca3..f575af4 100644 --- a/export_lang/csv.php +++ b/export_lang/csv.php @@ -1,65 +1,63 @@ <?php /** - * + * * Trad-lang v2 * Plugin SPIP de traduction de fichiers de langue * © Florent Jugla, Fil, kent1 - * + * * Fichier d'export d'un module de langue en .csv */ - + if (!defined('_ECRIRE_INC_VERSION')) { return; } /** * Fonction d'export d'une langue d'un module en .csv - * - * @param string $module + * + * @param string $module * Le module à exporter (le champ "module" dans la base) - * @param string $langue + * @param string $langue * La langue à exporter - * @param string $dir_lang + * @param string $dir_lang * Le répertoire où stocker les fichiers de langue - * @return string $fichier + * @return string $fichier * Le fichier final */ -function export_lang_csv_dist($module,$langue,$dir_lang){ +function export_lang_csv_dist($module, $langue, $dir_lang) { $chaines_csv=$tous=array(); - + /** * Le fichier final * local/cache-lang/module_lang.csv */ - $fichier = $dir_lang."/".$module."_".$langue.".csv"; + $fichier = $dir_lang . '/' . $module . '_' . $langue . '.csv'; /** * Les informations du module - */ - $info_module = sql_fetsel('id_tradlang_module,lang_mere,nom_mod','spip_tradlang_modules','module='.sql_quote($module)); + */ + $info_module = sql_fetsel('id_tradlang_module,lang_mere,nom_mod', 'spip_tradlang_modules', 'module = ' . sql_quote($module)); /** * Les chaines */ - $res=sql_allfetsel("id,str,statut,comm","spip_tradlangs","id_tradlang_module=".intval($info_module['id_tradlang_module'])." AND lang=".sql_quote($langue)." AND statut != 'attic'","id"); - foreach($res as $row){ + $res = sql_allfetsel('id,str,statut,comm', 'spip_tradlangs', 'id_tradlang_module = ' . intval($info_module['id_tradlang_module']) . ' AND lang=' . sql_quote($langue) . ' AND statut != "attic"', 'id'); + foreach ($res as $row) { $tous[$row['id']] = $row; } ksort($tous); - + foreach ($tous as $id => $row) { $str = $row['str']; $oldmd5 = md5($str); - $str = str_replace("\r\n", "\n", unicode_to_utf_8( - html_entity_decode( - preg_replace('/&([lg]t;)/S', '&\1', $str), - ENT_NOQUOTES, 'utf-8') - )); + $str = str_replace("\r\n", "\n", unicode_to_utf_8(html_entity_decode(preg_replace('/&([lg]t;)/S', '&\1', $str), ENT_NOQUOTES, 'utf-8'))); $newmd5 = md5($str); - if ($oldmd5 !== $newmd5) sql_updateq("spip_tradlangs",array('md5'=>$newmd5), "md5=".sql_quote($oldmd5)." AND id_tradlang_module=".intval($info_module['id_tradlang_module'])); - $str_original = sql_getfetsel('str','spip_tradlangs','id ='.sql_quote($id).' AND id_tradlang_module='.intval($info_module['id_tradlang_module']).' AND lang='.sql_quote($info_module['lang_mere'])); + if ($oldmd5 !== $newmd5) { + sql_updateq('spip_tradlangs', array('md5'=>$newmd5), 'md5 = '.sql_quote($oldmd5) . ' AND id_tradlang_module = ' . intval($info_module['id_tradlang_module'])); + } + $str_original = sql_getfetsel('str', 'spip_tradlangs', 'id = '.sql_quote($id).' AND id_tradlang_module = ' . intval($info_module['id_tradlang_module']).' AND lang = ' . sql_quote($info_module['lang_mere'])); $chaine = array('id' => $row['id'],'str_orig'=>$str_original,'str'=>$str,'statut'=>$row['statut'],'comm'=>$row['comm']); $chaines_csv[] = $chaine; @@ -67,7 +65,7 @@ function export_lang_csv_dist($module,$langue,$dir_lang){ } $fp = fopen($fichier, 'w'); - + foreach ($chaines_csv as $fields) { fputcsv($fp, $fields); } @@ -76,4 +74,3 @@ function export_lang_csv_dist($module,$langue,$dir_lang){ return $fichier; } -?> \ No newline at end of file diff --git a/export_lang/po.php b/export_lang/po.php index 4d5c370..e16084d 100644 --- a/export_lang/po.php +++ b/export_lang/po.php @@ -1,91 +1,93 @@ <?php /** - * + * * Trad-lang v2 * Plugin SPIP de traduction de fichiers de langue * © Florent Jugla, Fil, kent1 - * + * * Fichier d'export d'un module de langue en .po (Gettext) */ - + if (!defined('_ECRIRE_INC_VERSION')) { return; } /** * Fonction d'export d'une langue d'un module en .po - * + * * Les chaînes avec un statut NEW sont vidées * Les chaînes avec un statut MODIF sont mises en "fuzzy" - * - * @param string $module + * + * @param string $module * Le module à exporter (le champ "module" dans la base) - * @param string $langue + * @param string $langue * La langue à exporter - * @param string $dir_lang + * @param string $dir_lang * Le répertoire où stocker les fichiers de langue - * @return string $fichier + * @return string $fichier * Le fichier final */ -function export_lang_po_dist($module,$langue,$dir_lang){ +function export_lang_po_dist($module, $langue, $dir_lang) { $x=$tous=array(); $contenu = ''; - + /** * Le fichier final * local/cache-lang/module_lang.po */ - $fichier = $dir_lang."/".$module."_".$langue.".po"; + $fichier = $dir_lang . '/' . $module . '_' . $langue . '.po'; /** * Les informations du module - */ - $info_module = sql_fetsel('id_tradlang_module,lang_mere,nom_mod','spip_tradlang_modules','module='.sql_quote($module)); - - $url_trad = url_absolue(parametre_url(generer_url_entite($info_module['id_tradlang_module'],'tradlang_module'),'lang_cible',$langue)); - + */ + $info_module = sql_fetsel('id_tradlang_module,lang_mere,nom_mod', 'spip_tradlang_modules', 'module = ' . sql_quote($module)); + + $url_trad = url_absolue(parametre_url(generer_url_entite($info_module['id_tradlang_module'], 'tradlang_module'), 'lang_cible', $langue)); + /** * Gestion des auteurs - * + * * On ajoute une liste de traducteurs en entête de fichier (non obligatoire) * On ajoute également l'item "Last-Translator : user <email>" dans les métas ($last_auteur) */ $last_auteur = array(); - if($langue != $info_module['lang_mere']){ - $traducteur = sql_fetsel('id_tradlang,traducteur','spip_tradlangs',"id_tradlang_module=".intval($info_module['id_tradlang_module'])." AND lang=".sql_quote($langue),"",'maj DESC','0,1'); - if(is_numeric($traducteur['traducteur'])) + if ($langue != $info_module['lang_mere']) { + $traducteur = sql_fetsel('id_tradlang,traducteur', 'spip_tradlangs', 'id_tradlang_module = ' . intval($info_module['id_tradlang_module']) . ' AND lang = '.sql_quote($langue), '', 'maj DESC', '0,1'); + if (is_numeric($traducteur['traducteur'])) { $id_auteur = $traducteur['traducteur']; - else - $id_auteur = sql_getfetsel('id_auteur','spip_versions','objet="tradlang" AND id_objet='.intval($traducteur['id_tradlang']),"",'id_version DESC','0,1'); + } else { + $id_auteur = sql_getfetsel('id_auteur', 'spip_versions', 'objet="tradlang" AND id_objet = ' . intval($traducteur['id_tradlang']), '', 'id_version DESC', '0,1'); + } + + $last_auteur = sql_fetsel('nom,email', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); - $last_auteur = sql_fetsel('nom,email','spip_auteurs','id_auteur='.intval($id_auteur)); - $traducteurs[$lang] = array(); $people_unique = array(); - $liste_traducteurs = sql_select('DISTINCT(traducteur)','spip_tradlangs','id_tradlang_module='.intval($info_module['id_tradlang_module'])." and lang=".sql_quote($langue)); - while ($t = sql_fetch($liste_traducteurs)){ - $traducteurs_lang = explode(',',$t['traducteur']); - foreach($traducteurs_lang as $traducteur){ - if(!in_array($traducteur,$people_unique)){ - if(is_numeric($traducteur) AND $id_auteur=intval($traducteur)){ - $traducteur_supp['nom'] = extraire_multi(sql_getfetsel('nom','spip_auteurs','id_auteur='.$id_auteur)); - $traducteur_supp['lien'] = url_absolue(generer_url_entite($id_auteur,'auteur'),$url_site); - }else if(trim(strlen($traducteur)) > 0){ + $liste_traducteurs = sql_select('DISTINCT(traducteur)', 'spip_tradlangs', 'id_tradlang_module = '.intval($info_module['id_tradlang_module']) . ' AND lang = ' . sql_quote($langue)); + while ($t = sql_fetch($liste_traducteurs)) { + $traducteurs_lang = explode(',', $t['traducteur']); + foreach ($traducteurs_lang as $traducteur) { + if (!in_array($traducteur, $people_unique)) { + if (is_numeric($traducteur) and $id_auteur=intval($traducteur)) { + $traducteur_supp['nom'] = extraire_multi(sql_getfetsel('nom', 'spip_auteurs', 'id_auteur = ' . $id_auteur)); + $traducteur_supp['lien'] = url_absolue(generer_url_entite($id_auteur, 'auteur'), $url_site); + } elseif (trim(strlen($traducteur)) > 0) { $traducteur_supp['nom'] = trim($traducteur); $traducteur_supp['lien'] = ''; } - if(isset($traducteur_supp['nom'])) + if (isset($traducteur_supp['nom'])) { $traducteurs[$lang][] = $traducteur_supp; + } unset($traducteur_supp); $people_unique[] = $traducteur; } } } - foreach($traducteurs as $lang => $peoples) { + foreach ($traducteurs as $lang => $peoples) { $trad_texte = "#\n# Traducteurs :\n"; if ($peoples) { foreach ($peoples as $people) { - $trad_texte .= "# ".$people['nom']." (".$people['lien'].")\n"; + $trad_texte .= '# ' . $people['nom'] . ' (' . $people['lien'] . ")\n"; } } } @@ -118,11 +120,11 @@ msgstr "" /** * Les chaines - * + * * On crée un bloc pour chaque chaînes sous la forme - * + * * #, php-format - * #| msgid "id_dans_la_base" + * #| msgid "id_dans_la_base" * msgid "Item dans la langue originale" * msgstr "Item dans la langue actuelle (traduit), si non traduit, vide" */ @@ -131,34 +133,36 @@ msgstr "" $tous[$row['id']] = $row; } ksort($tous); - + foreach ($tous as $id => $row) { - if (trim($row['comm'])) $row['comm']=" # ".trim($row['comm']); // on rajoute les commentaires ? + if (trim($row['comm'])) { + /** + * on rajoute les commentaires ? + */ + $row['comm'] = ' # ' . trim($row['comm']); + } $str = $row['str']; $oldmd5 = md5($str); - $str = unicode_to_utf_8( - html_entity_decode( - preg_replace('/&([lg]t;)/S', '&\1', $str), - ENT_NOQUOTES, 'utf-8') - ); + $str = unicode_to_utf_8(html_entity_decode(preg_replace('/&([lg]t;)/S', '&\1', $str), ENT_NOQUOTES, 'utf-8')); $newmd5 = md5($str); - if ($oldmd5 !== $newmd5) sql_updateq("spip_tradlangs",array('md5'=>$newmd5), "md5=".sql_quote($oldmd5)." AND id_tradlang_module=".intval($info_module['id_tradlang_module'])); - $str_original = sql_getfetsel('str','spip_tradlangs','id ='.sql_quote($id).' AND id_tradlang_module='.intval($info_module['id_tradlang_module']).' AND lang='.sql_quote($info_module['lang_mere'])); - $x[]=($row['comm'] ? "#".$row['comm']."\n" : ""). -" -#, ".(($row['statut'] == 'MODIF') ? "fuzzy, php-format" : "php-format")." + if ($oldmd5 !== $newmd5) { + sql_updateq('spip_tradlangs', array('md5' => $newmd5), 'md5 = '.sql_quote($oldmd5) . ' AND id_tradlang_module = ' . intval($info_module['id_tradlang_module'])); + } + $str_original = sql_getfetsel('str', 'spip_tradlangs', 'id =' . sql_quote($id) . ' AND id_tradlang_module=' . intval($info_module['id_tradlang_module']) . ' AND lang=' . sql_quote($info_module['lang_mere'])); + $x[] = ($row['comm'] ? '#' . $row['comm']."\n" : ''). +' +#, '.(($row['statut'] == 'MODIF') ? 'fuzzy, php-format' : 'php-format')." #| msgid \"".$row['id']."\" -msgid \"".str_replace('"','\"',$str_original)."\" -msgstr \"".(($row['statut'] == 'NEW') ? '' : str_replace('"','\"',$str))."\""; +msgid \"".str_replace('"', '\"', $str_original)."\" +msgstr \"".(($row['statut'] == 'NEW') ? '' : str_replace('"', '\"', $str))."\""; unset($tous[$id]); } - $contenu .= str_replace("\r\n", "\n", join("\n",$x)); - - ecrire_fichier($fichier,$contenu); + $contenu .= str_replace("\r\n", "\n", join("\n", $x)); + + ecrire_fichier($fichier, $contenu); return $fichier; } -?> \ No newline at end of file diff --git a/export_lang/spip.php b/export_lang/spip.php index 0848e55..f991cc0 100644 --- a/export_lang/spip.php +++ b/export_lang/spip.php @@ -1,20 +1,20 @@ <?php /** - * + * * Trad-lang v2 * Plugin SPIP de traduction de fichiers de langue * © Florent Jugla, Fil, kent1 - * + * * Fichier des fonctions spécifiques du plugin */ -if (!defined("_ECRIRE_INC_VERSION")) { +if (!defined('_ECRIRE_INC_VERSION')) { return; } /** * Fonction d'export d'une langue d'un module SPIP en php - * + * * @param string $module * Le module à exporter * @param string $langue @@ -26,44 +26,55 @@ if (!defined("_ECRIRE_INC_VERSION")) { * @return string $fichier * Le fichier final */ -function export_lang_spip_dist($module,$langue,$dir_lang,$tout=false){ +function export_lang_spip_dist($module, $langue, $dir_lang, $tout = false) { /** * Le fichier final * local/cache-lang/module_lang.php */ - $fichier = $dir_lang."/".$module."_".$langue.".php"; + $fichier = $dir_lang . '/' . $module . '_' . $langue . '.php'; $tab = "\t"; - $where = "module=".sql_quote($module)." AND lang=".sql_quote($langue); - if(!$tout) + $where = 'module = ' . sql_quote($module) . ' AND lang = ' . sql_quote($langue); + if (!$tout) { $where .= " AND statut IN ('OK','MODIF','RELIRE')"; - $res=sql_allfetsel("id,str,comm,statut","spip_tradlangs",$where,"id"); + } + $res=sql_allfetsel('id,str,comm,statut', 'spip_tradlangs', $where, 'id'); $x=array(); - $prev=""; - $tous = $lorigine; // on part de l'origine comme ca on a tout meme si c'est pas dans la base de donnees (import de salvatore/lecteur.php) - foreach ($res as $row){ + $prev = ''; + /** + * on part de l'origine comme ca on a tout + * meme si c'est pas dans la base de donnees (import de salvatore/lecteur.php) + */ + $tous = $lorigine; + foreach ($res as $row) { $tous[$row['id']] = $row; } ksort($tous); foreach ($tous as $row) { - if ($prev!=strtoupper($row['id'][0])) $x[] = "\n$tab// ".strtoupper($row['id'][0]); - $prev=strtoupper($row['id'][0]); - if (strlen($row['statut']) && ($row['statut'] != 'OK')) + if ($prev != strtoupper($row['id'][0])) { + $x[] = "\n$tab// ".strtoupper($row['id'][0]); + } + $prev = strtoupper($row['id'][0]); + if (strlen($row['statut']) and ($row['statut'] != 'OK')) { $row['comm'] .= ' '.$row['statut']; - if (trim($row['comm'])) $row['comm']=" # ".trim($row['comm']); // on rajoute les commentaires ? + } + if (trim($row['comm'])) { + /** + * on rajoute les commentaires ? + */ + $row['comm'] = ' # ' . trim($row['comm']); + } $str = $row['str']; $oldmd5 = md5($str); - $str = unicode_to_utf_8( - html_entity_decode( - preg_replace('/&([lg]t;)/S', '&\1', $str), - ENT_NOQUOTES, 'utf-8') - ); + $str = unicode_to_utf_8(html_entity_decode(preg_replace('/&([lg]t;)/S', '&\1', $str), ENT_NOQUOTES, 'utf-8')); $newmd5 = md5($str); - if ($oldmd5 !== $newmd5) sql_updateq("spip_tradlangs",array('md5'=>$newmd5), "md5=".sql_quote($oldmd5)." AND module=".sql_quote($module)); + if ($oldmd5 !== $newmd5) { + sql_updateq('spip_tradlangs', array('md5'=>$newmd5), 'md5 = ' . sql_quote($oldmd5) . ' AND module = '.sql_quote($module)); + } - $x[]="$tab".var_export($row['id'],1).' => ' .var_export($str,1).','.$row['comm'] ; + $x[] = "$tab".var_export($row['id'], 1) . ' => ' . var_export($str, 1) . ',' . $row['comm'] ; } /** @@ -82,29 +93,29 @@ function export_lang_spip_dist($module,$langue,$dir_lang,$tout=false){ */ $x[count($x)-1] = preg_replace('/,([^,]*)$/', '\1', $x[count($x)-1]); - $contenu = join("\n",$x); - + $contenu = join("\n", $x); + /** * On écrit le fichier */ - fwrite($fd, - '<'.'?php + fwrite( + $fd, + '<'.'?php // This is a SPIP language file -- Ceci est un fichier langue de SPIP // extrait automatiquement de '.$url_trad.' // ** ne pas modifier le fichier ** ' -."\n".$secure.'$GLOBALS[$GLOBALS[\'idx_lang\']] = array( + ."\n".$secure.'$GLOBALS[$GLOBALS[\'idx_lang\']] = array( ' -. str_replace("\r\n", "\n", $contenu) -.' + . str_replace("\r\n", "\n", $contenu) + .' ); ?'.'>' ); - + fclose($fd); @chmod($fichier, 0666); - + return $fichier; } -?> \ No newline at end of file -- GitLab