PHP Класс yii\console\controllers\MessageController

The extracted messages can be saved the following depending on format setting in config file: - PHP message source files. - ".po" files. - Database. Usage: 1. Create a configuration file using the 'message/config' command: yii message/config /path/to/myapp/messages/config.php 2. Edit the created config file, adjusting it for your web application needs. 3. Run the 'message/extract' command, using created config: yii message /path/to/myapp/messages/config.php
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\console\Controller
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$catalog name of the file that will be used for translations for "po" format.
$db connection component ID for "db" format.
$defaultAction controller default action ID.
$except list of patterns that specify which files/directories should NOT be processed. If empty or not set, all files/directories will be processed. See helpers/FileHelper::findFiles() description for pattern matching rules. If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
$format generated file format. Can be "php", "db" or "po".
$ignoreCategories message categories to ignore. For example, 'yii', 'app*', 'widgets/menu', etc.
$languages required, list of language codes that the extracted messages should be translated to. For example, ['zh-CN', 'de'].
$markUnused whether to mark messages that no longer appear in the source code. Defaults to true, which means each of these messages will be enclosed with a pair of '@@' marks.
$messagePath required, root directory containing message translations.
$messageTable custom name for translation message table for "db" format.
$only list of patterns that specify which files (not directories) should be processed. If empty or not set, all files will be processed. See helpers/FileHelper::findFiles() description for pattern matching rules. If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
$overwrite whether the message file should be overwritten with the merged messages
$removeUnused whether to remove messages that no longer appear in the source code. Defaults to false, which means these messages will NOT be removed.
$sort whether to sort messages by keys when merging new messages with the existing ones. Defaults to false, which means the new (untranslated) messages will be separated from the old (translated) ones.
$sourceMessageTable custom name for source message table for "db" format.
$sourcePath required, root directory of all source files.
$translator the name of the function for translating messages. Defaults to 'Yii::t'. This is used as a mark to find the messages to be translated. You may use a string for single function name or an array for multiple function names.

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

Метод Описание
actionConfig ( string $filePath ) : integer Creates a configuration file for the "extract" command using command line options specified
actionConfigTemplate ( string $filePath ) : integer Creates a configuration file template for the "extract" command.
actionExtract ( string $configFile = null ) Extracts messages to be translated from source code.
optionAliases ( )
options ( $actionID )

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

Метод Описание
extractMessages ( string $fileName, string $translator, array $ignoreCategories = [] ) : array Extracts messages from a file
getLine ( array $tokens ) : integer | string Finds out a line of the first non-char PHP token found
isCategoryIgnored ( string $category, array $ignoreCategories ) : boolean The method checks, whether the $category is ignored according to $ignoreCategories array.
saveMessagesCategoryToPHP ( array $messages, string $fileName, boolean $overwrite, boolean $removeUnused, boolean $sort, string $category, boolean $markUnused ) : integer Writes category messages into PHP file
saveMessagesToDb ( array $messages, Connection $db, string $sourceMessageTable, string $messageTable, boolean $removeUnused, array $languages, boolean $markUnused ) Saves messages to database
saveMessagesToPHP ( array $messages, string $dirName, boolean $overwrite, boolean $removeUnused, boolean $sort, boolean $markUnused ) Writes messages into PHP files
saveMessagesToPO ( array $messages, string $dirName, boolean $overwrite, boolean $removeUnused, boolean $sort, string $catalog, boolean $markUnused ) Writes messages into PO file
saveMessagesToPOT ( array $messages, string $dirName, string $catalog ) Writes messages into POT file
tokensEqual ( array | string $a, array | string $b ) : boolean Finds out if two PHP tokens are equal

Приватные методы

Метод Описание
extractMessagesFromTokens ( array $tokens, array $translatorTokens, array $ignoreCategories ) : array Extracts messages from a parsed PHP tokens list.

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

actionConfig() публичный Метод

The generated configuration file contains parameters required for source code messages extraction. You may use this configuration file with the "extract" command.
public actionConfig ( string $filePath ) : integer
$filePath string output file name or alias.
Результат integer CLI exit code

actionConfigTemplate() публичный Метод

The created configuration file contains detailed instructions on how to customize it to fit for your needs. After customization, you may use this configuration file with the "extract" command.
public actionConfigTemplate ( string $filePath ) : integer
$filePath string output file name or alias.
Результат integer CLI exit code

actionExtract() публичный Метод

This command will search through source code files and extract messages that need to be translated in different languages.
public actionExtract ( string $configFile = null )
$configFile string the path or alias of the configuration file. You may use the "yii message/config" command to generate this file and then customize it for your needs.

extractMessages() защищенный Метод

Extracts messages from a file
protected extractMessages ( string $fileName, string $translator, array $ignoreCategories = [] ) : array
$fileName string name of the file to extract messages from
$translator string name of the function used to translate messages
$ignoreCategories array message categories to ignore. This parameter is available since version 2.0.4.
Результат array

