public $locale
The locale code, corresponding to the name of the country to localize numbers and dates for.
public $charset = 'UTF-8'
The charset of the current language, which can be used to tell the browser, or any language-aware PHP functions, which to use.
public $url_includes_lang = false
Tells the controller that the first level of the URL is the language
and not the page ID when $negotiation=url
.
public $new_request_uri = ''
If $url_includes_lang
is true, this will include the request with
the language stripped out.
public $prefix = ''
If $url_includes_lang
is true, this will include the stripped out
part of the URL. Otherwise it will be empty. This is useful for
including language URL prefixes in views via {{ i18n.prefix }}
.
public __construct ($directory = 'lang', $conf = array ())
Includes the appropriate language file in the provided $directory
.
This file is intended to fill out the $lang_hash
array.
$negotiationMethod
determines the method whereby the language of
choice is determined. See the negotiate()
method for more info on this.
public get ($original = '')
Takes a string, serializes it to generate a key, and performs
a key/value lookup on the $lang_hash
array. Returns the value found,
or the original string if not found. This is the method used in I18n
to return translated text.
public getf ()
Takes a string, serializes it to generate a key, and performs
a key/value lookup on the $lang_hash
array. Returns the value found,
or the original string if not found. This method is similar to
get()
, except it uses vsprintf()
to insert values.
If you pass an array as the second value, it will use that instead of
however many additional arguments you fed it. This is handy
because if you already have all your values in an array, you can
simply say getf($original, $array)
instead of getf($original, $array[0],
$array[1], $array[2])
.
public getLanguages ()
Returns a 2-D array from the specified language file, which is an INI file. Each section name in the file corresponds to a different available language. Keys in each section include 'name', 'code', 'locale', 'charset', 'fallback', and 'default'.
public negotiate ($method = false)
Returns the preferred language of the current visitor.
If the $method
is 'http'
then it uses the HTTP Accept-Language
string for this info. If the $method
is 'cookie'
it uses a
cookie (specified by the $cookieName
property) to determine,
if the $method
is 'subdomain'
then it looks for it in the
subdomain of the site (e.g., en.sitename.com
, fr.sitename.com
),
and if the $method
is 'url'
then it uses the start of the URL
to determine the language (e.g., /fr/
or /en/
).
Default is 'url'
.
public static export ($strings)
Export an array of strings into a JavaScript block that calls
$.i18n_add()
which can be passed to $page->add_script()
.
Can also be called from a view template on an array of strings
like this: {{ my_array|I18n::export }}
.
Note that you may pass either a single array, or each string
as a separate parameter, which allows you to omit the array()
wrapper when calling it in PHP code.
private static _date ($date, $class, $format)
Applies the specified class and format to a date for
the date()
, short_date()
, time()
, date_time()
and
short_date_time()
methods.
public static date ($date)
Filter for outputting dates. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::date }}
public static short_date ($date)
Filter for outputting a shortened date. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::short_date }}
public static short_date_year ($date)
Filter for outputting a shortened date with year included. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::short_date_year }}
public static day_date ($date)
Filter for outputting a shortened day and date. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::day_date }}
public static short_day_date ($date)
Filter for outputting a shortened day and date. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::short_day_date }}
public static time ($date)
Filter for outputting times. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::time }}
public static date_time ($date)
Filter for outputting date and time. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::date_time }}
public static day_date_time ($date)
Filter for outputting a shortened date and time. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::day_date_time }}
public static short_date_time ($date)
Filter for outputting a shortened date and time. Used with the jQuery localize plugin to convert dates into the current user's time zone.
Usage:
{{ date_value|I18n::short_date_time }}
I18n is a class that makes it easier to add multiple language support to PHP programs. It is lightweight and not very sophisticated, attempting to keep it straight-forward while emulating some of the more elegant features of other internationalization systems, such as gettext.
Translation files are PHP, so they benefit from language-level caching, and string replacement is simply an associative array lookup.