I18N
Allows the project to be internationalised.
load
public static function load(mixed $src, array $arr=null)
Loads a new language definition. $src can either be a php file that returns
an array of the format array('pack' => array('token' => 'string', ...)) or
the name of the locale, such as en. If the locale name is given as $src, you
then need to manually provide the language definition array as $arr. Each definition
contains one or more packs which are groups of tokens and corresponding strings.
An example of a pack would be user, which groups the tokens login and
account which have the corresponding strings 'Login' and 'View my account'. Will
return true if the definition successfully loaded, false otherwise.
Hint
If you need an example of a language definition file, check the tests/units/locales/
directory of the project, there are 2 examples en.php and ge.php.
e (echo)
public static function e(string $token, array $vars=null)
Echo's the localised string. The format for $token is pack.token. For example,
I18N::e('user.login') will echo the string associated with the login token inside
of the user pack. An optional array of arguments $vars can be passed in which
will replace any tokens formatted as {0..n} in the localised string. For example,
if the string associated with user.welcome was Hello {0}, welcome to {1}!,
and you called I18N::e('user.welcome', ['Tristan', 'Bantam']), the echo'd string would be
Hello Tristan, welcome to Bantam!.
r (return)
public static function r(string $token, array $vars=null)
Will return the localised string. Please see e (echo) above for usage examples.
setLocale
public static function setLocale(string $loc='en')
Will set the current locale to the specified $loc given. If the provided locale
is invalid or empty, it will default to en.
getLocale
public static function getLocale()
Returns the currently set locale.