Locale class. More...
Public Member Functions | |
__construct ($lang_file, $lang="auto", $default_lang="en", $cache_dir=false) | |
Constructor. | |
__get ($key) | |
Get a translation key. | |
getIterator () | |
Get the internal iterator. | |
setLang ($lang) | |
Set the current lang. | |
getLang () | |
Get the current lang. | |
conv () | |
Get the localized formats http://php.net/manual/en/function.localeconv.php. | |
date ($time=null) | |
Get date. | |
date2string ($date) | |
Get date human representation. | |
i18n ($key) | |
Use a string format for identifying translations. | |
Data Fields | |
const | CACHE_FILE = 'locale.cache.php' |
Protected Member Functions | |
_generateTree () | |
Generates the translation tree. | |
_cache () | |
Put the dictionnary in cache for later use. | |
_determineLanguage () | |
Determine the nearest available lang according to accepted languages. | |
Static Protected Member Functions | |
static | _getAcceptedLanguages () |
Get accepeted languages using browser capabilities. | |
Protected Attributes | |
$_file | |
Dictionnary file. | |
$_lang | |
Current lang used. | |
$_cache_dir | |
Cache directory (false if cache is disabled) | |
$tree | |
The translations tree. | |
Static Protected Attributes | |
static | $_accepted_languages_cache |
Accepted language cache. |
Locale class.
Definition at line 17 of file axLocale.class.php.
axLocale::__construct | ( | $ | lang_file, |
$ | lang = "auto" , |
||
$ | default_lang = "en" , |
||
$ | cache_dir = false |
||
) |
Constructor.
string | $lang_file | The langs file path, this file MUST be an INI file |
string | $lang | [optional] [default "auto" ] The language to be used or 'auto' to determine it from the browser |
string | $default_lang | [optional] [default "en" ] The default language to use if the $lang isn't found in the dictionnary |
string | $cache_dir | [optional] [default false ] The cache directory (or false if cache is disabled) |
axMissingFileException | If the lang file could not be found |
Definition at line 65 of file axLocale.class.php.
axLocale::__get | ( | $ | key | ) |
Get a translation key.
string | $key |
Definition at line 84 of file axLocale.class.php.
axLocale::_cache | ( | ) | [protected] |
Put the dictionnary in cache for later use.
Does nothing if cache is disabled
void
Definition at line 314 of file axLocale.class.php.
axLocale::_determineLanguage | ( | ) | [protected] |
Determine the nearest available lang according to accepted languages.
Will return false if no corresponding language could be found
Definition at line 376 of file axLocale.class.php.
axLocale::_generateTree | ( | ) | [protected] |
Generates the translation tree.
axMissingFileException | If the file is not found or not readable |
RuntimeException | If the file could not be parsed |
Definition at line 284 of file axLocale.class.php.
static axLocale::_getAcceptedLanguages | ( | ) | [static, protected] |
Get accepeted languages using browser capabilities.
The returned array will be ordered by browser preference (for instance en_US > en_GB > en).
Definition at line 329 of file axLocale.class.php.
axLocale::conv | ( | ) |
Get the localized formats http://php.net/manual/en/function.localeconv.php.
Definition at line 146 of file axLocale.class.php.
axLocale::date | ( | $ | time = null | ) |
Get date.
Will use the current date format to generate a date. The date format must be defined as a string in the dictionnary file (key is date.format
).
integer | $time | [optional] [default null ] |
Definition at line 159 of file axLocale.class.php.
axLocale::date2string | ( | $ | date | ) |
Get date human representation.
For instance "X hours ago" where X is a number determined by the $date
parameter against the current timestamp.
mixed | $date | The date (ymdHi format) or a timestamp |
Definition at line 176 of file axLocale.class.php.
Get the internal iterator.
Definition at line 93 of file axLocale.class.php.
axLocale::i18n | ( | $ | key | ) |
Use a string format for identifying translations.
string | $key | |
mixed | $arg | [optional] You may pass as many arguments as the translation accepts (according to the sprintf syntax) |
Definition at line 251 of file axLocale.class.php.
axLocale::setLang | ( | $ | lang | ) |
Set the current lang.
Returns the current axLocale instance in case of success or false in case of failure.
string | $lang | The lang to be used |
Definition at line 123 of file axLocale.class.php.
array axLocale::$_accepted_languages_cache [static, protected] |
Accepted language cache.
Definition at line 29 of file axLocale.class.php.
string axLocale::$_cache_dir [protected] |
Cache directory (false if cache is disabled)
Definition at line 47 of file axLocale.class.php.
string axLocale::$_file [protected] |
Dictionnary file.
Definition at line 35 of file axLocale.class.php.
string axLocale::$_lang [protected] |
Current lang used.
Definition at line 41 of file axLocale.class.php.
axTreeItem axLocale::$tree [protected] |
The translations tree.
Definition at line 53 of file axLocale.class.php.
const axLocale::CACHE_FILE = 'locale.cache.php' |
Definition at line 23 of file axLocale.class.php.