Skip to content

Commit

Permalink
Support extracting concatenated strings in yii message yiisoft#13824
Browse files Browse the repository at this point in the history
  • Loading branch information
developeruz committed Jun 20, 2017
1 parent 0973117 commit 5e52f55
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Yii Framework 2 Change Log
- Bug #14307: Fixed PHP warning when `yii\console\UnknownCommandException` is thrown for empty command (rob006)
- Chg #14201: `yii\console\controllers\MessageController::extractMessagesFromTokens()` is now protected (faenir)
- Enh #13787: Added `yii\db\Migration::$maxSqlOutputLength` that allows limiting number of characters for outputting SQL (thiagotalma)
- Enh #13824: Support extracting concatenated strings in `yii message` (developeruz)
- Enh #14089: Added tests for `yii\base\Theme` (vladis84)
- Enh #13586: Added `$preserveNonEmptyValues` property to the `yii\behaviors\AttributeBehavior` (Kolyunya)
- Bug #14192: Fixed wrong default null value for TIMESTAMP when using PostgreSQL (Tigrov)
Expand Down
10 changes: 8 additions & 2 deletions framework/console/controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,15 @@ protected function extractMessagesFromTokens(array $tokens, array $translatorTok
$category = mb_substr($category, 1, -1);

if (!$this->isCategoryIgnored($category, $ignoreCategories)) {
$message = stripcslashes($buffer[2][1]);
$message = mb_substr($message, 1, -1);

$fullMessage = mb_substr($buffer[2][1], 1, -1);
$i = 3;
while ($i < count($buffer) - 1 && !is_array($buffer[$i]) && $buffer[$i] == '.') {
$fullMessage .= mb_substr($buffer[$i + 1][1], 1, -1);
$i += 2;
}

$message = stripcslashes($fullMessage);
$messages[$category][] = $message;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/framework/console/controllers/BaseMessageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,26 @@ public function testMissingLanguage()
$this->language = $firstLanguage;
$this->assertArrayHasKey($mainMessage, $messages, "\"$mainMessage\" for language \"$secondLanguage\" is missing in translation file. Command output:\n\n" . $out);
}

/**
* @depends testCreateTranslation
*
* @see https://github.com/yiisoft/yii2/issues/13824
*/
public function testCreateTranslationFromConcatenatedString()
{
$category = 'test.category1';
$mainMessage = 'main message second message third message';
$sourceFileContent = "Yii::t('{$category}', 'main message'.' second message'.' third message');";
$this->createSourceFile($sourceFileContent);

$this->saveConfigFile($this->getConfig());
$out = $this->runMessageControllerAction('extract', [$this->configFileName]);

$messages = $this->loadMessages($category);
$this->assertArrayHasKey($mainMessage, $messages,
"\"$mainMessage\" is missing in translation file. Command output:\n\n" . $out);
}
}

class MessageControllerMock extends MessageController
Expand Down

0 comments on commit 5e52f55

Please sign in to comment.