# MessageController

> Extracts messages to be translated from source files.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [console](/docs/api/yii/console/index.md) › [controllers](/docs/api/yii/console/controllers/index.md) › MessageController

| class | `yii\console\controllers\MessageController` |
| --- | --- |
| Extends | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) » [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/console/controllers/MessageController.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/console/controllers/MessageController.php#L47) |

Extracts messages to be translated from source files.

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

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-action"></span>[`$action`](/docs/api/yii/base/controller/index.md#property-action) | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>\|null` | The action that is currently being executed. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-catalog"></span>`$catalog` | `string` | Name of the file that will be used for translations for "po" format. Default: `'messages'`. | `MessageController` |
| <span id="property-color"></span>[`$color`](/docs/api/yii/console/controller/index.md#property-color) | `bool\|null` | Whether to enable ANSI color in the output. Default: `null`. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-db"></span>`$db` | `string` | Connection component ID for "db" format. Default: `'db'`. | `MessageController` |
| <span id="property-defaultAction"></span>`$defaultAction` | `string` | Controller default action ID. Default: `'extract'`. | `MessageController` |
| [`$except`](#property-except) | `array\|null` | List of patterns that specify which files/directories should NOT be processed. Default: `['.*', '/.*', '/messages', '/tests', '/runtime', '/vendor', '/BaseYii.php']`. | `MessageController` |
| [`$format`](#property-format) | `string` | Generated file format. Default: `'php'`. | `MessageController` |
| <span id="property-help"></span>[`$help`](/docs/api/yii/console/controller/index.md#property-help) | `bool` | Whether to display help information about current command. Default: `false`. Available since 2.0.10. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-helpSummary"></span>[`$helpSummary`](/docs/api/yii/console/controller/index.md#property-helpSummary) read-only | `string` | The one-line short summary describing this controller. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/controller/index.md#property-id) | `string` | The ID of this controller. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`$ignoreCategories`](#property-ignoreCategories) | `array` | Message categories to ignore. Default: `[]`. | `MessageController` |
| <span id="property-interactive"></span>[`$interactive`](/docs/api/yii/console/controller/index.md#property-interactive) | `bool` | Whether to run the command interactively. Default: `true`. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`$languages`](#property-languages) | `array` | Required, list of language codes that the extracted messages should be translated to. Default: `[]`. | `MessageController` |
| <span id="property-layout"></span>[`$layout`](/docs/api/yii/base/controller/index.md#property-layout) | `string\|null\|false` | The name of the layout to be applied to this controller's views. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`$markUnused`](#property-markUnused) | `bool` | Whether to mark messages that no longer appear in the source code. Default: `true`. | `MessageController` |
| <span id="property-messagePath"></span>`$messagePath` | `string` | Required, root directory containing message translations. Default: `'@yii/messages'`. | `MessageController` |
| <span id="property-messageTable"></span>`$messageTable` | `string` | Custom name for translation message table for "db" format. Default: `'{{%message}}'`. | `MessageController` |
| <span id="property-module"></span>[`$module`](/docs/api/yii/base/controller/index.md#property-module) | `yii\base\T` | The module that this controller belongs to. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-modules"></span>[`$modules`](/docs/api/yii/base/controller/index.md#property-modules) read-only | [`yii\base\Module`](/docs/api/yii/base/module/index.md)`[]` | All ancestor modules that this controller is located within. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`$only`](#property-only) | `array\|null` | List of patterns that specify which files (not directories) should be processed. Default: `['*.php']`. | `MessageController` |
| <span id="property-overwrite"></span>`$overwrite` | `bool` | Whether the message file should be overwritten with the merged messages Default: `true`. | `MessageController` |
| <span id="property-passedOptions"></span>[`$passedOptions`](/docs/api/yii/console/controller/index.md#property-passedOptions) read-only | `array` | The names of the options passed during execution. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-passedOptionValues"></span>[`$passedOptionValues`](/docs/api/yii/console/controller/index.md#property-passedOptionValues) read-only | `array` | The properties corresponding to the passed options. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`$phpDocBlock`](#property-phpDocBlock) | `string\|null` | DocBlock used for messages array in generated PHP file. Default: `null`. Available since 2.0.13. | `MessageController` |
| [`$phpFileHeader`](#property-phpFileHeader) | `string` | File header in generated PHP file with messages. Default: `''`. Available since 2.0.13. | `MessageController` |
| [`$removeUnused`](#property-removeUnused) | `bool` | Whether to remove messages that no longer appear in the source code. Default: `false`. | `MessageController` |
| <span id="property-request"></span>[`$request`](/docs/api/yii/console/controller/index.md#property-request) | [`yii\console\Request`](/docs/api/yii/console/request/index.md) | The request object. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-response"></span>[`$response`](/docs/api/yii/console/controller/index.md#property-response) | [`yii\console\Response`](/docs/api/yii/console/response/index.md) | The response object. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="property-route"></span>[`$route`](/docs/api/yii/base/controller/index.md#property-route) read-only | `string` | The route (module ID, controller ID and action ID) of the current request. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-silentExitOnException"></span>[`$silentExitOnException`](/docs/api/yii/console/controller/index.md#property-silentExitOnException) | `bool\|null` | If true - script finish with `ExitCode::OK` in case of exception. false - `ExitCode::UNSPECIFIED_ERROR`. Default: `null`. Available since 2.0.36. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`$sort`](#property-sort) | `bool` | Whether to sort messages by keys when merging new messages with the existing ones. Default: `false`. | `MessageController` |
| <span id="property-sourceMessageTable"></span>`$sourceMessageTable` | `string` | Custom name for source message table for "db" format. Default: `'{{%source_message}}'`. | `MessageController` |
| <span id="property-sourcePath"></span>`$sourcePath` | `string` | Required, root directory of all source files. Default: `'@yii'`. | `MessageController` |
| [`$translator`](#property-translator) | `string\|string[]` | The name of the function for translating messages. Default: `['Yii::t', '\Yii::t']`. | `MessageController` |
| <span id="property-uniqueId"></span>[`$uniqueId`](/docs/api/yii/base/controller/index.md#property-uniqueId) read-only | `string` | The controller ID that is prefixed with the module ID (if any). | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/controller/index.md#property-view) | [`yii\base\View`](/docs/api/yii/base/view/index.md)`\|`[`yii\web\View`](/docs/api/yii/web/view/index.md) | The view object that can be used to render views or view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/controller/index.md#property-viewPath) | `string` | The directory containing the view files for this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-config"></span>`$config` protected | `array` | Config for messages extraction. Default: `null`. Available since 2.0.13. | `MessageController` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/controller/index.md#method-__construct) |  | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`actionConfig()`](#method-actionConfig) | Creates a configuration file for the "extract" command using command line options specified. | `MessageController` |
| [`actionConfigTemplate()`](#method-actionConfigTemplate) | Creates a configuration file template for the "extract" command. | `MessageController` |
| [`actionExtract()`](#method-actionExtract) | Extracts messages to be translated from source code. | `MessageController` |
| <span id="method-actions"></span>[`actions()`](/docs/api/yii/base/controller/index.md#method-actions) | Declares external actions for the controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-afterAction"></span>[`afterAction()`](/docs/api/yii/base/controller/index.md#method-afterAction) | This method is invoked right after an action is executed. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-ansiFormat"></span>[`ansiFormat()`](/docs/api/yii/console/controller/index.md#method-ansiFormat) | Formats a string with ANSI codes. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-beforeAction"></span>[`beforeAction()`](/docs/api/yii/console/controller/index.md#method-beforeAction) | This method is invoked right before an action is executed. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-bindActionParams"></span>[`bindActionParams()`](/docs/api/yii/console/controller/index.md#method-bindActionParams) | Binds the parameters to the action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-confirm"></span>[`confirm()`](/docs/api/yii/console/controller/index.md#method-confirm) | Asks user to confirm by typing y or n. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-createAction"></span>[`createAction()`](/docs/api/yii/base/controller/index.md#method-createAction) | Creates an action based on the given action ID. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-findLayoutFile"></span>[`findLayoutFile()`](/docs/api/yii/base/controller/index.md#method-findLayoutFile) | Finds the applicable layout file. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getActionArgsHelp"></span>[`getActionArgsHelp()`](/docs/api/yii/console/controller/index.md#method-getActionArgsHelp) | Returns the help information for the anonymous arguments for the action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getActionHelp"></span>[`getActionHelp()`](/docs/api/yii/console/controller/index.md#method-getActionHelp) | Returns the detailed help information for the specified action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getActionHelpSummary"></span>[`getActionHelpSummary()`](/docs/api/yii/console/controller/index.md#method-getActionHelpSummary) | Returns a one-line short summary describing the specified action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getActionOptionsHelp"></span>[`getActionOptionsHelp()`](/docs/api/yii/console/controller/index.md#method-getActionOptionsHelp) | Returns the help information for the options for the action. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getHelp"></span>[`getHelp()`](/docs/api/yii/console/controller/index.md#method-getHelp) | Returns help information for this controller. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getHelpSummary"></span>[`getHelpSummary()`](/docs/api/yii/console/controller/index.md#method-getHelpSummary) | Returns one-line short summary describing this controller. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getModules"></span>[`getModules()`](/docs/api/yii/base/controller/index.md#method-getModules) | Returns all ancestor modules of this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getOptionValues"></span>[`getOptionValues()`](/docs/api/yii/console/controller/index.md#method-getOptionValues) | Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getPassedOptions"></span>[`getPassedOptions()`](/docs/api/yii/console/controller/index.md#method-getPassedOptions) | Returns the names of valid options passed during execution. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getPassedOptionValues"></span>[`getPassedOptionValues()`](/docs/api/yii/console/controller/index.md#method-getPassedOptionValues) | Returns the properties corresponding to the passed options. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-getRoute"></span>[`getRoute()`](/docs/api/yii/base/controller/index.md#method-getRoute) | Returns the route of the current request. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getUniqueId"></span>[`getUniqueId()`](/docs/api/yii/base/controller/index.md#method-getUniqueId) | Returns the unique ID of the controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/controller/index.md#method-getView) | Returns the view object that can be used to render views or view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/controller/index.md#method-getViewPath) | Returns the directory containing view files for this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/controller/index.md#method-init) | Initializes the object. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-isColorEnabled"></span>[`isColorEnabled()`](/docs/api/yii/console/controller/index.md#method-isColorEnabled) | Returns a value indicating whether ANSI color is enabled. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`optionAliases()`](#method-optionAliases) | Returns option alias names. | `MessageController` |
| [`options()`](#method-options) | Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name. | `MessageController` |
| <span id="method-prompt"></span>[`prompt()`](/docs/api/yii/console/controller/index.md#method-prompt) | Prompts the user for input and validates it. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/controller/index.md#method-render) | Renders a view and applies layout if available. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderContent"></span>[`renderContent()`](/docs/api/yii/base/controller/index.md#method-renderContent) | Renders a static string by applying a layout. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/controller/index.md#method-renderFile) | Renders a view file. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderPartial"></span>[`renderPartial()`](/docs/api/yii/base/controller/index.md#method-renderPartial) | Renders a view without applying layout. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-run"></span>[`run()`](/docs/api/yii/base/controller/index.md#method-run) | Runs a request specified in terms of a route. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-runAction"></span>[`runAction()`](/docs/api/yii/console/controller/index.md#method-runAction) | Runs an action with the specified action ID and parameters. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-select"></span>[`select()`](/docs/api/yii/console/controller/index.md#method-select) | Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-setView"></span>[`setView()`](/docs/api/yii/base/controller/index.md#method-setView) | Sets the view object to be used by this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-setViewPath"></span>[`setViewPath()`](/docs/api/yii/base/controller/index.md#method-setViewPath) | Sets the directory that contains the view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-stderr"></span>[`stderr()`](/docs/api/yii/console/controller/index.md#method-stderr) | Prints a string to STDERR. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-stdout"></span>[`stdout()`](/docs/api/yii/console/controller/index.md#method-stdout) | Prints a string to STDOUT. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-bindInjectedParams"></span>[`bindInjectedParams()`](/docs/api/yii/base/controller/index.md#method-bindInjectedParams) protected final | Fills parameters based on types and names in action method signature. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`extractMessages()`](#method-extractMessages) protected | Extracts messages from a file. | `MessageController` |
| [`extractMessagesFromTokens()`](#method-extractMessagesFromTokens) protected | Extracts messages from a parsed PHP tokens list. | `MessageController` |
| <span id="method-getActionMethodReflection"></span>[`getActionMethodReflection()`](/docs/api/yii/console/controller/index.md#method-getActionMethodReflection) protected |  | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`getLine()`](#method-getLine) protected | Finds out a line of the first non-char PHP token found. | `MessageController` |
| [`initConfig()`](#method-initConfig) protected |  | `MessageController` |
| [`isCategoryIgnored()`](#method-isCategoryIgnored) protected | The method checks, whether the $category is ignored according to $ignoreCategories array. | `MessageController` |
| <span id="method-parseDocCommentDetail"></span>[`parseDocCommentDetail()`](/docs/api/yii/console/controller/index.md#method-parseDocCommentDetail) protected | Returns full description from the docblock. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-parseDocCommentSummary"></span>[`parseDocCommentSummary()`](/docs/api/yii/console/controller/index.md#method-parseDocCommentSummary) protected | Returns the first line of docblock. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| <span id="method-parseDocCommentTags"></span>[`parseDocCommentTags()`](/docs/api/yii/console/controller/index.md#method-parseDocCommentTags) protected | Parses the comment block into tags. | [`yii\console\Controller`](/docs/api/yii/console/controller/index.md) |
| [`saveMessagesCategoryToPHP()`](#method-saveMessagesCategoryToPHP) protected | Writes category messages into PHP file. | `MessageController` |
| [`saveMessagesToDb()`](#method-saveMessagesToDb) protected | Saves messages to database. | `MessageController` |
| [`saveMessagesToPHP()`](#method-saveMessagesToPHP) protected | Writes messages into PHP files. | `MessageController` |
| [`saveMessagesToPO()`](#method-saveMessagesToPO) protected | Writes messages into PO file. | `MessageController` |
| [`saveMessagesToPOT()`](#method-saveMessagesToPOT) protected | Writes messages into POT file. | `MessageController` |
| [`tokensEqual()`](#method-tokensEqual) protected | Finds out if two PHP tokens are equal. | `MessageController` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_BEFORE_ACTION"></span>[`EVENT_BEFORE_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_BEFORE_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised right before executing a controller action. Event name: `'beforeAction'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="event-EVENT_AFTER_ACTION"></span>[`EVENT_AFTER_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_AFTER_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised right after executing a controller action. Event name: `'afterAction'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |

## Property details

### $except <span id="property-except"></span>

```php
public array|null $except = ['.*', '/.*', '/messages', '/tests', '/runtime', '/vendor', '/BaseYii.php']
```

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 <span id="property-format"></span>

```php
public string $format = 'php'
```

Generated file format.

Can be "php", "db", "po" or "pot".

### $ignoreCategories <span id="property-ignoreCategories"></span>

```php
public array $ignoreCategories = []
```

Message categories to ignore.

For example, 'yii', 'app*', 'widgets/menu', etc.

### $languages <span id="property-languages"></span>

```php
public array $languages = []
```

Required, list of language codes that the extracted messages should be translated to.

For example, ['zh-CN', 'de'].

### $markUnused <span id="property-markUnused"></span>

```php
public bool $markUnused = true
```

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.

### $only <span id="property-only"></span>

```php
public array|null $only = ['*.php']
```

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.

### $phpDocBlock <span id="property-phpDocBlock"></span>

```php
public string|null $phpDocBlock = null
```

DocBlock used for messages array in generated PHP file.

If `null`, default DocBlock will be used.
This property is used only if [`$format`](/docs/api/yii/console/controllers/messagecontroller/index.md#property-format) is "php".

**Since**

2.0.13

### $phpFileHeader <span id="property-phpFileHeader"></span>

```php
public string $phpFileHeader = ''
```

File header in generated PHP file with messages.

This property is used only if [`$format`](/docs/api/yii/console/controllers/messagecontroller/index.md#property-format) is "php".

**Since**

2.0.13

### $removeUnused <span id="property-removeUnused"></span>

```php
public bool $removeUnused = false
```

Whether to remove messages that no longer appear in the source code.

Defaults to false, which means these messages will NOT be removed.

### $sort <span id="property-sort"></span>

```php
public bool $sort = false
```

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.

### $translator <span id="property-translator"></span>

```php
public string|string[] $translator = ['Yii::t', '\Yii::t']
```

The name of the function for translating messages.

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.

## Method details

### actionConfig() <span id="method-actionConfig"></span>

```php
public function actionConfig(string $filePath): int
```

Creates a configuration file for the "extract" command using command line options specified.

The generated configuration file contains parameters required
for source code messages extraction.
You may use this configuration file with the "extract" command.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$filePath` | `string` | Output file name or alias. |

**Returns**

`int`: CLI exit code

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): on failure.

### actionConfigTemplate() <span id="method-actionConfigTemplate"></span>

```php
public function actionConfigTemplate(string $filePath): int
```

Creates a configuration file template for the "extract" command.

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.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$filePath` | `string` | Output file name or alias. |

**Returns**

`int`: CLI exit code

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): on failure.

### actionExtract() <span id="method-actionExtract"></span>

```php
public function actionExtract(string|null $configFile = null): mixed
```

Extracts messages to be translated from source code.

This command will search through source code files and extract
messages that need to be translated in different languages.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$configFile` | `string\|null` | 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. |

**Returns**

`mixed`

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): on failure.

### optionAliases() <span id="method-optionAliases"></span>

```php
public function optionAliases(): array
```

Returns option alias names.

Child classes may override this method to specify alias options.

**Returns**

`array`: The options alias names valid for the action where the keys is alias name for option and value is option name.

**Since**

2.0.8

### options() <span id="method-options"></span>

```php
public function options(mixed $actionID): string[]
```

Returns the names of valid options for the action (id)
An option requires the existence of a public member variable whose
name is the option name.

Child classes may override this method to specify possible options.

Note that the values setting via options are not available
until [`beforeAction()`](/docs/api/yii/console/controller/index.md#method-beforeAction) is being called.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$actionID` | `mixed` | The action id of the current request |

**Returns**

`string[]`: The names of the options valid for the action

### extractMessages() <span id="method-extractMessages"></span>

```php
protected function extractMessages(string $fileName, string $translator, array $ignoreCategories = []): array
```

Extracts messages from a file.

**Parameters**

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

**Returns**

`array`

### extractMessagesFromTokens() <span id="method-extractMessagesFromTokens"></span>

```php
protected function extractMessagesFromTokens(array $tokens, array $translatorTokens, array $ignoreCategories): array
```

Extracts messages from a parsed PHP tokens list.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tokens` | `array` | Tokens to be processed. |
| `$translatorTokens` | `array` | Translator tokens. |
| `$ignoreCategories` | `array` | Message categories to ignore. |

**Returns**

`array`: Messages.

### getLine() <span id="method-getLine"></span>

```php
protected function getLine(array $tokens): int|string
```

Finds out a line of the first non-char PHP token found.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tokens` | `array` |  |

**Returns**

`int|string`

**Since**

2.0.1

### initConfig() <span id="method-initConfig"></span>

```php
protected function initConfig(string $configFile): mixed
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$configFile` | `string` |  |

**Returns**

`mixed`

**Throws**

- [`yii\console\Exception`](/docs/api/yii/console/exception/index.md): If configuration file does not exists.

**Since**

2.0.13

### isCategoryIgnored() <span id="method-isCategoryIgnored"></span>

```php
protected function isCategoryIgnored(string $category, array $ignoreCategories): bool
```

The method checks, whether the $category is ignored according to $ignoreCategories array.

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).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$category` | `string` | Category that is checked |
| `$ignoreCategories` | `array` | Message categories to ignore. |

**Returns**

`bool`

**Since**

2.0.7

### saveMessagesCategoryToPHP() <span id="method-saveMessagesCategoryToPHP"></span>

```php
protected function saveMessagesCategoryToPHP(array $messages, string $fileName, bool $overwrite, bool $removeUnused, bool $sort, string $category, bool $markUnused): int
```

Writes category messages into PHP file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array` |  |
| `$fileName` | `string` | Name of the file to write to |
| `$overwrite` | `bool` | If existing file should be overwritten without backup |
| `$removeUnused` | `bool` | If obsolete translations should be removed |
| `$sort` | `bool` | If translations should be sorted |
| `$category` | `string` | Message category |
| `$markUnused` | `bool` | If obsolete translations should be marked |

**Returns**

`int`: Exit code

### saveMessagesToDb() <span id="method-saveMessagesToDb"></span>

```php
protected function saveMessagesToDb(array $messages, yii\db\Connection $db, string $sourceMessageTable, string $messageTable, bool $removeUnused, array $languages, bool $markUnused): mixed
```

Saves messages to database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array` |  |
| `$db` | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) |  |
| `$sourceMessageTable` | `string` |  |
| `$messageTable` | `string` |  |
| `$removeUnused` | `bool` |  |
| `$languages` | `array` |  |
| `$markUnused` | `bool` |  |

**Returns**

`mixed`

### saveMessagesToPHP() <span id="method-saveMessagesToPHP"></span>

```php
protected function saveMessagesToPHP(array $messages, string $dirName, bool $overwrite, bool $removeUnused, bool $sort, bool $markUnused): mixed
```

Writes messages into PHP files.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array` |  |
| `$dirName` | `string` | Name of the directory to write to |
| `$overwrite` | `bool` | If existing file should be overwritten without backup |
| `$removeUnused` | `bool` | If obsolete translations should be removed |
| `$sort` | `bool` | If translations should be sorted |
| `$markUnused` | `bool` | If obsolete translations should be marked |

**Returns**

`mixed`

### saveMessagesToPO() <span id="method-saveMessagesToPO"></span>

```php
protected function saveMessagesToPO(array $messages, string $dirName, bool $overwrite, bool $removeUnused, bool $sort, string $catalog, bool $markUnused): mixed
```

Writes messages into PO file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array` |  |
| `$dirName` | `string` | Name of the directory to write to |
| `$overwrite` | `bool` | If existing file should be overwritten without backup |
| `$removeUnused` | `bool` | If obsolete translations should be removed |
| `$sort` | `bool` | If translations should be sorted |
| `$catalog` | `string` | Message catalog |
| `$markUnused` | `bool` | If obsolete translations should be marked |

**Returns**

`mixed`

### saveMessagesToPOT() <span id="method-saveMessagesToPOT"></span>

```php
protected function saveMessagesToPOT(array $messages, string $dirName, string $catalog): mixed
```

Writes messages into POT file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array` |  |
| `$dirName` | `string` | Name of the directory to write to |
| `$catalog` | `string` | Message catalog |

**Returns**

`mixed`

**Since**

2.0.6

### tokensEqual() <span id="method-tokensEqual"></span>

```php
protected function tokensEqual(array|string $a, array|string $b): bool
```

Finds out if two PHP tokens are equal.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$a` | `array\|string` |  |
| `$b` | `array\|string` |  |

**Returns**

`bool`

**Since**

2.0.1