From fb2dff85287253c558517d50133c8a80fe7637af Mon Sep 17 00:00:00 2001
From: Alexander Makarov <sam@rmcreative.ru>
Date: Fri, 21 Nov 2014 20:19:32 +0300
Subject: [PATCH] Fixes #6107 and #6112: `yii message` was emptying existing translations and incorrectly writing not yet translated strings in .po in case of multiple categories

---
 framework/CHANGELOG.md                              | 4 +++-
 framework/console/controllers/MessageController.php | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md
index 3729935..c60abce 100644
--- a/framework/CHANGELOG.md
+++ b/framework/CHANGELOG.md
@@ -26,7 +26,9 @@ Yii Framework 2 Change Log
 - Bug #5925: `ArrayHelper::htmlEncode()` does not work properly when the value being encoded is a nested array (tebazil)
 - Bug #5997: The same message may be exported twice to log targets (klimov-paul)
 - Bug #6018: When setting the `encode` option via `yii\widgets\ActiveRecord::errorOptions`, it works the other way around (stanishevsky, qiangxue)
-- Bug #6049: `yii\db\Connection::getSchema()` for Oracle should return false when the table does not exist. Oracle does not support `ON UPDATE` clause. (wenbin1989) 
+- Bug #6049: `yii\db\Connection::getSchema()` for Oracle should return false when the table does not exist. Oracle does not support `ON UPDATE` clause. (wenbin1989)
+- Bug #6107: `yii message` was emptying existing translations in .po in case of multiple categories (samdark)
+- Bug #6112: `yii message` was incorrectly writing not yet translated strings in .po in case of multiple categories (samdark)
 - Bug: Gii console command help information does not contain global options (qiangxue)
 - Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark)
 - Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark)
diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php
index a060e3f..683f9d8 100644
--- a/framework/console/controllers/MessageController.php
+++ b/framework/console/controllers/MessageController.php
@@ -408,11 +408,11 @@ EOD;
 
 
         $merged = [];
-        $notTranslatedYet = [];
         $todos = [];
 
         $hasSomethingToWrite = false;
         foreach ($messages as $category => $msgs) {
+            $notTranslatedYet = [];
             $msgs = array_values(array_unique($msgs));
 
             if (is_file($file)) {
@@ -425,7 +425,7 @@ EOD;
 
                     sort($msgs);
                     foreach ($msgs as $message) {
-                        $merged[$category . chr(4) . $message] = '';
+                        $merged[$category . chr(4) . $message] = $existingMessages[$message];
                     }
                     ksort($merged);
                     continue;
--
libgit2 0.27.1