dolibarr/htdocs/translate.class.php

160 lines
5.2 KiB
PHP
Raw Normal View History

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$
*/
2005-01-02 17:57:37 +01:00
/**
\class Translate
\brief Classe permettant de g<EFBFBD>rer les traductions
*/
class Translate {
var $tab_loaded=array();
var $tab_translate=array();
2004-07-13 23:25:53 +02:00
var $defaultlang;
var $dir;
var $debug;
2003-05-02 12:33:06 +02:00
/**
2005-01-02 17:57:37 +01:00
* \brief Constructeur de la classe
* \param dir repertoire racine des fichiers de traduction
* \param defaultlang langue par defaut <EFBFBD> utiliser
*/
2004-07-13 23:25:53 +02:00
function Translate($dir = "", $defaultlang = "") {
$this->dir=$dir;
$this->defaultlang=$defaultlang;
$this->tab_translate = array();
2004-07-13 23:25:53 +02:00
}
2003-05-02 12:33:06 +02:00
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
*/
2004-07-13 23:25:53 +02:00
function Load($domain = "main") {
2004-11-15 09:34:15 +01:00
if ($this->tab_loaded[$domain]) { return; } // Ce fichier est deja charg<72>
2003-05-02 12:33:06 +02:00
2004-11-15 09:34:15 +01:00
$scandir = $this->dir."/".$this->defaultlang; // Repertoire de traduction
$scandiralt = $this->dir."/fr_FR"; // Repertoire alternatif
2004-07-13 23:25:53 +02:00
$file_lang = $scandir . "/$domain.lang";
if (! is_file($file_lang)) {
$file_lang = $scandiralt . "/$domain.lang";
}
/* initialize tabs */
$i = 0;
2004-07-13 23:25:53 +02:00
if(is_file($file_lang)) {
//print "Ouverture fichier $file_lang";
if($fp = @fopen($file_lang,"rt")){
$finded = 0;
while (($ligne = fgets($fp,4096)) && ($finded == 0)){
if ($ligne[0] != "\n" && $ligne[0] != " " && $ligne[0] != "#") {
$tab=split('=',$ligne,2);
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
$this->tab_translate[$tab[0]]=trim($tab[1]);
}
}
fclose($fp);
2004-11-15 09:34:15 +01:00
$this->tab_loaded[$domain]=1; // Marque ce fichier comme charg<72>
}
2003-05-02 12:33:06 +02:00
}
2003-05-02 12:33:06 +02: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
*/
function list_domainloaded() {
return join(",",array_keys($this->tab_loaded));
}
/**
* \brief Retourne la version traduite du texte pass<EFBFBD> en param<EFBFBD>tre
2005-01-09 19:08:32 +01:00
* Si il n'y a pas de correspondance pour ce texte, il est retourn<EFBFBD> tel quel
* [en] Return translated version of parameter string
* \param str original string to translate
* \param param1 chaine de param1
* \param param2 chaine de param1
* \param param3 chaine de param1
2005-01-09 19:08:32 +01:00
* \return string chaine traduite
*/
function trans($str, $param1='', $param2='', $param3='') {
if ($this->tab_translate[$str]) {
// Si la traduction est disponible
2004-11-15 09:34:15 +01:00
return sprintf($this->tab_translate[$str],$param1,$param2,$param3);
}
return $str;
}
2004-07-13 23:25:53 +02:00
/**
2005-01-02 17:57:37 +01:00
* \brief Retourne la liste des langues disponibles
* \return array list of languages
*/
function get_available_languages()
{
// On parcour le r<>pertoire langs pour d<>tecter les langues dispo
$handle=opendir(DOL_DOCUMENT_ROOT ."/langs");
$langs_available=array();
while ($file = trim(readdir($handle))){
if($file != "." && $file != ".." && $file != "CVS") {
array_push($langs_available,$file);
}
}
return $langs_available;
2003-05-02 12:33:06 +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
*/
function lang_header()
2003-05-02 12:33:06 +02:00
{
$charset = "iso-8859-1";
//header("Content-Type: text/html; charset=$charset");
$texte .= "<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n";
return $texte;
}
2003-05-02 12:33:06 +02:00
}
?>