PHP Класс yii\i18n\MessageSource

A message source stores message translations in some persistent storage. Child classes should override MessageSource::loadMessages to provide translated messages.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Component
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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]].

Открытые методы

Метод Описание
init ( ) Initializes this component.
translate ( string $category, string $message, string $language ) : string | boolean Translates a message to the specified language.

Защищенные методы

Метод Описание
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.

Описание методов

init() публичный метод

Initializes this component.
public init ( )

loadMessages() защищенный метод

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
Результат array the loaded messages. The keys are original messages, and the values are translated messages.

translate() публичный метод

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
Результат string | boolean the translated message or false if translation wasn't found or isn't required

translateMessage() защищенный метод

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.
Результат string | boolean the translated message or false if translation wasn't found.

Описание свойств

$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.
public $forceTranslation

$sourceLanguage публичное свойство

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