From 9848e379f6df9d3da17145342f6db70a44ac0839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hu=C4=8D=C3=ADk?= Date: Mon, 8 Jun 2020 18:46:19 +0200 Subject: [PATCH] Translations: fix vanishing translation Since 1.1.0 translations are saved per section. Thirtybees first clears all translation from given section, and then import new translations submitted in form. The clearing mechanism works on prefix bases. If other section starts with the same prefix, its entries would be removed as well. For example, saving `authentication` section would remove all translations from sections `authentication-login` or `authentication-create`. The fix is simple -- don't clear translations at all. Remove only entries if the input post value contain empty string. Closes #976 --- .../admin/AdminTranslationsController.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index ca8b62a61f..a23bd8676d 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -1326,22 +1326,12 @@ protected function writeTranslationFile($overrideFile = false) $_POST['type'] ); - // To deal with vanished translations, remove all translations - // belonging to the saved panel before adding the ones POSTed. - $keyBase = array_keys($_POST)[0]; - if ($keyBase) { - $keyBase = substr($keyBase, 0, strrpos($keyBase, '_')); - foreach (array_keys($translationsArray) as $key) { - if (strpos($key, $keyBase) === 0 /* start of string! */) { - unset($translationsArray[$key]); - } - } - } - - // Get all POST which aren't empty + // update translations foreach ($_POST as $key => $value) { if (!empty($value)) { $translationsArray[$key] = $value; + } else { + unset($translationsArray[$key]); } }