Source for file class.translations.php
Documentation is available at class.translations.php
* Logique des traductions
* LODEL - Logiciel d'Edition ELectronique.
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @author Sophie Malafosse
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Fichier ajouté depuis la version 0.8
* @version CVS:$Id: class.translations.php 4006 2007-10-05 11:53:41Z malafosse $
$GLOBALS['translations_textgroups']= array("interface"=> array("common","edition","admin","lodeladmin","install","lodelloader"),
* Classe de logique des traductions
* @author Ghislain Picard
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Classe ajouté depuis la version 0.8
$this->Logic("translations");
function loop_textgroups(&$context,$funcname)
foreach($GLOBALS['translations_textgroups'][$context['textgroups']] as $textgroup) {
$localcontext['textgroup']= $textgroup;
function loop_alltexts(&$context,$funcname)
global $db,$distincttexts,$alltexts_cache;
$result= $db->execute(lq("SELECT status,contents,name,id,lang FROM #_TP_texts WHERE status>=-1 AND textgroup='". $context['textgroup']. "'")) or dberror();
$lang= $result->fields['lang'];
$name= $result->fields['name'];
$alltexts_cache[$lang][$name]= $result->fields;
if ($lang== $GLOBALS['lang']) {
$distincttexts[$name]= $result->fields['contents'];
} elseif (!isset ($distincttexts[$name])) {
$distincttexts[$name]= true;
foreach($distincttexts as $name=> $contents) {
$localcontext['name']= $name;
$localcontext['contents']= $contents;
function loop_lang_and_text(&$context,$funcname)
foreach(array_keys($GLOBALS['alltexts_cache']) as $lang) {
$row= $GLOBALS['alltexts_cache'][$lang][$context['name']];
$localcontext= $row ? array_merge($context,$row) : $context;
function editAction(&$context,&$error,$clean= false)
if (!$context['id']) $context['modificationdate']= date("Y-m-d");
require_once("validfunc.php");
if ($lang!= "all" && !validfield($lang,"lang")) die("ERROR: invalid lang");
//lock_write("translations","textes");
require_once("translationfunc.php");
#$ret=$xmldb->saveToString();
$xmldb->saveToFile($tmpfile);
$filename= "translation-$lang-". date("dmy"). ".xml";
require_once("importfunc.php");
require_once("validfunc.php");
require_once("translationfunc.php");
$xmldb->readFromFile($file);
global $fileregexp,$importdirs,$home;
foreach ($importdirs as $dir) {
while (($file= readdir($dh))!== FALSE) {
if (!preg_match("/^$fileregexp$/i",$file)) continue;
$localcontext['filename']= $file;
$localcontext['fullfilename']= "$dir/$file";
if ($dir== "CACHE") $localcontext['maybedeleted']= 1;
for($i= 1; $i< count($arr); $i+= 2) {
foreach (array("lang","title","creationdate","modificationdate") as $tag) {
if (preg_match("/<$tag>(.*)<\/$tag>/",$arr[$i],$result))
if (!$localcontext['lang']) continue;
return "import_translations";
/*---------------------------------------------------------------*/
//! Private or protected from this point
$context['textgroups']= $GLOBALS['site'] ? "site" : "interface";
* Sauve des données dans des tables liées éventuellement
* Appelé par editAction pour effectuer des opérations supplémentaires de sauvegarde.
* @param object $vo l'objet qui a été créé
* @param array $context le contexte
// create all the texts if needed
// can't use insert select... so it not really funny to do
if (!$vo->lang) { // get the lang if we don't have it
$vo= $dao->getById($vo->id);
if ($vo->lang== $lodeluser['lang']) {
// get any lang... this should not happen anyway
$vo2= $dao->find("status>0","lang");
// normal case... should be different !
$fromlang= $lodeluser['lang'];
// get all the text name, group, text in current lang for which the translation does not exists in the new lang
$result= $db->execute(lq("SELECT t1.name,t1.textgroup,t1.contents FROM #_TP_texts as t1 LEFT OUTER JOIN #_TP_texts as t2 ON t1.name=t2.name AND t1.textgroup=t2.textgroup AND t2.lang='". $vo->lang. "' WHERE t1.status>-64 AND t1.lang='". $fromlang. "' AND t2.id IS NULL AND t1.". $textscriteria. " GROUP BY t1.name,t1.textgroup")) or dberror();
do { // use multiple insert but not to much... to minimize the size of the query
$inserts= array(); $count= 0;
while (!$result->EOF && $count< 20) {
#$langs=explode(",",$row['langs']); // get the lang
#if (in_array($lang,$langs)) continue; // the text already exists in the correct lang
$inserts[]= "('". $row['name']. "','". $row['textgroup']. "','". mysql_escape_string($row['contents']). "','-1','". $context['lang']. "')";
$db->execute(lq("INSERT INTO #_TP_texts (name,textgroup,contents,status,lang) VALUES ". join(",",$inserts))) or dberror();
//il faut supprimer les texts associés à la traduction
// reinitialise le cache surement.
// begin{publicfields} automatic generation //
* Retourne la liste des champs publics
return array('lang' => array('text', '+'),
'title' => array('text', ''),
'textgroups' => array('text', ''),
'translators' => array('text', ''),
'creationdate' => array('date', ''));
// end{publicfields} automatic generation //
// begin{uniquefields} automatic generation //
* Retourne la liste des champs uniques
return array(array('lang', 'textgroups'), );
// end{uniquefields} automatic generation //
/*-----------------------------------*/
if (!$textgroups) die("ERROR: which textgroups ?");
if ($GLOBALS['translations_textgroups'][$textgroups]) {
return "textgroup IN ('". join("','",$GLOBALS['translations_textgroups'][$textgroups]). "')";
die("ERROR: unkown textgroup");
|