PHP Класс yii\i18n\DbMessageSource

The database must contain the following two tables: source_message and message. The source_message table stores the messages to be translated, and the message table stores the translated messages. The name of these two tables can be customized by setting [[sourceMessageTable]] and [[messageTable]], respectively. The database connection is specified by [[db]]. Database schema could be initialized by applying migration: yii migrate --migrationPath=@yii/i18n/migrations/ If you don't want to use migration and need SQL instead, files for all databases are in migrations directory.
С версии: 2.0
Автор: resurtm ([email protected])
Наследование: extends MessageSource
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$cache the cache object or the application component ID of the cache object. The messages data will be cached using this cache object. Note, that to enable caching you have to set [[enableCaching]] to true, otherwise setting this property has no effect. After the DbMessageSource object is created, if you want to change this property, you should only assign it with a cache object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$cachingDuration the time in seconds that the messages can remain valid in cache. Use 0 to indicate that the cached data will never expire.
$db the DB connection object or the application component ID of the DB connection. After the DbMessageSource object is created, if you want to change this property, you should only assign it with a DB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$enableCaching whether to enable caching translated messages
$messageTable the name of the translated message table.
$sourceMessageTable the name of the source message table.

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

Метод Описание
init ( ) Initializes the DbMessageSource component.

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

Метод Описание
createFallbackQuery ( string $category, string $language, string $fallbackLanguage ) : Query The method builds the [[Query]] object for the fallback language messages search.
loadMessages ( string $category, string $language ) : array Loads the message translation for the specified language and category.
loadMessagesFromDb ( string $category, string $language ) : array Loads the messages from database.

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

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

Normally is called from [[loadMessagesFromDb]].
См. также: loadMessagesFromDb
С версии: 2.0.7
protected createFallbackQuery ( string $category, string $language, string $fallbackLanguage ) : Query
$category string the message category
$language string the originally requested language
$fallbackLanguage string the target fallback language
Результат yii\db\Query

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

This method will initialize the [[db]] property to make sure it refers to a valid DB connection. Configured [[cache]] component would also be initialized.
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.

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

You may override this method to customize the message storage in the database.
protected loadMessagesFromDb ( string $category, string $language ) : array
$category string the message category.
$language string the target language.
Результат array the messages loaded from database.

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

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

the cache object or the application component ID of the cache object. The messages data will be cached using this cache object. Note, that to enable caching you have to set [[enableCaching]] to true, otherwise setting this property has no effect. After the DbMessageSource object is created, if you want to change this property, you should only assign it with a cache object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
См. также: cachingDuration
См. также: enableCaching
public $cache

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

the time in seconds that the messages can remain valid in cache. Use 0 to indicate that the cached data will never expire.
См. также: enableCaching
public $cachingDuration

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

the DB connection object or the application component ID of the DB connection. After the DbMessageSource object is created, if you want to change this property, you should only assign it with a DB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $db

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

whether to enable caching translated messages
public $enableCaching

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

the name of the translated message table.
public $messageTable

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

the name of the source message table.
public $sourceMessageTable