getLine() защищенный Метод

Finds out a line of the first non-char PHP token found
С версии: 2.0.1
protected getLine ( array $tokens ) : integer | string
$tokens array
Результат integer | string

isCategoryIgnored() защищенный Метод

Examples: - myapp - will be ignored only myapp category; - myapp* - will be ignored by all categories beginning with myapp (myapp, myapplication, myapprove, myapp/widgets, myapp.widgets, etc).
С версии: 2.0.7
protected isCategoryIgnored ( string $category, array $ignoreCategories ) : boolean
$category string category that is checked
$ignoreCategories array message categories to ignore.
Результат boolean

optionAliases() публичный Метод

С версии: 2.0.8
public optionAliases ( )

options() публичный Метод

public options ( $actionID )

saveMessagesCategoryToPHP() защищенный Метод

Writes category messages into PHP file
protected saveMessagesCategoryToPHP ( array $messages, string $fileName, boolean $overwrite, boolean $removeUnused, boolean $sort, string $category, boolean $markUnused ) : integer
$messages array
$fileName string name of the file to write to
$overwrite boolean if existing file should be overwritten without backup
$removeUnused boolean if obsolete translations should be removed
$sort boolean if translations should be sorted
$category string message category
$markUnused boolean if obsolete translations should be marked
Результат integer exit code

saveMessagesToDb() защищенный Метод

Saves messages to database
protected saveMessagesToDb ( array $messages, Connection $db, string $sourceMessageTable, string $messageTable, boolean $removeUnused, array $languages, boolean $markUnused )
$messages array
$db yii\db\Connection
$sourceMessageTable string
$messageTable string
$removeUnused boolean
$languages array
$markUnused boolean

saveMessagesToPHP() защищенный Метод

Writes messages into PHP files
protected saveMessagesToPHP ( array $messages, string $dirName, boolean $overwrite, boolean $removeUnused, boolean $sort, boolean $markUnused )
$messages array
$dirName string name of the directory to write to
$overwrite boolean if existing file should be overwritten without backup
$removeUnused boolean if obsolete translations should be removed
$sort boolean if translations should be sorted
$markUnused boolean if obsolete translations should be marked

saveMessagesToPO() защищенный Метод

Writes messages into PO file
protected saveMessagesToPO ( array $messages, string $dirName, boolean $overwrite, boolean $removeUnused, boolean $sort, string $catalog, boolean $markUnused )
$messages array
$dirName string name of the directory to write to
$overwrite boolean if existing file should be overwritten without backup
$removeUnused boolean if obsolete translations should be removed
$sort boolean if translations should be sorted
$catalog string message catalog
$markUnused boolean if obsolete translations should be marked

saveMessagesToPOT() защищенный Метод

Writes messages into POT file
С версии: 2.0.6
protected saveMessagesToPOT ( array $messages, string $dirName, string $catalog )
$messages array
$dirName string name of the directory to write to
$catalog string message catalog

tokensEqual() защищенный Метод

Finds out if two PHP tokens are equal
С версии: 2.0.1
protected tokensEqual ( array | string $a, array | string $b ) : boolean
$a array | string
$b array | string
Результат boolean

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

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

name of the file that will be used for translations for "po" format.
public $catalog

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

connection component ID for "db" format.
public $db

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

controller default action ID.
public $defaultAction

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

list of patterns that specify which files/directories should NOT be processed. If empty or not set, all files/directories will be processed. See helpers/FileHelper::findFiles() description for pattern matching rules. If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
public $except

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

generated file format. Can be "php", "db" or "po".
public $format

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

message categories to ignore. For example, 'yii', 'app*', 'widgets/menu', etc.
См. также: isCategoryIgnored
public $ignoreCategories

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

required, list of language codes that the extracted messages should be translated to. For example, ['zh-CN', 'de'].
public $languages

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

whether to mark messages that no longer appear in the source code. Defaults to true, which means each of these messages will be enclosed with a pair of '@@' marks.
public $markUnused

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

required, root directory containing message translations.
public $messagePath

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

custom name for translation message table for "db" format.
public $messageTable

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

list of patterns that specify which files (not directories) should be processed. If empty or not set, all files will be processed. See helpers/FileHelper::findFiles() description for pattern matching rules. If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
public $only

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

whether the message file should be overwritten with the merged messages
public $overwrite

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

whether to remove messages that no longer appear in the source code. Defaults to false, which means these messages will NOT be removed.
public $removeUnused

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

whether to sort messages by keys when merging new messages with the existing ones. Defaults to false, which means the new (untranslated) messages will be separated from the old (translated) ones.
public $sort

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

custom name for source message table for "db" format.
public $sourceMessageTable

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

required, root directory of all source files.
public $sourcePath

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

the name of the function for translating messages. Defaults to 'Yii::t'. This is used as a mark to find the messages to be translated. You may use a string for single function name or an array for multiple function names.
public $translator