diff --git a/core/modules/views/src/Tests/Plugin/PagerTest.php b/core/modules/views/src/Tests/Plugin/PagerTest.php index c821950..e16d6b1 100644 --- a/core/modules/views/src/Tests/Plugin/PagerTest.php +++ b/core/modules/views/src/Tests/Plugin/PagerTest.php @@ -332,9 +332,9 @@ function testPagerApi() { } /** - * Test the pager in a different language. + * Tests translating the pager using config_translation. */ - public function testPagerMultilingual() { + public function testPagerConfigTranslation() { $view = Views::getView('content'); $display = &$view->storage->getDisplay('default'); $display['display_options']['pager']['options']['items_per_page'] = 5; @@ -383,4 +383,63 @@ public function testPagerMultilingual() { $this->assertRaw($translation); } } + + /** + * Tests translating the pager using locale. + */ + public function testPagerLocale() { + // Enable locale and language module. + $this->container->get('module_installer')->install(array('locale', 'language')); + $this->resetAll(); + $langcode = 'nl'; + + // Add a default locale storage for this test. + $this->localeStorage = $this->container->get('locale.storage'); + + // Add Dutch language programmatically. + ConfigurableLanguage::createFromLangcode($langcode)->save(); + + // Labels that need translations. + $labels = array( + '« first' => '« eerste', + '‹ previous' => '‹ vorige', + 'next ›' => 'volgende ›', + 'last »' => 'laatste »', + ); + foreach ($labels as $label => $translation) { + // Create source string. + $source = $this->localeStorage->createString( + array( + 'source' => $label + ) + ); + $source->save(); + $this->createTranslation($source, $translation, $langcode); + } + + // We create 11 nodes, this will give us 3 pages. + $this->drupalCreateContentType(array('type' => 'page')); + for ($i = 0; $i < 11; $i++) { + $this->drupalCreateNode(); + } + + // Go to the second page so we see both previous and next buttons. + $this->drupalGet('nl/test_pager_full', array('query' => array('page' => 1))); + foreach ($labels as $label => $translation) { + // Check if we can find the translation. + $this->assertRaw($translation); + } + } + + /** + * Creates single translation for source string. + */ + protected function createTranslation($source, $translation, $langcode) { + $values = array( + 'lid' => $source->lid, + 'language' => $langcode, + 'translation' => $translation, + ); + return $this->localeStorage->createTranslation($values)->save(); + } } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_pager_full.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_pager_full.yml index a347a76..9c61403 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_pager_full.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_pager_full.yml @@ -34,3 +34,11 @@ display: display_title: Master id: default position: 0 +page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: test_pager_full