PHP Class 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
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\console\Controller
Datei anzeigen Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$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.

Public Methods

Method Description
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 )

Protected Methods

Method Description
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

Private Methods

Method Description
extractMessagesFromTokens ( array $tokens, array $translatorTokens, array $ignoreCategories ) : array Extracts messages from a parsed PHP tokens list.

Method Details

actionConfig() public method

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.
return integer CLI exit code

actionConfigTemplate() public method

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.
return integer CLI exit code

actionExtract() public method

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() protected method

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.
return array

getLine() protected method

Finds out a line of the first non-char PHP token found
Since: 2.0.1
protected getLine ( array $tokens ) : integer | string
$tokens array
return integer | string

isCategoryIgnored() protected method

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).
Since: 2.0.7
protected isCategoryIgnored ( string $category, array $ignoreCategories ) : boolean
$category string category that is checked
$ignoreCategories array message categories to ignore.
return boolean

optionAliases() public method

Since: 2.0.8
public optionAliases ( )

options() public method

public options ( $actionID )

saveMessagesCategoryToPHP() protected method

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
return integer exit code

saveMessagesToDb() protected method

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() protected method

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() protected method

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() protected method

Writes messages into POT file
Since: 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() protected method

Finds out if two PHP tokens are equal
Since: 2.0.1
protected tokensEqual ( array | string $a, array | string $b ) : boolean
$a array | string
$b array | string
return boolean

Property Details

$catalog public_oe property

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

$db public_oe property

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

$defaultAction public_oe property

controller default action ID.
public $defaultAction

$except public_oe property

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 public_oe property

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

$ignoreCategories public_oe property

message categories to ignore. For example, 'yii', 'app*', 'widgets/menu', etc.
See also: isCategoryIgnored
public $ignoreCategories

$languages public_oe property

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

$markUnused public_oe property

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 public_oe property

required, root directory containing message translations.
public $messagePath

$messageTable public_oe property

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

$only public_oe property

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 public_oe property

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

$removeUnused public_oe property

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 public_oe property

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 public_oe property

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

$sourcePath public_oe property

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

$translator public_oe property

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