Difference between revisions of "Translation system"
m |
|||
Line 7: | Line 7: | ||
= Development rules for internationalization (i18n) = | = Development rules for internationalization (i18n) = | ||
− | In Dolibarr code | + | 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 | + | There are two methods: |
<source lang="ini"> | <source lang="ini"> | ||
$langs->trans('TRAD_STRING'); | $langs->trans('TRAD_STRING'); | ||
</source> | </source> | ||
− | This | + | 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"> | <source lang="ini"> | ||
$langs->transnoentitiesnoconv('TRAD_STRING'); | $langs->transnoentitiesnoconv('TRAD_STRING'); | ||
</source> | </source> | ||
− | This method | + | 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 | + | 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"> | <source lang="ini"> |
Revision as of 20:11, 13 September 2018
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