PHP Class yii\i18n\GettextMessageSource

Each GettextMessageSource instance represents the message translations for a single domain. And each message category represents a message context in Gettext. Translated messages are stored as either a MO or PO file, depending on the [[useMoFile]] property value. All translations are saved under the [[basePath]] directory. Translations in one language are kept as MO or PO files under an individual subdirectory whose name is the language ID. The file name is specified via [[catalog]] property, which defaults to 'messages'.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends MessageSource
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$basePath string
$catalog string
$useBigEndian boolean
$useMoFile boolean

Protected Methods

Method Description
getMessageFilePath ( string $language ) : string Returns message file path for the specified language and category.
loadFallbackMessages ( string $category, string $fallbackLanguage, array $messages, string $originalMessageFile ) : array The method is normally called by [[loadMessages]] to load the fallback messages for the language.
loadMessages ( string $category, string $language ) : array Loads the message translation for the specified $language and $category.
loadMessagesFromFile ( string $messageFile, string $category ) : array | null Loads the message translation for the specified language and category or returns null if file doesn't exist.

Method Details

getMessageFilePath() protected method

Returns message file path for the specified language and category.
protected getMessageFilePath ( string $language ) : string
$language string the target language
return string path to message file

loadFallbackMessages() protected method

Method tries to load the $category messages for the $fallbackLanguage and adds them to the $messages array.
Since: 2.0.7
protected loadFallbackMessages ( string $category, string $fallbackLanguage, array $messages, string $originalMessageFile ) : array
$category string the message category
$fallbackLanguage string the target fallback language
$messages array the array of previously loaded translation messages. The keys are original messages, and the values are the translated messages.
$originalMessageFile string the path to the file with messages. Used to log an error message in case when no translations were found.
return array the loaded messages. The keys are original messages, and the values are the translated messages.

loadMessages() protected method

If translation for specific locale code such as en-US isn't found it tries more generic en. When both are present, the en-US messages will be merged over en. See [[loadFallbackMessages]] for details. If the $language is less specific than [[sourceLanguage]], the method will try to load the messages for [[sourceLanguage]]. For example: [[sourceLanguage]] is en-GB, $language is en. The method will load the messages for en and merge them over en-GB.
See also: loadFallbackMessages
See also: sourceLanguage
protected loadMessages ( string $category, string $language ) : array
$category string the message category
$language string the target language
return array the loaded messages. The keys are original messages, and the values are translated messages.

loadMessagesFromFile() protected method

Loads the message translation for the specified language and category or returns null if file doesn't exist.
protected loadMessagesFromFile ( string $messageFile, string $category ) : array | null
$messageFile string path to message file
$category string the message category
return array | null array of messages or null if file not found

Property Details

$basePath public property

public string $basePath
return string

$catalog public property

public string $catalog
return string

$useBigEndian public property

public bool $useBigEndian
return boolean

$useMoFile public property

public bool $useMoFile
return boolean