Translate
class Translate (View source)
Class to manage translations
Properties
| string[] | $dir | ||
| string | $defaultlang | ||
| string | $shortlang | ||
| string | $charset_output | ||
| array<string, string> | $tab_translate | ||
| array<string, array<string, string>> | $cache_labels | ||
| array<string, array{label: string, unicode: string}> | $cache_currencies | ||
| string | $origlang | ||
| $error | |||
| string[] | $errors |
Methods
Set accessor for this->defaultlang
Return active language code for current user It's an accessor for this->defaultlang
Load translation files.
Load translation key-value for a particular file, into a memory array.
Get information with result of loading data for domain
Return text translated of text received as parameter (and encode it into HTML) If there is no match for this text, we look in alternative file and if still not found, it is returned as it is.
Return translated value of a text string If there is no match for this text, we look in alternative file and if still not found it is returned as is.
Return translated value of a text string If there is no match for this text, we look in alternative file and if still not found, it is returned as is.
Return translated value of a text string. Alias of tr() for backward compatibility.
Return translation of a key depending on country
Retourne la version traduite du texte passe en parameter complete du code pays
Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client)
Return list of all available languages
Return if a filename $filename exists for current language (or alternate language)
Return full text translated to language label for a key. Store key-label in a cache.
Return a label for a key.
Return a currency code into its symbol
Return a currency code into its symbol.
Load into the cache this->cache_currencies, all currencies
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)
Details
__construct($dir, Conf $conf)
Constructor
@param string $dir Force directory that contains /langs subdirectory (value is sometimes '..' like into install/ pages or support/ pages). Use '' by default.
void
setDefaultLang($srclang = 'en_US')
Set accessor for this->defaultlang
@param string $srclang Language to use. If '' or 'auto', we use browser lang.
string
getDefaultLang($mode = 0)
Return active language code for current user It's an accessor for this->defaultlang
@param int $mode 0=Long language code, 1=Short language code (en, fr, es, ...)
int
loadLangs($domains)
Load translation files.
@param string[] $domains Array of lang files to load
int
load(string $domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = '', $loadfromfileonly = 0, $forceloadifalreadynotfound = 0, $tabtranslatedomain = [], $langkey = '')
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
int
loadFromDatabase(DoliDB $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
int
isLoaded(string $domain)
Get information with result of loading data for domain
trans(string $key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', int $maxsize = 0)
Return text translated of text received as parameter (and encode it into HTML) If there is no match for this text, we look in alternative file and if still not found, it is returned as it is.
The parameters of this method should not contain HTML tags. If there is, they will be htmlencoded to have no effect.
transnoentities(string $key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '')
Return translated value of a text string If there is no match for this text, we look in alternative file and if still not found it is returned as is.
Parameters of this method must not contain any HTML tags.
tr(string $key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '')
Return translated value of a text string If there is no match for this text, we look in alternative file and if still not found, it is returned as is.
No conversion to encoding charset of lang object is done. Parameters of this method must not contains any HTML tags.
transnoentitiesnoconv(string $key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '')
Return translated value of a text string. Alias of tr() for backward compatibility.
If there is no match for this text, we look in alternative file and if still not found, it is returned as is. No conversion to encoding charset of lang object is done. Parameters of this method must not contains any HTML tags.
transcountry($str, string $countrycode)
Return translation of a key depending on country
@param string $str String root to translate. Example 'TotalHT', 'AmountLT1', 'ProfId1', 'ProfId2', 'LocalTax1IsUsedExample', ...
transcountrynoentities($str, string $countrycode)
Retourne la version traduite du texte passe en parameter complete du code pays
@param string $str string root to translate
convToOutputCharset($str, string $pagecodefrom = 'UTF-8', $pagecodeto = '')
Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client)
@param string $str String to convert
get_available_languages($langdir = DOL_DOCUMENT_ROOT, int $maxlength = 0, $usecode = 0, $mainlangonly = 0)
Return list of all available languages
@param string $langdir Directory to scan
file_exists($filename, int $searchalt = 0)
Return if a filename $filename exists for current language (or alternate language)
@param string $filename Language filename to search
getLabelFromNumber(int|string $number, $isamount = '')
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).
getLabelFromKey(DoliDB $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.
getCurrencyAmount($currency_code, string $amount)
Return a currency code into its symbol
@param string $currency_code Currency Code
getCurrencySymbol(string $currency_code = '', $forceloadall = 0)
Return a currency code into its symbol.
If mb_convert_encoding is not available, return currency code.
loadCacheCurrencies(string $currency_code)
Load into the cache this->cache_currencies, all currencies
array<string, string>
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)