diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 290a2e04e8..2cbf31603a 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -27,7 +27,7 @@ Yii Framework 2 Change Log - Bug #18913: Add filename validation for `MessageSource::getMessageFilePath()` (uaoleg) - Bug #18909: Fix bug with binding default action parameters for controllers (bizley) - Bug #18955: Check `yiisoft/yii2-swiftmailer` before using as default mailer in `yii\base\Application` (WinterSilence) -- Enh #18962: Extend ignore list in `yii\console\MessageController::$except` (WinterSilence) +- Bug #18988: Fix default value of `yii\console\controllers\MessageController::$translator` (WinterSilence) 2.0.43 August 09, 2021 diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index 17dcb899dc..5eb1e312a0 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -58,12 +58,11 @@ class MessageController extends \yii\console\Controller */ public $languages = []; /** - * @var string|array 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. + * @var string|string[] 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. */ - public $translator = 'Yii::t'; + public $translator = ['Yii::t', '\Yii::t']; /** * @var bool whether to sort messages by keys when merging new messages * with the existing ones. Defaults to false, which means the new (untranslated) diff --git a/tests/framework/console/controllers/BaseMessageControllerTest.php b/tests/framework/console/controllers/BaseMessageControllerTest.php index 87a186fceb..b3485967e4 100644 --- a/tests/framework/console/controllers/BaseMessageControllerTest.php +++ b/tests/framework/console/controllers/BaseMessageControllerTest.php @@ -170,7 +170,8 @@ abstract class BaseMessageControllerTest extends TestCase { $category = 'test.category1'; $message = 'test message'; - $sourceFileContent = "Yii::t('{$category}', '{$message}');"; + $message2 = 'test message 2'; + $sourceFileContent = "Yii::t('{$category}', '{$message}');\n\Yii::t('{$category}', '{$message2}');"; $this->createSourceFile($sourceFileContent); $this->saveConfigFile($this->getConfig()); @@ -178,6 +179,7 @@ abstract class BaseMessageControllerTest extends TestCase $messages = $this->loadMessages($category); $this->assertArrayHasKey($message, $messages, "\"$message\" is missing in translation file. Command output:\n\n" . $out); + $this->assertArrayHasKey($message2, $messages, "\"$message2\" is missing in translation file. Command output:\n\n" . $out); } /**