Skip to content

Commit

Permalink
Translations: fix vanishing translation
Browse files Browse the repository at this point in the history
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 thirtybees#976
  • Loading branch information
getdatakick authored and eschiendorfer committed Jul 29, 2020
1 parent 7e86caf commit 758339e
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions controllers/admin/AdminTranslationsController.php
Expand Up @@ -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]);
}
}

Expand Down

0 comments on commit 758339e

Please sign in to comment.