From 4229deba6bb340ec8f01aca387e9bd2ed810a7f8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Jul 2004 21:25:53 +0000 Subject: [PATCH] Gestion multi-lingues --- htdocs/langs/en | 21 ---------- htdocs/langs/en_US/main.lang | 10 +++++ htdocs/langs/en_US/soc.lang | 21 ++++++++++ htdocs/langs/fr | 5 --- htdocs/langs/fr_FR/main.lang | 10 +++++ htdocs/langs/fr_FR/soc.lang | 21 ++++++++++ htdocs/main.inc.php | 46 ++++++++++++--------- htdocs/pre.inc.php | 2 +- htdocs/soc.php | 44 +++++++++++--------- htdocs/translate.class.php | 78 +++++++++++------------------------- 10 files changed, 139 insertions(+), 119 deletions(-) delete mode 100644 htdocs/langs/en create mode 100644 htdocs/langs/en_US/main.lang create mode 100644 htdocs/langs/en_US/soc.lang delete mode 100644 htdocs/langs/fr create mode 100644 htdocs/langs/fr_FR/main.lang create mode 100644 htdocs/langs/fr_FR/soc.lang diff --git a/htdocs/langs/en b/htdocs/langs/en deleted file mode 100644 index 9ef83c408b4..00000000000 --- a/htdocs/langs/en +++ /dev/null @@ -1,21 +0,0 @@ -#do not change next line please ! -charset="iso-8859-1" - -# Menus -Société=Company - -# Fiches sociétés -Adresse=Address -Téléphone=Phone - -# Utilisateurs -Auteur=Author -Utilisateur=User - -# Autre -Choisissez votre langue=Please choose your language -Ajouter=Add -Supprimer=Delete -Factures=Bills -Facture=Bill -Payé=Payed diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang new file mode 100644 index 00000000000..8f08fe81178 --- /dev/null +++ b/htdocs/langs/en_US/main.lang @@ -0,0 +1,10 @@ +# Dolibarr language file - fr_FR - main +charset="iso-8859-1" +Add=Ajouter +Delete=Supprimer +Cancel=Annuler +Modify=Modifier +Edit=Editer +ChooseLangage=Please choose your language +User=User +Group=Group diff --git a/htdocs/langs/en_US/soc.lang b/htdocs/langs/en_US/soc.lang new file mode 100644 index 00000000000..b548c4cb4c0 --- /dev/null +++ b/htdocs/langs/en_US/soc.lang @@ -0,0 +1,21 @@ +# Dolibarr language file - fr_FR - soc +NewCompany=New company (prospect, customer, supplier) +Company=Company +Name=Name +Surname=Surname +Address=Addrese +State=State +Country=Country +Phone=Phone +Fax=Fax +Zip=Zip Code +Town=Town +Web=Web +ProfIdSiren=Professional ID +ProfIdSiret=Professional ID +ProfIdApe=APE +TVAIntra=Intracommunautary VAT +ProspectCustomer=Prospect / Customer +Prospect=Prospect +Customer=Customer +Supplier=Supplier \ No newline at end of file diff --git a/htdocs/langs/fr b/htdocs/langs/fr deleted file mode 100644 index ba3a1021568..00000000000 --- a/htdocs/langs/fr +++ /dev/null @@ -1,5 +0,0 @@ -#do not change next line please ! -charset="iso-8859-1" - -# Le fichier de langue pour le francais n'a pas besoin d'etre rempli pour l'instant -# Sa presence suffit diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang new file mode 100644 index 00000000000..974ffaef2e1 --- /dev/null +++ b/htdocs/langs/fr_FR/main.lang @@ -0,0 +1,10 @@ +# Dolibarr language file - fr_FR - main +charset="iso-8859-1" +Add=Ajouter +Delete=Supprimer +Cancel=Annuler +Modify=Modifier +Edit=Editer +ChooseLangage=Please choose your language +User=Utilisateur +Group=Groupe diff --git a/htdocs/langs/fr_FR/soc.lang b/htdocs/langs/fr_FR/soc.lang new file mode 100644 index 00000000000..f098c2cc59b --- /dev/null +++ b/htdocs/langs/fr_FR/soc.lang @@ -0,0 +1,21 @@ +# Dolibarr language file - fr_FR - soc +NewCompany=Nouvelle société (prospect, client, fournisseur) +Company=Société +Name=Nom +Surname=Prénom +Address=Adresse +State=Département/Province/Canton +Country=Pays +Phone=Téléphone +Fax=Fax +Zip=Code postal +Town=Ville +Web=Web +ProfIdSiren=SIREN +ProfIdSiret=SIRET +ProfIdApe=APE +TVAIntra=Numéro de TVA Intracommunautaire +ProspectCustomer=Prospect / Client +Prospect=Prospect +Customer=Client +Supplier=Fournisseur \ No newline at end of file diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 58d59328948..6546214e419 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -152,13 +152,15 @@ else require (DOL_DOCUMENT_ROOT ."/product.class.php"); require (DOL_DOCUMENT_ROOT ."/menu.class.php"); require (DOL_DOCUMENT_ROOT ."/societe.class.php"); -require (DOL_DOCUMENT_ROOT ."/translate.class.php"); require (DOL_DOCUMENT_ROOT ."/boxes.php"); require (DOL_DOCUMENT_ROOT ."/address.class.php"); require (DOL_DOCUMENT_ROOT ."/notify.class.php"); require (DOL_DOCUMENT_ROOT ."/includes/fpdf/fpdf152/fpdf.php"); + + define('FPDF_FONTPATH',DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf152/font/'); + /* * Definition de toutes les Constantes globales d'environement * @@ -177,13 +179,32 @@ if ($result) $i++; } } + +/* + * Positionne le langage et localisation dans $conf->langage + * et charge l'objet de traduction + */ +if (! defined(MAIN_LANG_DEFAULT)) +{ + define(MAIN_LANG_DEFAULT,"fr_FR"); +} +$conf->langage=MAIN_LANG_DEFAULT; + +// On corrige $conf->language si il ne vaut pas le code long: fr_FR par exemple +if (strlen($conf->language) <= 3) { + $conf->langage = strtolower($conf->langage)."_".strtoupper($conf->langage); +} +setlocale(LC_ALL, $conf->language); +//setlocale(LC_TIME, $conf->language); + +require (DOL_DOCUMENT_ROOT ."/translate.class.php"); +$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs", $conf->langage); + + + /* - * * */ - -//$db->close(); - if (defined("MAIN_NOT_INSTALLED")) { Header("Location: install.php"); @@ -389,20 +410,6 @@ if (defined("MAIN_MAIL_NEW_SUBJECT")) } -/* - * Positionne le langage dans $conf->langage - */ -if (! defined(MAIN_LANG_DEFAULT)) -{ - define(MAIN_LANG_DEFAULT,"fr"); -} -$conf->langage=MAIN_LANG_DEFAULT; -$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs", $conf->langage, $conf->langage, $conf->langage); - -$lc=strtolower($conf->langage)."_".strtoupper($conf->langage); // lc vaut fr_FR par exemple -setlocale(LC_TIME, $lc); - - /* */ $bc[0]="class=\"impair\""; @@ -421,6 +428,7 @@ function top_menu($head, $title="", $target="") print ''; print "\n"; + $langs->load("main"); print $langs->lang_header(); print $head; diff --git a/htdocs/pre.inc.php b/htdocs/pre.inc.php index 2b1085e4ab8..b8c2a4f097d 100644 --- a/htdocs/pre.inc.php +++ b/htdocs/pre.inc.php @@ -25,7 +25,7 @@ require ("./main.inc.php"); function llxHeader($head = "") { - global $user, $conf; + global $user, $conf, $langs; $user->getrights('societe'); /* diff --git a/htdocs/soc.php b/htdocs/soc.php index e515d573563..2faa2d668ae 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -24,6 +24,10 @@ require("pre.inc.php"); +$langs->load("soc"); + + + /* * Sécurité accés client */ @@ -72,8 +76,9 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update') llxHeader(); $form = new Form($db); -if ($_GET["action"] == 'create' && $user->rights->societe->creer) +if ($_GET["action"] == 'create') { + if ($user->rights->societe->creer) { /* * Fiche societe en mode création */ @@ -82,35 +87,35 @@ if ($_GET["action"] == 'create' && $user->rights->societe->creer) if ($_GET["type"]=='c') { $soc->client=1; } if ($_GET["type"]=='p') { $soc->client=2; } - print '
Nouvelle société (prospect, client, fournisseur)

