class I18n extends AbstractSingleton implements TranslatableInterface

Methods

setLoader( LoaderInterface $loader)

Store the loader

getLoader()

Gets the loader

loadFile( string $file_name, null|string $dir_name = null)

Load a new language file

setLanguage( string $lang, bool $throw_errors = true, bool $force_rebuild = false)

Loads a new language

string
getLanguage()

Get the current language code used

setDefaultFromHttp()

Try to get the browser default locale and use it

bool
isAvailableLanguage( string $lang)

Check if a language code is available in the Loader

null|string
getAvailableLocale( string $lang)

Get the full locale info for a language code

array
getAvailableLanguages()

Get the list of Loader::available_languages

setLocale( string $locale)

Define a new locale for the system

string
getLocale()

Get the current locale used by the system

setTimezone( string $timezone)

Define a new timezone for the system

string
getTimezone()

Get the current timezone used by the system

bool
hasLocalizedString( string $index)

Check if a translation exists for an index

string
getLocalizedString( string $index)

Get the translation of an index

string
parseString( string $str, array $arguments = null)

Parse a translated string making some parameters replacements

array
parseStringMetadata( string $str)

Get the meta-data of a language string

string
getCurrency( string $lang = null)

Get the currency of the current locale

string
getHttpHeaderLocale()

Get the browser requested locale if so

array
getAvailableLanguagesNames( string $lang = null)

Get the full list of Loader::available_languages option like human readable names

string
getLanguageCode( string $lang = null)

Get the language code of the current locale

string
getRegionCode( string $lang = null)

Get the region code of the current locale

string
getScriptCode( string $lang = null)

Get the script code of the current locale

array
getKeywords( string $lang = null)

Get the keywords of the current locale

null|string
getKeyword( string $keyword, string $lang = null)

Get one keyword value of the current locale

string
getPrimaryLanguage( string $for_locale = null, string $lang = null)

Get the primary language of a locale

string
getLanguageName( string $for_locale = null, string $lang = null)

Get the language name of a locale

string
getCountryName( string $for_locale = null, string $lang = null)

Get the country name of a locale

string
getLocaleScript( string $for_locale = null, string $lang = null)

Get the script name of a locale

string
getLocaleVariant( string $for_locale = null, string $lang = null)

Get the variant name of a locale

static  string
getLocalizedNumberString( int $number, string $lang = null)

Get a localized number value

static  string
getLocalizedPriceString( int $number, string $lang = null)

Get a localized price value

static  string
getLocalizedDateString( DateTime $date, string $mask = null, string $charset = 'UTF-8', string $lang = null)

Get a localized date value

static  string
translate( string $index, array $args = null, string $lang = null)

Process a translation with arguments

static  string
pluralize( array $indexes = array(), int $number, array $args = null, string $lang = null)

Process a translation with arguments depending on a counter

Details

at line 212
I18n setLoader( LoaderInterface $loader)

Store the loader

Parameters

LoaderInterface $loader

Return Value

I18n

at line 223
LoaderInterface getLoader()

Gets the loader

Return Value

LoaderInterface

at line 235
loadFile( string $file_name, null|string $dir_name = null)

Load a new language file

Parameters

string $file_name
null|string $dir_name

Exceptions

I18nException
Exception

at line 273
I18n setLanguage( string $lang, bool $throw_errors = true, bool $force_rebuild = false)

Loads a new language

This will actually define a new default Locale and load the language strings database.

Parameters

string $lang A language code to use by default
bool $throw_errors Throw errors while re-creating the databases (default is false)
bool $force_rebuild Force the system to rebuild the databases using I18n\Generator (default is false)

Return Value

I18n Returns $this for method chaining

Exceptions

I18nInvalidArgumentException it the language is not available

at line 293
string getLanguage()

Get the current language code used

Return Value

string The current language code in use

at line 303
I18n setDefaultFromHttp()

Try to get the browser default locale and use it

Return Value

I18n

at line 318
bool isAvailableLanguage( string $lang)

Check if a language code is available in the Loader

Parameters

string $lang A language code to use by default

Return Value

bool Returns true if the language code exists, false otherwise

at line 333
null|string getAvailableLocale( string $lang)

Get the full locale info for a language code

This will look in the Loader::available_languages option to retrieve the full locale string corresponding to a language code.

Parameters

string $lang A language code to use by default

Return Value

null|string The full locale string if found

at line 349
array getAvailableLanguages()

Get the list of Loader::available_languages

Return Value

array The array defined in the Loader

at line 363
I18n setLocale( string $locale)

Define a new locale for the system

Parameters

string $locale The full locale string to define

Return Value

I18n Returns $this for method chaining

at line 374
string getLocale()

Get the current locale used by the system

Return Value

string The full locale string currently in use

at line 385
I18n setTimezone( string $timezone)

Define a new timezone for the system

Parameters

string $timezone The full timezone string to define

Return Value

I18n

at line 397
string getTimezone()

Get the current timezone used by the system

Return Value

string The full timezone string currently in use

at line 408
bool hasLocalizedString( string $index)

Check if a translation exists for an index

Parameters

string $index The original string or index to find translation of

Return Value

bool Returns true if the translation exists, false otherwise

at line 419
string getLocalizedString( string $index)

Get the translation of an index

Parameters

string $index The original string or index to find translation of

Return Value

