Unverified Commit 18c35487 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3577001 LocaleConfigManager::updateConfigTranslations() unconditionally...

fix: #3577001 LocaleConfigManager::updateConfigTranslations() unconditionally re-saves unchanged config overrides

By: petar_basic
By: alexpott
(cherry picked from commit 2ed9cb80)
parent c7ec79e8
Loading
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -597,7 +597,7 @@ public function updateConfigTranslations(array $names, array $langcodes = []) {
            $this->deleteTranslationOverride($name, $langcode);
            $count++;
          }
          elseif (!empty($data)) {
          elseif (!empty($data) && $override->get() !== $data) {
            // Update translation data in configuration override.
            $this->saveTranslationOverride($name, $langcode, $data);
            $count++;
@@ -607,12 +607,14 @@ public function updateConfigTranslations(array $names, array $langcodes = []) {
          // If the language code is the active storage language, we should
          // update. If it is English, we should only update if English is also
          // translatable.
          $active = NestedArray::mergeDeepArray([$active, $processed], TRUE);
          $this->saveTranslationActive($name, $active);
          $data = NestedArray::mergeDeepArray([$active, $processed], TRUE);
          if ($data !== $active) {
            $this->saveTranslationActive($name, $data);
            $count++;
          }
        }
      }
    }
    return $count;
  }

+16 −0
Original line number Diff line number Diff line
@@ -121,6 +121,22 @@ public function testLocaleDeleteActiveTranslation(): void {
    $this->assertEquals('Hungarian test', $this->configFactory->getEditable($config_name)->get('test'));
  }

  /**
   * Tests that unchanged active translations are not re-saved.
   */
  public function testUnchangedActiveTranslationNotResaved(): void {
    $config_name = 'locale_test.translation';

    // After setUp(), the Hungarian active translation already exists. Calling
    // updateConfigTranslations() again without changes should not re-save it.
    $this->localeConfigManager->reset();
    $count = $this->localeConfigManager->updateConfigTranslations([$config_name], ['hu']);
    $this->assertSame(0, $count, 'Unchanged active config translation should not be re-saved.');

    // Verify the active config is still intact.
    $this->assertActiveConfig($config_name, 'test', 'Hungarian test', 'hu');
  }

  /**
   * Tests that adding English creates a translation override.
   */
+19 −0
Original line number Diff line number Diff line
@@ -200,6 +200,25 @@ public function testLocaleDeleteTranslation(): void {
    $this->assertNoTranslation($config_name, 'de');
  }

  /**
   * Tests that unchanged translations are not re-saved.
   *
   * Verifies that updateConfigTranslations() skips saving config overrides
   * when the computed translation data is identical to the existing override.
   */
  public function testUnchangedTranslationNotResaved(): void {
    $config_name = 'locale_test.translation';

    // After setUp(), the German override already exists. Calling
    // updateConfigTranslations() again without changes should not re-save it.
    $this->localeConfigManager->reset();
    $count = $this->localeConfigManager->updateConfigTranslations([$config_name], ['de']);
    $this->assertSame(0, $count, 'Unchanged config translation should not be re-saved.');

    // Verify the override is still intact.
    $this->assertConfigOverride($config_name, 'test', 'German test', 'de');
  }

  /**
   * Sets up a configuration string without a translation.
   *