Axiom (v1.2.0)

A lightweight PHP framework
axLocale Class Reference

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.

Detailed Description

Locale class.

Todo:
Locale class description
Author:
Delespierre
Since:
1.1.4
License:
http://www.gnu.org/licenses/lgpl.html Lesser General Public Licence version 3

Definition at line 17 of file axLocale.class.php.


Constructor & Destructor Documentation

axLocale::__construct ( lang_file,
lang = "auto",
default_lang = "en",
cache_dir = false 
)

Constructor.

Parameters:
string$lang_fileThe 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)
Exceptions:
axMissingFileExceptionIf the lang file could not be found

Definition at line 65 of file axLocale.class.php.


Member Function Documentation

axLocale::__get ( key)

Get a translation key.

Parameters:
string$key
Returns:
axTreeItem

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.

Determine the nearest available lang according to accepted languages.

Will return false if no corresponding language could be found

Returns:
string

Definition at line 376 of file axLocale.class.php.

axLocale::_generateTree ( ) [protected]

Generates the translation tree.

Exceptions:
axMissingFileExceptionIf the file is not found or not readable
RuntimeExceptionIf the file could not be parsed
Returns:
void

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).

Returns:
array

Definition at line 329 of file axLocale.class.php.

Get the localized formats http://php.net/manual/en/function.localeconv.php.

Returns:
array

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).

Parameters:
integer$time[optional] [default null]
Returns:
string

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.

Warning:
You must use the ymdHi format for the $date parameter or a integer representing a timestamp.
Parameters:
mixed$dateThe date (ymdHi format) or a timestamp
Returns:
string

Definition at line 176 of file axLocale.class.php.

Get the internal iterator.

See also:
IteratorAggregate::getIterator()
Returns:
axTreeItem

Definition at line 93 of file axLocale.class.php.

Get the current lang.

Returns:
string

Definition at line 137 of file axLocale.class.php.

axLocale::i18n ( key)

Use a string format for identifying translations.

Parameters:
string$key
mixed$arg[optional] You may pass as many arguments as the translation accepts (according to the sprintf syntax)
Returns:
string

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.

Note:
You may specify "auto" to determine the language automatically
Parameters:
string$langThe lang to be used
Returns:
axLocale

Definition at line 123 of file axLocale.class.php.


Field Documentation

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.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables