mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 14:28:27 +08:00
Fixes #14016: Fixed empty messages marked as unused in PHP and PO sources when extracted with message command when markUnused
is false
This commit is contained in:

committed by
GitHub

parent
66723d0e74
commit
6bde69aa96
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.13 under development
|
2.0.13 under development
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
- Bug #14016: Fixed empty messages marked as unused in PHP and PO sources when extracted with message command when `markUnused` is `false` (samdark)
|
||||||
- Enh #9438: `yii\web\DbSession` now relies on error handler to display errors (samdark)
|
- Enh #9438: `yii\web\DbSession` now relies on error handler to display errors (samdark)
|
||||||
- Bug #6226: Fix fatal symlink error when publishing in multi threaded environments (dynasource)
|
- Bug #6226: Fix fatal symlink error when publishing in multi threaded environments (dynasource)
|
||||||
- Enh #13486: Use DI container to instantiate cookies in order to be able to set defaults (samdark)
|
- Enh #13486: Use DI container to instantiate cookies in order to be able to set defaults (samdark)
|
||||||
|
@ -702,7 +702,7 @@ EOD;
|
|||||||
ksort($existingMessages);
|
ksort($existingMessages);
|
||||||
foreach ($existingMessages as $message => $translation) {
|
foreach ($existingMessages as $message => $translation) {
|
||||||
if (!$removeUnused && !isset($merged[$message]) && !isset($todo[$message])) {
|
if (!$removeUnused && !isset($merged[$message]) && !isset($todo[$message])) {
|
||||||
if (!empty($translation) && (!$markUnused || (strncmp($translation, '@@', 2) === 0 && substr_compare($translation, '@@', -2, 2) === 0))) {
|
if (!$markUnused || (!empty($translation) && (strncmp($translation, '@@', 2) === 0 && substr_compare($translation, '@@', -2, 2) === 0))) {
|
||||||
$todo[$message] = $translation;
|
$todo[$message] = $translation;
|
||||||
} else {
|
} else {
|
||||||
$todo[$message] = '@@' . $translation . '@@';
|
$todo[$message] = '@@' . $translation . '@@';
|
||||||
@ -804,7 +804,7 @@ EOD;
|
|||||||
// add obsolete unused messages
|
// add obsolete unused messages
|
||||||
foreach ($existingMessages as $message => $translation) {
|
foreach ($existingMessages as $message => $translation) {
|
||||||
if (!$removeUnused && !isset($merged[$category . chr(4) . $message]) && !isset($todos[$category . chr(4) . $message])) {
|
if (!$removeUnused && !isset($merged[$category . chr(4) . $message]) && !isset($todos[$category . chr(4) . $message])) {
|
||||||
if (!empty($translation) && (!$markUnused || (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@'))) {
|
if (!$markUnused || (!empty($translation) && ((substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@')))) {
|
||||||
$todos[$category . chr(4) . $message] = $translation;
|
$todos[$category . chr(4) . $message] = $translation;
|
||||||
} else {
|
} else {
|
||||||
$todos[$category . chr(4) . $message] = '@@' . $translation . '@@';
|
$todos[$category . chr(4) . $message] = '@@' . $translation . '@@';
|
||||||
|
@ -478,6 +478,41 @@ abstract class BaseMessageControllerTest extends TestCase
|
|||||||
$this->assertArrayHasKey($mainMessage, $messages,
|
$this->assertArrayHasKey($mainMessage, $messages,
|
||||||
"\"$mainMessage\" is missing in translation file. Command output:\n\n" . $out);
|
"\"$mainMessage\" is missing in translation file. Command output:\n\n" . $out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://github.com/yiisoft/yii2/issues/14016
|
||||||
|
*/
|
||||||
|
public function testShouldNotMarkUnused()
|
||||||
|
{
|
||||||
|
$category = 'my';
|
||||||
|
|
||||||
|
$key1 = 'key1';
|
||||||
|
$key2 = 'key2';
|
||||||
|
|
||||||
|
$this->saveMessages(
|
||||||
|
[
|
||||||
|
$key1 => '',
|
||||||
|
$key2 => '',
|
||||||
|
],
|
||||||
|
$category
|
||||||
|
);
|
||||||
|
|
||||||
|
$sourceFileContent = 'Yii::t("my", "test");';
|
||||||
|
$this->createSourceFile($sourceFileContent);
|
||||||
|
|
||||||
|
$this->saveConfigFile($this->getConfig(['markUnused' => false]));
|
||||||
|
$out = $this->runMessageControllerAction('extract', [$this->configFileName]);
|
||||||
|
$messages = $this->loadMessages($category);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey($key1, $messages, "$key1 isn't there. Command output:\n\n" . $out);
|
||||||
|
$this->assertArrayHasKey($key2, $messages, "$key2 isn't there. Command output:\n\n" . $out);
|
||||||
|
|
||||||
|
$value1 = $messages[$key1];
|
||||||
|
$value2 = $messages[$key2];
|
||||||
|
|
||||||
|
$this->assertEquals('', $value1, "Message at $key1 should be empty but it is $value1. Command output:\n\n" . $out);
|
||||||
|
$this->assertEquals('', $value2, "Message at $key2 should be empty but it is $value2. Command output:\n\n" . $out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageControllerMock extends MessageController
|
class MessageControllerMock extends MessageController
|
||||||
|
Reference in New Issue
Block a user