Difference between revisions of "Translation system"

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
m
m
Tag: 2017 source edit
 
(2 intermediate revisions by 2 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}}
  
Line 7: Line 15:
  
 
= Development rules for internationalization (i18n) =
 
= Development rules for internationalization (i18n) =
In Dolibarr code source, translations are made by using a method available on object $langs with the key to translate as parameter of this method. The $langs object contains definition of use language. This object is always defined in all pages.
+
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 is 2 methods:
+
There are two methods:
<source lang="ini">
+
<syntaxHighlight lang="ini">
 
  $langs->trans('TRAD_STRING');
 
  $langs->trans('TRAD_STRING');
</source>
+
</syntaxHighlight>
This methode return translation of key TRAD_STRING, and encode result into HTML entities to allow to output it correctly (even with special characters) into an HTML page.
+
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.
<source lang="ini">
+
<syntaxHighlight lang="ini">
 
  $langs->transnoentitiesnoconv('TRAD_STRING');
 
  $langs->transnoentitiesnoconv('TRAD_STRING');
</source>
+
</syntaxHighlight>
This method return translation of key TRAD_STRING, but result is translated string with no particular encoding (string is stored in UTF-8 in memory).
+
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).
  
This 2 methods can accept arguments that will be used to replaced strings %s found in resulted translated string.
+
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 itslef a translated string, you must use method $langs->transnoentitiesnoconv, otherwise string will be encoded twice.
+
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:
 
Example:
<source lang="ini">
+
<syntaxHighlight lang="ini">
 
  print $langs->trans("STRING_TO_TRANSLATE",$langs->transnoentitiesnoconv("STRING_PARAM1"))
 
  print $langs->trans("STRING_TO_TRANSLATE",$langs->transnoentitiesnoconv("STRING_PARAM1"))
</source>
+
</syntaxHighlight>
  
 
= Translate Dolibarr into another language =
 
= Translate Dolibarr into another language =
 
See page [[Translator documentation]]
 
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