Objectifs

On veut écrire une application multilingue pour s'adapter à l'utilisateur, ou bien on veut permettre la traduction d'une application en limitant l'effort à fournir.

Solution

En utilisant un dictionnaire de messages, on peut rassembler tous les messages dans un seul script, et créer des version traduites. Pour les gros messages, utiliser la syntaxe "here doc" pour améliorer la lisibilité.

De plus, en choisissant dès le départ l'encodage utf-8, on évite les problèmes d'encodages disparates.

Code Source

<?
/*
(c)2004 David Sporn

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 2.1 as published by the Free Software Foundation.

This library 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 library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

$messages = array();
//Error messages
$messages["ERROR_MYSQL_CONNECT"] = "Impossible de se connecter.";
$messages["ERROR_MYSQL_SELECT_DB"] = "Impossible de choisir la base.";
$messages["ERROR_QUERY_DO_NOT_EXIST"] = "L'objet demand&eacute; n'existe pas.";
$messages["ERROR_NO_DATA"] = "Pas de donn&eacute;es." ;

//App title
$messages["TITLE"] = "VirtualPage Manager v0.2.0";

//Action Label
$messages["LABEL_GOTO_EDIT"] = "Modifier";
$messages["LABEL_GOTO_NEW"] = "Ajouter une page";
$messages["LABEL_GOTO_VIEW"] = "Retour &agrave; la liste";
$messages["LABEL_GOTO_DELETE"] = "Supprimer";
$messages["LABEL_GOTO_PREVIEW"] = "Pr&eacute;visualiser";
$messages["LABEL_GOTO_RESUME"] = "Reprendre";

//Directions
$messages["DIRECTION_CONFIRM_DELETE"] = "Confirmer la suppression en cliquant sur \"Supprimer\".";
$messages["DIRECTION_COPYRIGHT"] = "&copy;2004 David Sporn";
$messages["DIRECTION_LICENSE"] = <<< EOF
<p>Ce logiciel est libre; vous pouvez le redistribuer et/ou le
modifier selon les termes du contrat GNU General Public License
version 2.1 tel qu'il est publi&eacute; par la Free Software Foundation.
</p>
<p>Ce logiciel est distribu&eacute; dans l'espoir qu'il se 
r&eacute;v&egrave;lera utile, mais SANS AUCUNE GARANTIE; pas m&ecirc;me
une garantie implicite de COMMERCIABILIT&Eacute; ou d'AD&Eacute;QUATION 
&Agrave; UN BUT PARTICULIER. Pour plus de d&eacute;tails, consultez le
contrat GNU General Public License.
</p>
<p>Vous devez avoir re&ccedil;u un exemplaire du contrat GNU General Public License
avec ce logiciel; sinon, &eacute;crivez &agrave; la Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
</p>
EOF;
$messages["DIRECTION_BROWSER"] = <<< EOF
Visuellement optimal avec un navigateur respectant 
<strong>compl&egrave;tement</strong> les standards 
<a href="http://validator.w3.org/check/referer">XHTML 1.0</a>, 
<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS 2.1</a> 
et <a href="http://www.w3.org/Graphics/PNG/">PNG</a>.
EOF;

//Form fields
$messages["FORM_TITLE"] = "Fiche VirtualPage";
$messages["FORM_ENTRY"] = "Url";
$messages["FORM_LABEL"] = "Libell&eacute;";
$messages["FORM_DATA"] = "Data";
$messages["FORM_MENU"] = "Menu";
$messages["FORM_FIRST"] = "Premi&egrave;re page";
$messages["FORM_PREVIOUS"] = "Page pr&eacute;c&eacute;dente";
$messages["FORM_NEXT"] = "Page suivante";
$messages["FORM_LAST"] = "Derni&egrave;re page";
$messages["FORM_TYPE"] = "Type";
$messages["FORM_TYPE_VALUE_0"] = "Code XHTML";
$messages["FORM_TYPE_VALUE_1"] = "Code PHP";
$messages["FORM_TYPE_VALUE_2"] = "Url externe";
$messages["FORM_SUBMIT"] = "Envoyer";
$messages["FORM_PREVIEW"] = "Pr&eacute;visualisation";

?>