Class I18n
I18n handles translation of Text and time format strings.
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/I18n/I18n.php
Constants summary
Properties summary
- 
			$_categoriesprotectedarrayTranslation categories
- 
			$_domainsprotectedarrayTranslation strings for a specific domain read from the .mo or .po files
- 
			$_escapeprotectedstringEscape string
- 
			$_langprotectedstringCurrent language used for translations
- 
			$_noLocaleprotectedbooleanSet to true when I18N::_bindTextDomain() is called for the first time. If a translation file is found it is set to false again 
- 
			$categorypublicstringCurrent category of translation
- 
			$defaultDomainpublic staticstringDefault domain of translation
- 
			$domainpublicstringCurrent domain of translation
- 
			$l10npublicInstance of the L10n class for localization
Method Summary
- 
			__construct() publicConstructor, use I18n::getInstance() to get the i18n translation object.
- 
			_bindTextDomain() protectedBinds the given domain to a file in the specified directory.
- 
			_parseLiteralValue() protectedAuxiliary function to parse a symbol from a locale definition file
- 
			_pluralGuess() protectedAttempts to find the plural form of a string.
- 
			_translateTime() protectedReturns a Time format definition from corresponding domain
- 
			clear() public staticClears the domains internal data array. Useful for testing i18n.
- 
			domains() public staticGet the loaded domains cache.
- 
			getInstance() public staticReturn a static instance of the I18n class
- 
			insertArgs() public staticPuts the parameters in raw translated strings
- 
			loadLocaleDefinition() public staticParses a locale definition file following the POSIX standard
- 
			loadMo() public staticLoads the binary .mo file and returns array of translations
- 
			loadPo() public staticLoads the text .po file and returns array of translations
- 
			translate() public staticUsed by the translation functions in basics.php Returns a translated string based on current language and translation files stored in locale folder 
Method Detail
__construct() public ¶
__construct( )
Constructor, use I18n::getInstance() to get the i18n translation object.
_bindTextDomain() protected ¶
_bindTextDomain( string $domain )
Binds the given domain to a file in the specified directory.
Parameters
- string $domain
- Domain to bind
Returns
Domain binded
_parseLiteralValue() protected ¶
_parseLiteralValue( string $string )
Auxiliary function to parse a symbol from a locale definition file
Parameters
- string $string
- Symbol to be parsed
Returns
parsed symbol
_pluralGuess() protected ¶
_pluralGuess( string $header , integer $n )
Attempts to find the plural form of a string.
Parameters
- string $header
- Type
- integer $n
- Number
Returns
plural match
Link
_translateTime() protected ¶
_translateTime( string $format , string $domain )
Returns a Time format definition from corresponding domain
Parameters
- string $format
- Format to be translated
- string $domain
- Domain where format is stored
Returns
translated format string if only value or array of translated strings for corresponding format.
insertArgs() public static ¶
insertArgs( string $translated , array $args )
Puts the parameters in raw translated strings
Parameters
- string $translated
- The raw translated string
- array $args
- The arguments to put in the translation
Returns
Translated string with arguments
loadLocaleDefinition() public static ¶
loadLocaleDefinition( string $filename )
Parses a locale definition file following the POSIX standard
Parameters
- string $filename
- Locale definition filename
Returns
Array of definitions on success or false on failure
loadMo() public static ¶
loadMo( string $filename )
Loads the binary .mo file and returns array of translations
Parameters
- string $filename
- Binary .mo file to load
Returns
Array of translations on success or false on failure
Link
loadPo() public static ¶
loadPo( string $filename )
Loads the text .po file and returns array of translations
Parameters
- string $filename
- Text .po file to load
Returns
Array of translations on success or false on failure
translate() public static ¶
translate( string $singular , string $plural = null , string $domain = null , string $category = self::LC_MESSAGES , integer $count = null , string $language = null , string $context = null )
Used by the translation functions in basics.php Returns a translated string based on current language and translation files stored in locale folder
Parameters
- string $singular
- String to translate
- string $plural optional null
- Plural string (if any)
- string $domain optional null
- Domain The domain of the translation. Domains are often used by plugin translations. If null, the default domain will be used. 
- string $category optional self::LC_MESSAGES
- Category The integer value of the category to use.
- integer $count optional null
- Count Count is used with $plural to choose the correct plural form.
- string $language optional null
- Language to translate string to. If null it checks for language in session followed by Config.language configuration variable. 
- string $context optional null
- Context The context of the translation, e.g a verb or a noun.
Returns
translated string.
Throws
Properties detail
$_categories ¶
Translation categories
array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES' )
$_domains ¶
Translation strings for a specific domain read from the .mo or .po files
array()
			$_noLocale ¶
Set to true when I18N::_bindTextDomain() is called for the first time. If a translation file is found it is set to false again
false
			