PHP Class yii\i18n\MessageSource

A message source stores message translations in some persistent storage. Child classes should override MessageSource::loadMessages to provide translated messages.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Component
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$forceTranslation whether to force message translation when the source and target languages are the same. Defaults to false, meaning translation is only performed when source and target languages are different.
$sourceLanguage the language that the original messages are in. If not set, it will use the value of [[\yii\base\Application::sourceLanguage]].

Méthodes publiques

Méthode Description
init ( ) Initializes this component.
translate ( string $category, string $message, string $language ) : string | boolean Translates a message to the specified language.

Méthodes protégées

Méthode Description
loadMessages ( string $category, string $language ) : array Loads the message translation for the specified language and category.
translateMessage ( string $category, string $message, string $language ) : string | boolean Translates the specified message.

Method Details

init() public méthode

Initializes this component.
public init ( )

loadMessages() protected méthode

If translation for specific locale code such as en-US isn't found it tries more generic en.
protected loadMessages ( string $category, string $language ) : array
$category string the message category
$language string the target language
Résultat array the loaded messages. The keys are original messages, and the values are translated messages.

translate() public méthode

Note that unless [[forceTranslation]] is true, if the target language is the same as the [[sourceLanguage|source language]], the message will NOT be translated. If a translation is not found, a [[EVENT_MISSING_TRANSLATION|missingTranslation]] event will be triggered.
public translate ( string $category, string $message, string $language ) : string | boolean
$category string the message category
$message string the message to be translated
$language string the target language
Résultat string | boolean the translated message or false if translation wasn't found or isn't required

translateMessage() protected méthode

If the message is not found, a [[EVENT_MISSING_TRANSLATION|missingTranslation]] event will be triggered. If there is an event handler, it may provide a [[MissingTranslationEvent::$translatedMessage|fallback translation]]. If no fallback translation is provided this method will return false.
protected translateMessage ( string $category, string $message, string $language ) : string | boolean
$category string the category that the message belongs to.
$message string the message to be translated.
$language string the target language.
Résultat string | boolean the translated message or false if translation wasn't found.

Property Details

$forceTranslation public_oe property

whether to force message translation when the source and target languages are the same. Defaults to false, meaning translation is only performed when source and target languages are different.
public $forceTranslation

$sourceLanguage public_oe property

the language that the original messages are in. If not set, it will use the value of [[\yii\base\Application::sourceLanguage]].
public $sourceLanguage