Difference between revisions of "Translation system"

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
(Created page with '{{TemplateDocDevEn}} {{ToTranslate}} == Principe développement == Dans le code les traductions se font par appel de methode sur l'objet $langs avec en paramètre la clé de la ...')
 
m
Tag: 2017 source edit
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<!-- BEGIN origin interlang links -->
 +
<!-- You can edit this section but do NOT remove these comments
 +
    Links below will be automatically replicated on translated pages by PolyglotBot -->
 +
[[fr:Système_de_traduction]]
 +
[[es:Sistema_de_traducción]]
 +
[[zh:翻译]]
 +
<!-- END interlang links -->
 +
 
{{TemplateDocDevEn}}
 
{{TemplateDocDevEn}}
{{ToTranslate}}
 
  
== Principe développement ==
 
Dans le code les traductions se font par appel de methode sur l'objet $langs avec en paramètre la clé de la chaine à traduire. lo'bjet $langs contient la définition de la langue de l'utilisateur. Il est définit dans toutes les pages.
 
  
On trouve 2 méthodes:
 
* $langs->trans('TRAD_STRING');
 
Cette méthode renvoi la traduction de l'entrée TRAD_STRING, tout en codant le résultat en entities HTML pour permettre un affichage des caractères spéciaux correct dans une page HTML.
 
* $langs->transnoentities('TRAD_STRING');
 
Cette méthode renvoi la traduction de l'entrée TRAD_STRING, mais ne code pas le résultat.
 
  
Ces 2 méthodes peuvent accepter des arguments complémentaires qui sont substitués aux valeurs %s dans la chaine résultante de la traduction.
 
  
  
Note: Si en paramètre, on met un résultat de traduction, il convient que ce résultat soit renvoyé par la fonction $langs->transnoentities, sinon il sera codé en HTML puis le sera une deuxième fois par l'appel $langs->trans initiale. Exemple:
 
print $langs->trans("STRING_TO_TRANSLATE",$langs->transnoentities("STRING_PARAM1"))
 
  
 +
= Development rules for internationalization (i18n) =
 +
In Dolibarr code, translations are made by using a method available in object $langs with the key to translate as a parameter of this method. The $langs object contains definition of use language. This object is always defined in all pages.
 +
 +
There are two methods:
 +
<syntaxHighlight lang="ini">
 +
$langs->trans('TRAD_STRING');
 +
</syntaxHighlight>
 +
This method returns the translation of key TRAD_STRING, and encodes the result into HTML entities to allow to display correctly (even with special characters) on an HTML page.
 +
<syntaxHighlight lang="ini">
 +
$langs->transnoentitiesnoconv('TRAD_STRING');
 +
</syntaxHighlight>
 +
This method returns the translation of key TRAD_STRING, but the result is the translated string with no particular encoding (string is stored in UTF-8 in memory).
 +
 +
These two methods can accept arguments that will be used to replace strings %s in the translated string.
 +
 +
 +
Note: If, as arguments, you use a string that is itself a translated string, you must use method $langs->transnoentitiesnoconv, otherwise the string will be encoded twice.
 +
Example:
 +
<syntaxHighlight lang="ini">
 +
print $langs->trans("STRING_TO_TRANSLATE",$langs->transnoentitiesnoconv("STRING_PARAM1"))
 +
</syntaxHighlight>
  
== Traduire Dolibarr dans une autre langue ==
+
= Translate Dolibarr into another language =
Voir la page [http://www.dolibarr.com/wikidev/index.php/Documentation_traducteur Documentation_traducteur]
+
See page [[Translator documentation]]

Latest revision as of 22:26, 25 May 2021





Development rules for internationalization (i18n)

In Dolibarr code, translations are made by using a method available in object $langs with the key to translate as a parameter of this method. The $langs object contains definition of use language. This object is always defined in all pages.

There are two methods:

 $langs->trans('TRAD_STRING');

This method returns the translation of key TRAD_STRING, and encodes the result into HTML entities to allow to display correctly (even with special characters) on an HTML page.

 $langs->transnoentitiesnoconv('TRAD_STRING');

This method returns the translation of key TRAD_STRING, but the result is the translated string with no particular encoding (string is stored in UTF-8 in memory).

These two methods can accept arguments that will be used to replace strings %s in the translated string.


Note: If, as arguments, you use a string that is itself a translated string, you must use method $langs->transnoentitiesnoconv, otherwise the string will be encoded twice. Example:

 print $langs->trans("STRING_TO_TRANSLATE",$langs->transnoentitiesnoconv("STRING_PARAM1"))

Translate Dolibarr into another language

See page Translator documentation