Commit 5ff53d74 authored by alexpott's avatar alexpott
Browse files

Issue #2460259 by sasanikolic, ameenkhan07: Multiple calls to...

Issue #2460259 by sasanikolic, ameenkhan07: Multiple calls to LocaleConfigManager::getStringTranslation can return multiple new translation objects for the same source
parent bd2e540e
......@@ -433,7 +433,9 @@ public function getStringTranslation($name, $langcode, $source, $context) {
if ($string = $this->translations[$name][$langcode][$context][$source]) {
if (!$string->isTranslation()) {
$conditions = array('lid' => $string->lid, 'language' => $langcode);
return $this->localeStorage->createTranslation($conditions);
$translation = $this->localeStorage->createTranslation($conditions);
$this->translations[$name][$langcode][$context][$source] = $translation;
return $translation;
}
else {
return $string;
......
......@@ -40,4 +40,25 @@ public function testHasTranslation() {
$result = $locale_config_manager->hasTranslation('locale_test.translation', $language->getId());
$this->assertTrue($result, 'There is a translation for locale_test.translation configuration.');
}
/**
* Tests getStringTranslation().
*/
public function testGetStringTranslation() {
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
$this->installConfig(array('locale_test'));
$locale_config_manager = \Drupal::service('locale.config_manager');
$language = ConfigurableLanguage::createFromLangcode('de');
$language->save();
$translation_before = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
$this->assertTrue($translation_before->isNew());
$translation_before->setString('translation')->save();
$translation_after = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
$this->assertFalse($translation_after->isNew());
$translation_after->setString('updated_translation')->save();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment