dolibarr
9.0.0
|
Class to manage translations. More...
Public Member Functions | |
__construct ($dir, $conf) | |
Constructor. More... | |
setDefaultLang ($srclang='en_US') | |
Set accessor for this->defaultlang. More... | |
getDefaultLang ($mode=0) | |
Return active language code for current user It's an accessor for this->defaultlang. More... | |
loadLangs ($domains) | |
Load translation files. More... | |
load ($domain, $alt=0, $stopafterdirection=0, $forcelangdir='', $loadfromfileonly=0) | |
Load translation key-value for a particular file, into a memory array. More... | |
loadFromDatabase ($db) | |
Load translation key-value from database into a memory array. More... | |
trans ($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0) | |
Return text translated of text received as parameter (and encode it into HTML) Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif et si toujours pas trouve, il est retourne tel quel Les parametres de cette methode peuvent contenir de balises HTML. More... | |
transnoentities ($key, $param1='', $param2='', $param3='', $param4='', $param5='') | |
Return translated value of a text string Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif et si toujours pas trouve, il est retourne tel quel. More... | |
transnoentitiesnoconv ($key, $param1='', $param2='', $param3='', $param4='', $param5='') | |
Return translated value of a text string Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif et si toujours pas trouve, il est retourne tel quel. More... | |
transcountry ($str, $countrycode) | |
Return translation of a key depending on country. More... | |
transcountrynoentities ($str, $countrycode) | |
Retourne la version traduite du texte passe en parametre complete du code pays. More... | |
convToOutputCharset ($str, $pagecodefrom='UTF-8') | |
Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client) More... | |
get_available_languages ($langdir=DOL_DOCUMENT_ROOT, $maxlength=0, $usecode=0) | |
Return list of all available languages. More... | |
file_exists ($filename, $searchalt=0) | |
Return if a filename $filename exists for current language (or alternate language) More... | |
getLabelFromNumber ($number, $isamount=0) | |
Return full text translated to language label for a key. More... | |
getLabelFromKey ($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect='', $filteronentity=0) | |
Return a label for a key. More... | |
getCurrencyAmount ($currency_code, $amount) | |
Return a currency code into its symbol. More... | |
getCurrencySymbol ($currency_code, $forceloadall=0) | |
Return a currency code into its symbol. More... | |
loadCacheCurrencies ($currency_code) | |
Load into the cache this->cache_currencies, all currencies. More... | |
get_translations_for_substitutions () | |
Return an array with content of all loaded translation keys (found into this->tab_translate) so we get a substitution array we can use for substitutions (for mail or ODT generation for example) More... | |
Private Member Functions | |
getTradFromKey ($key) | |
Return translated value of key for special keys ("Currency...", "Civility...", ...). More... | |
Class to manage translations.
Definition at line 30 of file translate.class.php.
Translate::__construct | ( | $dir, | |
$conf | |||
) |
Constructor.
string | $dir | Force directory that contains /langs subdirectory (value is sometimes '..' like into install/* pages or support/* pages). Use '' by default. |
Conf | $conf | Object with Dolibarr configuration |
Definition at line 51 of file translate.class.php.
Translate::convToOutputCharset | ( | $str, | |
$pagecodefrom = 'UTF-8' |
|||
) |
Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client)
string | $str | String to convert |
string | $pagecodefrom | Page code of src string |
Definition at line 750 of file translate.class.php.
Translate::file_exists | ( | $filename, | |
$searchalt = 0 |
|||
) |
Return if a filename $filename exists for current language (or alternate language)
string | $filename | Language filename to search |
integer | $searchalt | Search also alernate language file |
Definition at line 807 of file translate.class.php.
Translate::get_available_languages | ( | $langdir = DOL_DOCUMENT_ROOT , |
|
$maxlength = 0 , |
|||
$usecode = 0 |
|||
) |
Return list of all available languages.
string | $langdir | Directory to scan |
integer | $maxlength | Max length for each value in combo box (will be truncated) |
int | $usecode | 1=Show code instead of country name for language variant, 2=Show only code |
Definition at line 767 of file translate.class.php.
Translate::get_translations_for_substitutions | ( | ) |
Return an array with content of all loaded translation keys (found into this->tab_translate) so we get a substitution array we can use for substitutions (for mail or ODT generation for example)
Definition at line 1031 of file translate.class.php.
Translate::getCurrencyAmount | ( | $currency_code, | |
$amount | |||
) |
Return a currency code into its symbol.
string | $currency_code | Currency Code |
string | $amount | If not '', show currency + amount according to langs ($10, 10€). |
Definition at line 934 of file translate.class.php.
Translate::getCurrencySymbol | ( | $currency_code, | |
$forceloadall = 0 |
|||
) |
Return a currency code into its symbol.
If mb_convert_encoding is not available, return currency code.
string | $currency_code | Currency code |
integer | $forceloadall | 1=Force to load all currencies into cache. We know we need to use all of them. By default read and cache only required currency. |
Definition at line 950 of file translate.class.php.
References loadCacheCurrencies().
Translate::getDefaultLang | ( | $mode = 0 | ) |
Return active language code for current user It's an accessor for this->defaultlang.
int | $mode | 0=Long language code, 1=Short language code (en, fr, es, ...) |
Definition at line 135 of file translate.class.php.
Translate::getLabelFromKey | ( | $db, | |
$key, | |||
$tablename, | |||
$fieldkey, | |||
$fieldlabel, | |||
$keyforselect = '' , |
|||
$filteronentity = 0 |
|||
) |
Return a label for a key.
Search into translation array, then into cache, then if still not found, search into database. Store key-label found into cache variable $this->cache_labels to save SQL requests to get labels.
DoliDB | $db | Database handler |
string | $key | Translation key to get label (key in language file) |
string | $tablename | Table name without prefix |
string | $fieldkey | Field for key |
string | $fieldlabel | Field for label |
string | $keyforselect | Use another value than the translation key for the where into select |
int | $filteronentity | Use a filter on entity |
Definition at line 882 of file translate.class.php.
Translate::getLabelFromNumber | ( | $number, | |
$isamount = 0 |
|||
) |
Return full text translated to language label for a key.
Store key-label in a cache. This function need module "numberwords" to be installed. If not it will return same number (this module is not provided by default as it use non GPL source code).
int | $number | Number to encode in full text |
int | $isamount | 1=It's an amount, 0=it's just a number |
Definition at line 839 of file translate.class.php.
|
private |
Return translated value of key for special keys ("Currency...", "Civility...", ...).
Search in lang file, then into database. Key must be any complete entry into lang file: CurrencyEUR, ... If not found, return key. The string return is not formated (translated with transnoentitiesnoconv) NOTE: To avoid infinite loop (getLabelFromKey->transnoentities->getTradFromKey), if you modify this function, check that getLabelFromKey is not called with same value than input.
string | $key | Key to translate |
Definition at line 540 of file translate.class.php.
Translate::load | ( | $domain, | |
$alt = 0 , |
|||
$stopafterdirection = 0 , |
|||
$forcelangdir = '' , |
|||
$loadfromfileonly = 0 |
|||
) |
Load translation key-value for a particular file, into a memory array.
If data for file already loaded, do nothing. All data in translation array are stored in UTF-8 format. tab_loaded is completed with $domain key. rule "we keep first entry found with we keep last entry found" so it is probably not what you want to do.
Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
string | $domain | File name to load (.lang file). Must be "file" or "file@module" for module language files: If $domain is "file@module" instead of "file" then we look for module lang file in htdocs/custom/modules/mymodule/langs/code_CODE/file.lang then in htdocs/module/langs/code_CODE/file.lang instead of htdocs/langs/code_CODE/file.lang |
integer | $alt | 0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US) |
int | $stopafterdirection | Stop when the DIRECTION tag is found (optimize speed) |
int | $forcelangdir | To force a different lang directory |
int | $loadfromfileonly | 1=Do not load overwritten translation from file or old conf. |
Read each lines until a '=' (with any combination of spaces around it) and split the rest until a line feed. This is more efficient than fgets + explode + trim by a factor of ~2.
Definition at line 176 of file translate.class.php.
Referenced by loadLangs().
Translate::loadCacheCurrencies | ( | $currency_code | ) |
Load into the cache this->cache_currencies, all currencies.
string | $currency_code | Get only currency. Get all if ''. |
Definition at line 976 of file translate.class.php.
Referenced by getCurrencySymbol().
Translate::loadFromDatabase | ( | $db | ) |
Load translation key-value from database into a memory array.
If data already loaded, do nothing. All data in translation array are stored in UTF-8 format. tab_loaded is completed with $domain key. rule "we keep first entry found with we keep last entry found" so it is probably not what you want to do.
Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
Definition at line 402 of file translate.class.php.
Translate::loadLangs | ( | $domains | ) |
Load translation files.
array | $domains | Array of lang files to load |
Definition at line 148 of file translate.class.php.
References load().
Translate::setDefaultLang | ( | $srclang = 'en_US' | ) |
Set accessor for this->defaultlang.
string | $srclang | Language to use. If '' or 'auto', we use browser lang. |
Definition at line 65 of file translate.class.php.
Translate::trans | ( | $key, | |
$param1 = '' , |
|||
$param2 = '' , |
|||
$param3 = '' , |
|||
$param4 = '' , |
|||
$maxsize = 0 |
|||
) |
Return text translated of text received as parameter (and encode it into HTML) Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif et si toujours pas trouve, il est retourne tel quel Les parametres de cette methode peuvent contenir de balises HTML.
string | $key | Key to translate |
string | $param1 | chaine de param1 |
string | $param2 | chaine de param2 |
string | $param3 | chaine de param3 |
string | $param4 | chaine de param4 |
int | $maxsize | Max length of text |
Definition at line 597 of file translate.class.php.
Referenced by transcountry().
Translate::transcountry | ( | $str, | |
$countrycode | |||
) |
Return translation of a key depending on country.
string | $str | string root to translate |
string | $countrycode | country code (FR, ...) |
Definition at line 722 of file translate.class.php.
References trans().
Translate::transcountrynoentities | ( | $str, | |
$countrycode | |||
) |
Retourne la version traduite du texte passe en parametre complete du code pays.
string | $str | string root to translate |
string | $countrycode | country code (FR, ...) |
Definition at line 736 of file translate.class.php.
References transnoentities().
Translate::transnoentities | ( | $key, | |
$param1 = '' , |
|||
$param2 = '' , |
|||
$param3 = '' , |
|||
$param4 = '' , |
|||
$param5 = '' |
|||
) |
Return translated value of a text string Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif et si toujours pas trouve, il est retourne tel quel.
Parameters of this method must not contains any HTML tags.
string | $key | Key to translate |
string | $param1 | chaine de param1 |
string | $param2 | chaine de param2 |
string | $param3 | chaine de param3 |
string | $param4 | chaine de param4 |
string | $param5 | chaine de param5 |
Definition at line 658 of file translate.class.php.
Referenced by transcountrynoentities().
Translate::transnoentitiesnoconv | ( | $key, | |
$param1 = '' , |
|||
$param2 = '' , |
|||
$param3 = '' , |
|||
$param4 = '' , |
|||
$param5 = '' |
|||
) |
Return translated value of a text string Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif et si toujours pas trouve, il est retourne tel quel.
No convert to encoding charset of lang object is done. Parameters of this method must not contains any HTML tags.
string | $key | Key to translate |
string | $param1 | chaine de param1 |
string | $param2 | chaine de param2 |
string | $param3 | chaine de param3 |
string | $param4 | chaine de param4 |
string | $param5 | chaine de param5 |
Definition at line 679 of file translate.class.php.