diff --git a/core/modules/locale/locale.post_update.php b/core/modules/locale/locale.post_update.php new file mode 100644 index 0000000000..91728f305e --- /dev/null +++ b/core/modules/locale/locale.post_update.php @@ -0,0 +1,13 @@ +storage[$offset] = $value; // Disabling the usage of string caching allows a module to watch for // the exact list of strings used on a page. From a performance diff --git a/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php b/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php index 5f3e5f7e80..3d2cca417e 100644 --- a/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php @@ -4,6 +4,7 @@ use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\Core\Cache\CacheCollectorHelper; /** * Tests LocaleLookup. @@ -55,4 +56,38 @@ public function testLanguageFallbackDefaults() { $this->assertEqual($context['operation'], 'locale_lookup'); } + /** + * Test old plural style @count[number] fix. + */ + public function testFixOldPluralStyle() { + /** @var \Drupal\locale\StringDatabaseStorage $string_storage */ + $string_storage = \Drupal::service('locale.storage'); + + $string = $string_storage->findString(['source' => 'Member for', 'context' => '']); + + // Create translation with old @count[2] plural style. + $string_storage->createTranslation([ + 'lid' => $string->getId(), + 'language' => 'fr', + 'translation' => '@count[2] old-plural-test', + ])->save(); + + // Assert that @count[2] was fixed with caching. + drupal_flush_all_caches(); + $this->drupalGet(''); + $this->assertSession()->pageTextContains('@count old-plural-test'); + + // Assert that @count[2] wasn't fixed after caching. + drupal_flush_all_caches(); + $collector = new CacheCollectorHelper('locale:fr::authenticated', $this->container->get('cache.default'), $this->container->get('lock')); + $collector->set('Member for', '@count[2] old-plural back'); + $collector->destruct(); + $this->drupalGet(''); + $this->assertSession()->pageTextContains('@count[2] old-plural back'); + + // Assert that source not changed. + $translation = $string_storage->findTranslation(['language' => 'fr', 'lid' => $string->getId()])->translation; + $this->assertSame('@count[2] old-plural-test', $translation); + } + }