'; + print '
'.$langs->trans("NewCompany").'

'; print '
'; print ''; print ''; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; - print ''; - print ''; - print ''; + print ''; print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; print ''; print ''; - print ''; - print ''; - print ''; - print ''; + print ''; print '
Nom
'.$langs->trans('Adresse').'
CP '; - print 'Ville 
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').' '; + print $langs->trans('Town').' Département/Province/Canton'; + print ''.$langs->trans('State').''; print $form->select_departement($soc->departement_id); print '
Pays'; + print '
'.$langs->trans('Country').''; print $form->select_pays($soc->pays_id); print '
'.$langs->trans('Téléphone').'
'.$langs->trans('Phone').''.$langs->trans('Fax').'
Webhttp://
'.$langs->trans('Web').'http://
Siren
'.$langs->trans('ProfIdSiren').'Siret
'.$langs->trans('ProfIdSiret').'
Ape
'.$langs->trans('Ape').'Capital '.MAIN_MONNAIE.'
Forme juridique'; @@ -121,26 +126,27 @@ if ($_GET["action"] == 'create' && $user->rights->societe->creer) print $form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id); print '
Numéro de TVA Intracommunautaire'; + print '
'.$langs->trans('TVAIntra').''; print ''; print ''; print '
Vous pouvez vérifier ce numéro sur le site de la commission européenne'; print '
Prospect / Client
'.$langs->trans('ProspectCustomer').'Fournisseur'.$langs->trans('Supplier').'
'; print '
'; + } } elseif ($_GET["action"] == 'edit') { diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php index a1c5b078170..c8ba6377527 100644 --- a/htdocs/translate.class.php +++ b/htdocs/translate.class.php @@ -16,71 +16,40 @@ * 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. - * *************************************************************************** - * File : translate.class.php - * Author : Eric SEIGNE - * mailto:erics@rycks.com - * http://www.rycks.com/ - * Date : 09/09/2001 - * Licence : GNU/GPL Version 2 ou plus - * Modif : Rodolphe Quiedeville - * - * Description: - * ------------ - * - * - * - * @version 1.0 - * @author Eric Seigne - * @project AbulEdu - * @copyright Eric Seigne 09/09/2001 - * * ************************************************************************* */ Class Translate { - var $tab_langs; + var $tab_loaded; var $tab_translate; - var $file_lang; - /** Default language interface (isocode) */ - var $defaultiso; - /** Source language (isocode) */ - var $sourceiso; - /** This session language (isocode) */ - var $sessioniso; - /** Where are languages files ? */ + + var $defaultlang; var $dir; var $debug; - //------------------------------------------------- - /** Constructor */ - function Translate($dir = "", $sourceiso = "", $defaultiso = "", $sessioniso = "") - { - $this->tab_langs = array(); + function Translate($dir = "", $defaultlang = "") { + $this->dir=$dir; + $this->defaultlang=$defaultlang; + $this->tab_translate = array(); - $this->file_lang = ""; - $this->debug = 0; - $this->dir = $dir; - $this->sessioniso = $sessioniso; - $this->sourceiso = $sourceiso; - $this->defaultiso = $defaultiso; + } + - if ($sessioniso == 'fr') { - // Français demandé, on ne fait rien - return; + function Load($domain = "main") { + if ($this->tab_loaded[$domain]) { return; } # Ce fichier est deja chargé + + $scandir = $this->dir."/".$this->defaultlang; # Repertoire de traduction + $scandiralt = $this->dir."/fr_FR"; # Repertoire alternatif + + $file_lang = $scandir . "/$domain.lang"; + if (! is_file($file_lang)) { + $file_lang = $scandiralt . "/$domain.lang"; } - - //Si on a une langue par defaut - if(($this->defaultiso != "") && ($this->sessioniso == "")) - $this->file_lang = $this->dir . "/" . $this->defaultiso; - else if($this->sessioniso != "") - $this->file_lang = $this->dir . "/" . $this->sessioniso; - + /* initialize tabs */ $i = 0; - if(is_dir($this->dir)) { - $filet = $this->dir . "/" . $sessioniso; - //print "Ouverture fichier $filet"; - if($fp = @fopen($filet,"rt")){ + 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] != "#") { @@ -90,6 +59,7 @@ Class Translate { } } fclose($fp); + $this->tab_loaded[$domain]=1; # Marque ce fichier comme chargé } } @@ -115,7 +85,7 @@ Class Translate { } return $str; } - + /** * Return the list of available languages * [fr] Retourne la liste des langues disponibles