string The translation found if so, $index otherwise

at line 432
string parseString( string $str, array $arguments = null)

Parse a translated string making some parameters replacements

Parameters

string $str The original string to work on
array $arguments A table of arguments to replace, like var=>val pairs for the replacement of %var% by val in the final string (by default)

Return Value

string The string with replacements

at line 454
array parseStringMetadata( string $str)

Get the meta-data of a language string

Parameters

string $str

Return Value

array array( (string) $str , (array) $info )

at line 503
string getCurrency( string $lang = null)

Get the currency of the current locale

Parameters

string $lang The language to use

Return Value

string The currency code for the current locale

at line 522
string getHttpHeaderLocale()

Get the browser requested locale if so

Return Value

string The browser prefered locale

at line 534
array getAvailableLanguagesNames( string $lang = null)

Get the full list of Loader::available_languages option like human readable names

Parameters

string $lang The language to use

Return Value

array The available languages table with the value as the human readable description of the corresponding locale

at line 559
string getLanguageCode( string $lang = null)

Get the language code of the current locale

Parameters

string $lang The language to use

Return Value

string The language code for the current locale

at line 571
string getRegionCode( string $lang = null)

Get the region code of the current locale

Parameters

string $lang The language to use

Return Value

string The region code for the current locale

at line 582
string getScriptCode( string $lang = null)

Get the script code of the current locale

Parameters

string $lang The language to use

Return Value

string The script code for the current locale

at line 593
array getKeywords( string $lang = null)

Get the keywords of the current locale

Parameters

string $lang The language to use

Return Value

array The keywords for the current locale

at line 605
null|string getKeyword( string $keyword, string $lang = null)

Get one keyword value of the current locale

Parameters

string $keyword The keyword to search
string $lang The language to use

Return Value

null|string The keyword value for the current locale if found

at line 618
string getPrimaryLanguage( string $for_locale = null, string $lang = null)

Get the primary language of a locale

Parameters

string $for_locale The locale to work on, by default this will be the current locale
string $lang The language to use, by default this will be the current locale

Return Value

string The primary language for the locale in the requested language

at line 630
string getLanguageName( string $for_locale = null, string $lang = null)

Get the language name of a locale

Parameters

string $for_locale The locale to work on, by default this will be the current locale
string $lang The language to use, by default this will be the current locale

Return Value

string The language name for the locale in the requested language

at line 642
string getCountryName( string $for_locale = null, string $lang = null)

Get the country name of a locale

Parameters

string $for_locale The locale to work on, by default this will be the current locale
string $lang The language to use, by default this will be the current locale

Return Value

string The country name for the locale in the requested language

at line 654
string getLocaleScript( string $for_locale = null, string $lang = null)

Get the script name of a locale

Parameters

string $for_locale The locale to work on, by default this will be the current locale
string $lang The language to use, by default this will be the current locale

Return Value

string The script name for the locale in the requested language

at line 666
string getLocaleVariant( string $for_locale = null, string $lang = null)

Get the variant name of a locale

Parameters

string $for_locale The locale to work on, by default this will be the current locale
string $lang The language to use, by default this will be the current locale

Return Value

string The variant name for the locale in the requested language

at line 710
static string getLocalizedNumberString( int $number, string $lang = null)

Get a localized number value

This is called by aliases _N and numberify.

Parameters

int $number The number value to parse
string $lang The language to use, by default this will be the current locale

Return Value

string The number value written in the locale

See also

_N()
numberify()

at line 736
static string getLocalizedPriceString( int $number, string $lang = null)

Get a localized price value

This is called by aliases _C and currencify.

Parameters

int $number The price value to parse
string $lang The language to use, by default this will be the current locale

Return Value

string The price value written in the locale with a currency sign

See also

_C()
currencify()

at line 765
static string getLocalizedDateString( DateTime $date, string $mask = null, string $charset = 'UTF-8', string $lang = null)

Get a localized date value

This is called by aliases _D and datify.

Parameters

DateTime $date The date value to parse as a DateTime object
string $mask A mask to use for date writing (by default, the datetime_mask_icu translation string will be used, or no mask at all if it is not defined)
string $charset The charset to use (default is utf-8)
string $lang The language to use, by default this will be the current locale

Return Value

string The date value written in the locale

See also

_D()
datify()

at line 817
static string translate( string $index, array $args = null, string $lang = null)

Process a translation with arguments

This is the core method of the class: it searches the translation of $index in the current language, rebuilds it replacing the keys of $args by their values and returns the corresponding localized translated string.

This is called by aliases _T and translate.

Parameters

string $index The index of the translation
array $args The optional array of arguments for the final string replacements
string $lang The language code to load translation from

Return Value

string Returns the translated string if it exists in the current language, with variables replacements

See also

_T()
translate()

at line 859
static string pluralize( array $indexes = array(), int $number, array $args = null, string $lang = null)

Process a translation with arguments depending on a counter

This will first choose in $indexes the corresponding value for the counter $number and then process the translation of the chosen string with arguments.

This is called by aliases _P and pluralize.

Parameters

array $indexes An array of translation strings indexes to choose in considering the counter value
int $number The value of the counter to consider
array $args The optional array of arguments for the final string replacements
string $lang The language code to load translation from

Return Value

string Returns the translated string fot the counter value if it exists, in the current language and with variables replacements

See also

_P()
pluralize()