2003-05-02 12:33:06 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
/* ***************************************************************************
|
2005-01-02 17:57:37 +01:00
|
|
|
|
* Copyright (C) 2001 Eric Seigne <erics@rycks.com>
|
|
|
|
|
|
* Copyright (C) 2004-2005 Destailleur Laurent <eldy@users.sourceforge.net>
|
2003-05-02 12:33:06 +02:00
|
|
|
|
*
|
|
|
|
|
|
* 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
|
|
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
* ************************************************************************* */
|
|
|
|
|
|
|
2005-01-02 17:57:37 +01:00
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/translate.class.php
|
|
|
|
|
|
\brief Fichier de la classe de traduction
|
|
|
|
|
|
\author Laurent Destailleur
|
|
|
|
|
|
\version $Revision$
|
2004-08-15 20:09:30 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-02 17:57:37 +01:00
|
|
|
|
/**
|
|
|
|
|
|
\class Translate
|
|
|
|
|
|
\brief Classe permettant de g<EFBFBD>rer les traductions
|
2004-08-15 20:09:30 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class Translate {
|
2004-07-25 19:43:23 +02:00
|
|
|
|
|
2005-02-06 19:41:45 +01:00
|
|
|
|
var $dir;
|
2006-08-07 04:20:57 +02:00
|
|
|
|
var $origlang; // Langue origine
|
|
|
|
|
|
var $defaultlang; // Langue courante en vigueur de l'utilisateur
|
2005-02-06 19:41:45 +01:00
|
|
|
|
|
2006-05-20 11:19:20 +02:00
|
|
|
|
var $tab_loaded=array(); // Tableau pour signaler les fichiers deja charg<72>s
|
|
|
|
|
|
var $tab_translate=array(); // Tableau des traductions
|
2004-07-13 23:25:53 +02:00
|
|
|
|
|
2007-05-25 22:02:23 +02:00
|
|
|
|
var $charset_inputfile='ISO-8859-1'; // Codage du contenu du fichier langue
|
|
|
|
|
|
var $charset_output='ISO-8859-1'; // Codage par defaut de la sortie de la m<>thode trans
|
2007-05-21 02:41:46 +02:00
|
|
|
|
|
2003-05-02 12:33:06 +02:00
|
|
|
|
|
2004-08-15 20:09:30 +02:00
|
|
|
|
/**
|
2005-01-02 17:57:37 +01:00
|
|
|
|
* \brief Constructeur de la classe
|
2005-10-30 01:42:54 +02:00
|
|
|
|
* \param dir Repertoire racine des fichiers de traduction
|
2007-05-25 22:02:23 +02:00
|
|
|
|
* \param conf Objet qui contient la config Dolibarr
|
2004-10-20 23:15:17 +02:00
|
|
|
|
*/
|
2007-05-25 22:02:23 +02:00
|
|
|
|
function Translate($dir = "",$conf)
|
2005-10-30 01:42:54 +02:00
|
|
|
|
{
|
2007-05-25 22:02:23 +02:00
|
|
|
|
// Si charset output defini
|
|
|
|
|
|
if (isset($conf->character_set_client) && $conf->character_set_client)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->charset_output=$conf->character_set_client;
|
|
|
|
|
|
}
|
2004-07-13 23:25:53 +02:00
|
|
|
|
$this->dir=$dir;
|
2005-10-30 02:07:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-20 11:19:20 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoie la chaine traduite pour une cl<EFBFBD> donn<EFBFBD>e.
|
|
|
|
|
|
* Le tableau des traductions doit avoir <EFBFBD>t<EFBFBD> charg<EFBFBD>.
|
|
|
|
|
|
* \param key Cl<EFBFBD> de traduction
|
|
|
|
|
|
* \return string Chaine de traduction
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getTransFromTab($key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isset($this->tab_translate[$key]) && $this->tab_translate[$key])
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->tab_translate[$key];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Positionne la chaine traduite pour une cl<EFBFBD> donn<EFBFBD>e.
|
|
|
|
|
|
* \param key Cl<EFBFBD> de traduction
|
|
|
|
|
|
* \param value Chaine de traduction
|
|
|
|
|
|
*/
|
|
|
|
|
|
function setTransFromTab($key,$value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->tab_translate[$key]=$value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-10-30 02:07:00 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Accesseur de this->defaultlang
|
2006-08-07 04:20:57 +02:00
|
|
|
|
* \param srclang Langue <EFBFBD> utiliser
|
2005-10-30 02:07:00 +01:00
|
|
|
|
*/
|
2006-08-07 04:20:57 +02:00
|
|
|
|
function setDefaultLang($srclang='fr_FR')
|
2005-10-30 02:07:00 +01:00
|
|
|
|
{
|
2006-08-07 04:20:57 +02:00
|
|
|
|
$this->origlang=$srclang;
|
|
|
|
|
|
|
|
|
|
|
|
if ($srclang == 'auto')
|
2005-10-30 01:42:54 +02:00
|
|
|
|
{
|
2005-10-30 02:07:00 +01:00
|
|
|
|
$langpref=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
|
|
|
|
|
$langpref=eregi_replace(";[^,]*","",$langpref);
|
|
|
|
|
|
$langpref=eregi_replace("-","_",$langpref);
|
2005-10-30 02:52:48 +01:00
|
|
|
|
|
|
|
|
|
|
$langlist=split("[;,]",$langpref);
|
|
|
|
|
|
|
|
|
|
|
|
$langpart=split("_",$langlist[0]);
|
|
|
|
|
|
|
2006-08-07 04:20:57 +02:00
|
|
|
|
if (isset($langpart[1])) $srclang=strtolower($langpart[0])."_".strtoupper($langpart[1]);
|
|
|
|
|
|
else $srclang=strtolower($langpart[0])."_".strtoupper($langpart[0]);
|
2005-10-30 01:42:54 +02:00
|
|
|
|
}
|
2005-10-30 02:07:00 +01:00
|
|
|
|
|
2006-08-07 04:20:57 +02:00
|
|
|
|
$this->defaultlang=$srclang;
|
2004-07-13 23:25:53 +02:00
|
|
|
|
}
|
2003-05-02 12:33:06 +02:00
|
|
|
|
|
2005-10-30 02:07:00 +01:00
|
|
|
|
|
2005-11-01 00:49:35 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Accesseur de this->defaultlang
|
|
|
|
|
|
* \return string Langue utilis<EFBFBD>e
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getDefaultLang()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->defaultlang;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
\brief Positionne environnement PHP en fonction du langage
|
|
|
|
|
|
\remarks Le code langue long (fr_FR, en_US, ...) doit <EFBFBD>tre positionn<EFBFBD>
|
|
|
|
|
|
\return int >0 si ok, <0 so ko
|
|
|
|
|
|
*/
|
|
|
|
|
|
function setPhpLang()
|
|
|
|
|
|
{
|
2006-06-18 14:56:57 +02:00
|
|
|
|
//dolibarr_syslog("Translate::set_php_lang: ".$this->defaultlang,LOG_DEBUG);
|
2005-11-01 00:49:35 +01:00
|
|
|
|
|
|
|
|
|
|
$code_lang_tiret=ereg_replace('_','-',$this->defaultlang);
|
|
|
|
|
|
setlocale(LC_ALL, $this->defaultlang); // Compenser pb de locale avec windows
|
|
|
|
|
|
setlocale(LC_ALL, $code_lang_tiret);
|
|
|
|
|
|
if (defined("MAIN_FORCE_SETLOCALE_LC_ALL") && MAIN_FORCE_SETLOCALE_LC_ALL) setlocale(LC_ALL, MAIN_FORCE_SETLOCALE_LC_ALL);
|
|
|
|
|
|
if (defined("MAIN_FORCE_SETLOCALE_LC_TIME") && MAIN_FORCE_SETLOCALE_LC_TIME) setlocale(LC_TIME, MAIN_FORCE_SETLOCALE_LC_TIME);
|
|
|
|
|
|
if (defined("MAIN_FORCE_SETLOCALE_LC_NUMERIC") && MAIN_FORCE_SETLOCALE_LC_NUMERIC) setlocale(LC_NUMERIC, MAIN_FORCE_SETLOCALE_LC_NUMERIC);
|
|
|
|
|
|
if (defined("MAIN_FORCE_SETLOCALE_LC_MONETARY") && MAIN_FORCE_SETLOCALE_LC_MONETARY) setlocale(LC_MONETARY, MAIN_FORCE_SETLOCALE_LC_MONETARY);
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-02 17:57:37 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Charge en m<EFBFBD>moire le tableau de traduction pour un domaine particulier
|
|
|
|
|
|
* Si le domaine est deja charg<EFBFBD>, la fonction ne fait rien
|
|
|
|
|
|
* \param domain Nom du domain (fichier lang) <EFBFBD> charger
|
2005-10-30 01:42:54 +02:00
|
|
|
|
* \param alt Utilise le fichier alternatif meme si fichier dans la langue est trouv<EFBFBD>e
|
2005-01-02 17:57:37 +01:00
|
|
|
|
*/
|
2005-02-06 19:41:45 +01:00
|
|
|
|
function Load($domain,$alt=0)
|
|
|
|
|
|
{
|
2005-03-21 20:53:50 +01:00
|
|
|
|
if (isset($this->tab_loaded[$domain]) && $this->tab_loaded[$domain]) { return; } // Le fichier de ce domaine est deja charg<72>
|
2005-02-06 19:41:45 +01:00
|
|
|
|
|
|
|
|
|
|
// Repertoire de traduction
|
|
|
|
|
|
$scandir = $this->dir."/".$this->defaultlang;
|
2004-07-13 23:25:53 +02:00
|
|
|
|
$file_lang = $scandir . "/$domain.lang";
|
2005-10-30 01:42:54 +02:00
|
|
|
|
$filelangexists=is_file($file_lang);
|
2005-02-06 19:41:45 +01:00
|
|
|
|
|
2005-10-30 01:42:54 +02:00
|
|
|
|
if ($alt || ! $filelangexists)
|
|
|
|
|
|
{
|
2005-02-06 19:41:45 +01:00
|
|
|
|
// Repertoire de la langue alternative
|
2006-12-12 19:33:19 +01:00
|
|
|
|
if ($this->defaultlang == "en_US") $scandiralt = $this->dir."/fr_FR";
|
|
|
|
|
|
elseif (eregi('^fr',$this->defaultlang) && $this->defaultlang != 'fr_FR') $scandiralt = $this->dir."/fr_FR";
|
|
|
|
|
|
elseif (eregi('^en',$this->defaultlang) && $this->defaultlang != 'en_US') $scandiralt = $this->dir."/en_US";
|
|
|
|
|
|
else $scandiralt = $this->dir."/en_US";
|
|
|
|
|
|
|
2004-07-13 23:25:53 +02:00
|
|
|
|
$file_lang = $scandiralt . "/$domain.lang";
|
2005-10-30 01:42:54 +02:00
|
|
|
|
$filelangexists=is_file($file_lang);
|
2005-02-06 19:41:45 +01:00
|
|
|
|
$alt=1;
|
2004-07-13 23:25:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-30 01:42:54 +02:00
|
|
|
|
if ($filelangexists)
|
|
|
|
|
|
{
|
2007-08-03 01:30:57 +02:00
|
|
|
|
//dolibarr_syslog("Translate::load open file ".$file_lang);
|
2005-10-30 01:42:54 +02:00
|
|
|
|
if($fp = @fopen($file_lang,"rt"))
|
|
|
|
|
|
{
|
2004-06-11 01:38:00 +02:00
|
|
|
|
$finded = 0;
|
2005-10-30 01:42:54 +02:00
|
|
|
|
while (($ligne = fgets($fp,4096)) && ($finded == 0))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($ligne[0] != "\n" && $ligne[0] != " " && $ligne[0] != "#")
|
|
|
|
|
|
{
|
2004-07-25 17:31:16 +02:00
|
|
|
|
$tab=split('=',$ligne,2);
|
2006-10-24 23:05:51 +02:00
|
|
|
|
$key=trim($tab[0]); $value='';
|
2004-07-25 18:52:26 +02:00
|
|
|
|
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
|
2006-07-13 15:53:40 +02:00
|
|
|
|
if (! $this->getTransFromTab($key))
|
|
|
|
|
|
{
|
2006-07-13 16:39:46 +02:00
|
|
|
|
if (isset($tab[1])) $value=trim(ereg_replace('\\\n',"\n",$tab[1]));
|
2007-05-25 22:02:23 +02:00
|
|
|
|
|
|
|
|
|
|
if (eregi('^CHARSET$',$key))
|
|
|
|
|
|
{
|
|
|
|
|
|
// On est tombe sur une balise qui declare le format du fichier lu
|
|
|
|
|
|
$this->charset_inputfile=strtoupper($value);
|
|
|
|
|
|
//print 'File '.$file_lang.' has format '.$this->charset_inputfile.'<br>';
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// On stocke toujours dans le tableau Tab en ISO
|
|
|
|
|
|
if ($this->charset_inputfile == 'UTF-8') $value=utf8_decode($value);
|
2007-05-25 22:43:47 +02:00
|
|
|
|
//if ($this->charset_inputfile == 'ISO-8859-1') $value=$value;
|
|
|
|
|
|
|
2007-05-25 22:02:23 +02:00
|
|
|
|
$this->setTransFromTab($key,$value);
|
|
|
|
|
|
}
|
2006-07-13 15:53:40 +02:00
|
|
|
|
}
|
2004-06-11 01:38:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
fclose($fp);
|
2003-05-02 12:33:06 +02:00
|
|
|
|
|
2005-02-06 19:41:45 +01:00
|
|
|
|
// Pour les langues aux fichiers parfois incomplets, on charge la langue alternative
|
2005-10-30 01:42:54 +02:00
|
|
|
|
if (! $alt && $this->defaultlang != "fr_FR" && $this->defaultlang != "en_US")
|
|
|
|
|
|
{
|
2005-02-06 19:41:45 +01:00
|
|
|
|
dolibarr_syslog("translate::load loading alternate translation file");
|
|
|
|
|
|
$this->load($domain,1);
|
|
|
|
|
|
}
|
2003-05-02 12:33:06 +02:00
|
|
|
|
|
2005-02-06 19:41:45 +01:00
|
|
|
|
$this->tab_loaded[$domain]=1; // Marque ce fichier comme charg<72>
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-10-30 02:07:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-05-02 12:33:06 +02:00
|
|
|
|
|
2005-01-02 17:57:37 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retourne la liste des domaines charg<EFBFBD>es en memoire
|
|
|
|
|
|
* \return array Tableau des domaines charg<EFBFBD>es
|
|
|
|
|
|
*/
|
2005-10-30 01:42:54 +02:00
|
|
|
|
function list_domainloaded()
|
|
|
|
|
|
{
|
2004-07-25 19:43:23 +02:00
|
|
|
|
return join(",",array_keys($this->tab_loaded));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-10-20 23:15:17 +02:00
|
|
|
|
/**
|
2006-12-12 20:43:41 +01:00
|
|
|
|
* \brief Retourne la version traduite du texte pass<EFBFBD> en param<EFBFBD>tre en la codant en HTML
|
2006-12-12 20:25:30 +01:00
|
|
|
|
* Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif
|
|
|
|
|
|
* et si toujours pas trouv<EFBFBD>, il est retourn<EFBFBD> tel quel
|
|
|
|
|
|
* Les param<EFBFBD>tres de cette m<EFBFBD>thode peuvent contenir de balises HTML.
|
|
|
|
|
|
* \param key cl<EFBFBD> de chaine a traduire
|
|
|
|
|
|
* \param param1 chaine de param1
|
|
|
|
|
|
* \param param2 chaine de param1
|
|
|
|
|
|
* \param param3 chaine de param1
|
|
|
|
|
|
* \param maxsize taille max
|
2006-12-12 20:43:41 +01:00
|
|
|
|
* \return string chaine traduite et cod<EFBFBD> en HTML
|
2004-10-20 23:15:17 +02:00
|
|
|
|
*/
|
2006-12-12 20:25:30 +01:00
|
|
|
|
function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0)
|
2005-10-30 01:42:54 +02:00
|
|
|
|
{
|
2006-12-12 20:25:30 +01:00
|
|
|
|
if ($this->getTransFromTab($key))
|
|
|
|
|
|
{
|
|
|
|
|
|
// Si la traduction est disponible
|
|
|
|
|
|
$str=sprintf($this->tab_translate[$key],$param1,$param2,$param3,$param4);
|
|
|
|
|
|
if ($maxsize) $str=dolibarr_trunc($str,$maxsize);
|
2006-12-12 20:43:41 +01:00
|
|
|
|
// On remplace les tags HTML par __xx__ pour eviter traduction par htmlentities
|
|
|
|
|
|
$newstr=ereg_replace('<','__lt__',$str);
|
|
|
|
|
|
$newstr=ereg_replace('>','__gt__',$newstr);
|
2006-12-16 14:45:59 +01:00
|
|
|
|
$newstr=ereg_replace('"','__quot__',$newstr);
|
2007-05-21 02:41:46 +02:00
|
|
|
|
|
2007-05-26 00:23:03 +02:00
|
|
|
|
$newstr=$this->convToOuptutCharset($newstr);
|
2007-05-25 22:43:47 +02:00
|
|
|
|
|
2006-12-12 20:43:41 +01:00
|
|
|
|
// Cryptage en html de la chaine
|
2007-05-25 22:43:47 +02:00
|
|
|
|
// $newstr est une chaine stockee en memoire au format $this->charset_output
|
2007-05-25 22:02:23 +02:00
|
|
|
|
$newstr=htmlentities($newstr,ENT_QUOTES,$this->charset_output);
|
2007-05-21 02:41:46 +02:00
|
|
|
|
|
2006-12-12 20:43:41 +01:00
|
|
|
|
// On restaure les tags HTML
|
|
|
|
|
|
$newstr=ereg_replace('__lt__','<',$newstr);
|
|
|
|
|
|
$newstr=ereg_replace('__gt__','>',$newstr);
|
2006-12-16 14:45:59 +01:00
|
|
|
|
$newstr=ereg_replace('__quot__','"',$newstr);
|
2006-12-12 20:43:41 +01:00
|
|
|
|
return $newstr;
|
2006-12-12 20:25:30 +01:00
|
|
|
|
}
|
2007-05-26 00:23:03 +02:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->convToOuptutCharset($key);
|
|
|
|
|
|
}
|
2005-03-21 20:04:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-30 02:07:00 +01:00
|
|
|
|
|
2005-03-21 20:04:39 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retourne la version traduite du texte pass<EFBFBD> en param<EFBFBD>tre
|
|
|
|
|
|
* Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif
|
2006-05-20 11:19:20 +02:00
|
|
|
|
* et si toujours pas trouv<EFBFBD>, il est retourn<EFBFBD> tel quel.
|
|
|
|
|
|
* Les param<EFBFBD>tres de cette m<EFBFBD>thode ne doivent pas contenir de balises HTML.
|
|
|
|
|
|
* \param key cl<EFBFBD> de chaine a traduire
|
2005-03-21 20:04:39 +01:00
|
|
|
|
* \param param1 chaine de param1
|
|
|
|
|
|
* \param param2 chaine de param1
|
|
|
|
|
|
* \param param3 chaine de param1
|
2006-11-21 21:02:49 +01:00
|
|
|
|
* \param param4 chaine de param1
|
2005-03-21 20:04:39 +01:00
|
|
|
|
* \return string chaine traduite
|
|
|
|
|
|
*/
|
2006-11-21 21:02:49 +01:00
|
|
|
|
function transnoentities($key, $param1='', $param2='', $param3='', $param4='')
|
2005-10-30 02:07:00 +01:00
|
|
|
|
{
|
2006-05-20 11:19:20 +02:00
|
|
|
|
if ($this->getTransFromTab($key))
|
2005-10-30 02:07:00 +01:00
|
|
|
|
{
|
2004-06-11 01:38:00 +02:00
|
|
|
|
// Si la traduction est disponible
|
2006-11-21 21:02:49 +01:00
|
|
|
|
return sprintf($this->tab_translate[$key],$param1,$param2,$param3,$param4);
|
2004-06-11 01:38:00 +02:00
|
|
|
|
}
|
2006-05-20 11:19:20 +02:00
|
|
|
|
return $key;
|
2004-06-11 01:38:00 +02:00
|
|
|
|
}
|
2004-07-13 23:25:53 +02:00
|
|
|
|
|
2005-10-30 02:07:00 +01:00
|
|
|
|
|
2005-02-10 22:32:46 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retourne la version traduite du texte pass<EFBFBD> en param<EFBFBD>tre compl<EFBFBD>t<EFBFBD> du code pays
|
|
|
|
|
|
* \param str chaine a traduire
|
2005-03-01 22:44:32 +01:00
|
|
|
|
* \param countrycode code pays (FR, ...)
|
2005-02-10 22:32:46 +01:00
|
|
|
|
* \return string chaine traduite
|
|
|
|
|
|
*/
|
2005-10-30 02:07:00 +01:00
|
|
|
|
function transcountry($str, $countrycode)
|
|
|
|
|
|
{
|
2005-02-10 22:32:46 +01:00
|
|
|
|
if ($this->tab_translate["$str$countrycode"]) return $this->trans("$str$countrycode");
|
|
|
|
|
|
else return $this->trans("$str");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-05-26 00:23:03 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Convertit une chaine dans le charset de sortie
|
|
|
|
|
|
* \param str chaine a convertir
|
|
|
|
|
|
* \return string chaine traduite
|
|
|
|
|
|
*/
|
|
|
|
|
|
function convToOuptutCharset($str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->charset_output=='UTF-8') $str=utf8_encode($str);
|
|
|
|
|
|
//if ($this->charset_output=='ISO-8859-1') $str=$str;
|
|
|
|
|
|
return $str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-11 01:38:00 +02:00
|
|
|
|
/**
|
2005-01-02 17:57:37 +01:00
|
|
|
|
* \brief Retourne la liste des langues disponibles
|
|
|
|
|
|
* \return array list of languages
|
|
|
|
|
|
*/
|
2005-02-12 22:25:39 +01:00
|
|
|
|
function get_available_languages($langdir=DOL_DOCUMENT_ROOT)
|
2004-06-11 01:38:00 +02:00
|
|
|
|
{
|
2005-12-16 01:44:34 +01:00
|
|
|
|
// On parcour le r<>pertoire langs pour d<>tecter les langues disponibles
|
|
|
|
|
|
$handle=opendir($langdir ."/langs");
|
|
|
|
|
|
$langs_available=array();
|
|
|
|
|
|
while ($file = trim(readdir($handle)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (eregi('^[a-z]+_[A-Z]+',$file))
|
|
|
|
|
|
{
|
|
|
|
|
|
array_push($langs_available,$file);
|
|
|
|
|
|
}
|
2004-07-31 13:36:01 +02:00
|
|
|
|
}
|
2005-12-16 01:44:34 +01:00
|
|
|
|
return $langs_available;
|
2003-05-02 12:33:06 +02:00
|
|
|
|
}
|
2004-06-11 01:38:00 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2005-01-02 17:57:37 +01:00
|
|
|
|
* \brief Exp<EFBFBD>die le header correct et retourne le d<EFBFBD>but de la page html
|
|
|
|
|
|
* [en] Send header and return a string of html start page
|
|
|
|
|
|
* \return string html header avec charset
|
|
|
|
|
|
*/
|
2004-06-11 01:38:00 +02:00
|
|
|
|
function lang_header()
|
2003-05-02 12:33:06 +02:00
|
|
|
|
{
|
2007-05-25 22:02:23 +02:00
|
|
|
|
$texte = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$this->charset_output."\">\n";
|
2004-06-11 01:38:00 +02:00
|
|
|
|
return $texte;
|
|
|
|
|
|
}
|
2003-05-02 12:33:06 +02:00
|
|
|
|
|
2005-05-14 00:43:56 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoi si le fichier $filename existe dans la version de la langue courante ou alternative
|
|
|
|
|
|
* \param filename nom du fichier <EFBFBD> rechercher
|
|
|
|
|
|
* \param searchalt cherche aussi dans langue alternative
|
|
|
|
|
|
* \return boolean true si existe, false sinon
|
|
|
|
|
|
*/
|
2005-10-30 02:07:00 +01:00
|
|
|
|
function file_exists($filename,$searchalt=0)
|
|
|
|
|
|
{
|
2005-05-14 00:43:56 +02:00
|
|
|
|
// Test si fichier dans r<>pertoire de la langue
|
|
|
|
|
|
$htmlfile=$this->dir."/".$this->defaultlang."/".$filename;
|
|
|
|
|
|
if (is_readable($htmlfile)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
if ($searchalt) {
|
|
|
|
|
|
// Test si fichier dans r<>pertoire de la langue alternative
|
|
|
|
|
|
if ($this->defaultlang != "en_US") $htmlfilealt = $this->dir."/en_US/".$filename;
|
|
|
|
|
|
else $htmlfilealt = $this->dir."/fr_FR/".$filename;
|
|
|
|
|
|
if (is_readable($htmlfilealt)) return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoi le fichier $filename dans la version de la langue courante, sinon alternative
|
|
|
|
|
|
* \param filename nom du fichier <EFBFBD> rechercher
|
|
|
|
|
|
* \param searchalt cherche aussi dans langue alternative
|
|
|
|
|
|
*/
|
2005-10-30 02:07:00 +01:00
|
|
|
|
function print_file($filename,$searchalt=0)
|
|
|
|
|
|
{
|
2005-05-14 00:43:56 +02:00
|
|
|
|
// Test si fichier dans r<>pertoire de la langue
|
|
|
|
|
|
$htmlfile=$this->dir."/".$this->defaultlang."/".$filename;
|
2005-10-30 02:07:00 +01:00
|
|
|
|
if (is_readable($htmlfile))
|
|
|
|
|
|
{
|
2005-05-14 00:43:56 +02:00
|
|
|
|
include $htmlfile;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($searchalt) {
|
|
|
|
|
|
// Test si fichier dans r<>pertoire de la langue alternative
|
|
|
|
|
|
if ($this->defaultlang != "en_US") $htmlfilealt = $this->dir."/en_US/".$filename;
|
|
|
|
|
|
else $htmlfilealt = $this->dir."/fr_FR/".$filename;
|
2005-10-30 02:07:00 +01:00
|
|
|
|
if (is_readable($htmlfilealt))
|
|
|
|
|
|
{
|
2005-05-14 00:43:56 +02:00
|
|
|
|
include $htmlfilealt;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-05-02 12:33:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|