diff --git a/core/modules/node/config/install/views.view.content.yml b/core/modules/node/config/install/views.view.content.yml index bb1e2c0..523cc9d 100644 --- a/core/modules/node/config/install/views.view.content.yml +++ b/core/modules/node/config/install/views.view.content.yml @@ -37,6 +37,11 @@ display: type: full options: items_per_page: 50 + tags: + previous: '‹ previous' + next: 'next ›' + first: '« first' + last: 'last »' style: type: table options: diff --git a/core/modules/node/tests/src/Unit/Plugin/views/field/NodeBulkFormTest.php b/core/modules/node/tests/src/Unit/Plugin/views/field/NodeBulkFormTest.php index 452c514..8c5456c 100644 --- a/core/modules/node/tests/src/Unit/Plugin/views/field/NodeBulkFormTest.php +++ b/core/modules/node/tests/src/Unit/Plugin/views/field/NodeBulkFormTest.php @@ -60,6 +60,7 @@ public function testConstructor() { ->will($this->returnValue(array('table' => array('entity type' => 'node')))); $container = new ContainerBuilder(); $container->set('views.views_data', $views_data); + $container->set('string_translation', $this->getStringTranslationStub()); \Drupal::setContainer($container); $storage = $this->getMock('Drupal\views\ViewEntityInterface'); diff --git a/core/modules/system/src/Plugin/views/field/BulkForm.php b/core/modules/system/src/Plugin/views/field/BulkForm.php index 7270571..f4a2545 100644 --- a/core/modules/system/src/Plugin/views/field/BulkForm.php +++ b/core/modules/system/src/Plugin/views/field/BulkForm.php @@ -81,7 +81,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o */ protected function defineOptions() { $options = parent::defineOptions(); - $options['action_title'] = array('default' => 'With selection'); + $options['action_title'] = array('default' => $this->t('With selection')); $options['include_exclude'] = array( 'default' => 'exclude', ); diff --git a/core/modules/user/tests/src/Unit/Plugin/views/field/UserBulkFormTest.php b/core/modules/user/tests/src/Unit/Plugin/views/field/UserBulkFormTest.php index afead97..0c389cd 100644 --- a/core/modules/user/tests/src/Unit/Plugin/views/field/UserBulkFormTest.php +++ b/core/modules/user/tests/src/Unit/Plugin/views/field/UserBulkFormTest.php @@ -60,6 +60,7 @@ public function testConstructor() { ->will($this->returnValue(array('table' => array('entity type' => 'user')))); $container = new ContainerBuilder(); $container->set('views.views_data', $views_data); + $container->set('string_translation', $this->getStringTranslationStub()); \Drupal::setContainer($container); $storage = $this->getMock('Drupal\views\ViewEntityInterface'); diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index 760bae3..4d252e2 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -169,11 +169,11 @@ protected function defineOptions() { return array(); } * @param array $options * An array which describes the options of a plugin. Each element is an * associative array containing: - * - default: The default value of one option + * - default: The default value of one option. Should be translated to the + * current interface language if translatable. * - (optional) contains: An array which describes the available options * under the key. If contains is set, the default will be ignored and * assumed to be an empty array. - * - (optional) 'translatable': TRUE if it should be translated, else FALSE. * - (optional) 'bool': TRUE if the value is boolean, else FALSE. */ protected function setOptionDefaults(array &$storage, array $options) { diff --git a/core/modules/views/src/Plugin/views/area/Result.php b/core/modules/views/src/Plugin/views/area/Result.php index 8dd56d7..0182c06 100644 --- a/core/modules/views/src/Plugin/views/area/Result.php +++ b/core/modules/views/src/Plugin/views/area/Result.php @@ -28,7 +28,7 @@ protected function defineOptions() { $options = parent::defineOptions(); $options['content'] = array( - 'default' => 'Displaying @start - @end of @total', + 'default' => $this->t('Displaying @start - @end of @total'), ); return $options; diff --git a/core/modules/views/src/Plugin/views/display/Block.php b/core/modules/views/src/Plugin/views/display/Block.php index 391046c..9de84ef 100644 --- a/core/modules/views/src/Plugin/views/display/Block.php +++ b/core/modules/views/src/Plugin/views/display/Block.php @@ -85,7 +85,7 @@ protected function defineOptions() { $options = parent::defineOptions(); $options['block_description'] = array('default' => ''); - $options['block_category'] = array('default' => 'Lists (Views)'); + $options['block_category'] = array('default' => $this->t('Lists (Views)')); $options['block_hide_empty'] = array('default' => FALSE); $options['allow'] = array( diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index 3652e8b..f9ba904 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -43,13 +43,13 @@ protected function defineOptions() { $options = parent::defineOptions(); - $options['submit_button'] = array('default' => 'Apply'); + $options['submit_button'] = array('default' => $this->t('Apply')); $options['reset_button'] = array('default' => FALSE); - $options['reset_button_label'] = array('default' => 'Reset'); - $options['exposed_sorts_label'] = array('default' => 'Sort by'); + $options['reset_button_label'] = array('default' => $this->t('Reset')); + $options['exposed_sorts_label'] = array('default' => $this->t('Sort by')); $options['expose_sort_order'] = array('default' => TRUE); - $options['sort_asc_label'] = array('default' => 'Asc'); - $options['sort_desc_label'] = array('default' => 'Desc'); + $options['sort_asc_label'] = array('default' => $this->t('Asc')); + $options['sort_desc_label'] = array('default' => $this->t('Desc')); return $options; } diff --git a/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php b/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php index f883a91..f6ab6bc 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php +++ b/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php @@ -26,7 +26,7 @@ class InputRequired extends ExposedFormPluginBase { protected function defineOptions() { $options = parent::defineOptions(); - $options['text_input_required'] = array('default' => 'Select any filter and click on Apply to see results', 'translatable' => TRUE); + $options['text_input_required'] = array('default' => $this->t('Select any filter and click on Apply to see results')); $options['text_input_required_format'] = array('default' => NULL); return $options; } diff --git a/core/modules/views/src/Plugin/views/pager/Full.php b/core/modules/views/src/Plugin/views/pager/Full.php index 43a0ca7..3a522e8 100644 --- a/core/modules/views/src/Plugin/views/pager/Full.php +++ b/core/modules/views/src/Plugin/views/pager/Full.php @@ -34,8 +34,8 @@ protected function defineOptions() { // Use the same default quantity that core uses by default. $options['quantity'] = array('default' => 9); - $options['tags']['contains']['first'] = array('default' => '« first'); - $options['tags']['contains']['last'] = array('default' => 'last »'); + $options['tags']['contains']['first'] = array('default' => $this->t('« first')); + $options['tags']['contains']['last'] = array('default' => $this->t('last »')); return $options; } diff --git a/core/modules/views/src/Plugin/views/pager/SqlBase.php b/core/modules/views/src/Plugin/views/pager/SqlBase.php index cf81809..a3d0d22 100644 --- a/core/modules/views/src/Plugin/views/pager/SqlBase.php +++ b/core/modules/views/src/Plugin/views/pager/SqlBase.php @@ -23,19 +23,19 @@ protected function defineOptions() { $options['expose'] = array( 'contains' => array( 'items_per_page' => array('default' => FALSE), - 'items_per_page_label' => array('default' => 'Items per page'), + 'items_per_page_label' => array('default' => $this->t('Items per page')), 'items_per_page_options' => array('default' => '5, 10, 25, 50'), 'items_per_page_options_all' => array('default' => FALSE), - 'items_per_page_options_all_label' => array('default' => '- All -'), + 'items_per_page_options_all_label' => array('default' => $this->t('- All -')), 'offset' => array('default' => FALSE), - 'offset_label' => array('default' => 'Offset'), + 'offset_label' => array('default' => $this->t('Offset')), ), ); $options['tags'] = array( 'contains' => array( - 'previous' => array('default' => '‹ previous'), - 'next' => array('default' => 'next ›'), + 'previous' => array('default' => $this->t('‹ previous')), + 'next' => array('default' => $this->t('next ›')), ), ); return $options; diff --git a/core/modules/views/src/Tests/Plugin/PagerTest.php b/core/modules/views/src/Tests/Plugin/PagerTest.php index 46e75bc..e16d6b1 100644 --- a/core/modules/views/src/Tests/Plugin/PagerTest.php +++ b/core/modules/views/src/Tests/Plugin/PagerTest.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests\Plugin; use Drupal\views\Views; +use Drupal\language\Entity\ConfigurableLanguage; /** * Tests the pluggable pager system. @@ -21,7 +22,7 @@ class PagerTest extends PluginTestBase { * * @var array */ - public static $testViews = array('test_store_pager_settings', 'test_pager_none', 'test_pager_some', 'test_pager_full', 'test_view_pager_full_zero_items_per_page', 'test_view'); + public static $testViews = array('test_store_pager_settings', 'test_pager_none', 'test_pager_some', 'test_pager_full', 'test_view_pager_full_zero_items_per_page', 'test_view', 'content'); /** * Modules to enable. @@ -31,6 +32,13 @@ class PagerTest extends PluginTestBase { public static $modules = array('node', 'views_ui'); /** + * String translation storage object. + * + * @var \Drupal\locale\StringStorageInterface + */ + protected $localeStorage; + + /** * Pagers was sometimes not stored. * * @see http://drupal.org/node/652712 @@ -323,4 +331,115 @@ function testPagerApi() { $this->assertEqual($view->getCurrentPage(), 0, 'Make sure setCurrentPage always sets a valid page number.'); } + /** + * Tests translating the pager using config_translation. + */ + public function testPagerConfigTranslation() { + $view = Views::getView('content'); + $display = &$view->storage->getDisplay('default'); + $display['display_options']['pager']['options']['items_per_page'] = 5; + $view->save(); + + // Enable locale, config_translation and language module. + $this->container->get('module_installer')->install(array('locale', 'language', 'config_translation')); + $this->resetAll(); + + $admin_user = $this->drupalCreateUser(array('access content overview', 'administer nodes', 'bypass node access', 'translate configuration')); + $this->drupalLogin($admin_user); + + $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(); + + $edit = array( + 'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][first]' => '« eerste', + 'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][previous]' => '‹ vorige', + 'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][next]' => 'volgende ›', + 'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][last]' => 'laatste »', + ); + $this->drupalPostForm('admin/structure/views/view/content/translate/nl/edit', $edit, t('Save translation')); + + // 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/admin/content', array('query' => array('page' => 1))); + // Translation mapping.. + $labels = array( + '« first' => '« eerste', + '‹ previous' => '‹ vorige', + 'next ›' => 'volgende ›', + 'last »' => 'laatste »', + ); + foreach ($labels as $label => $translation) { + // Check if we can find the translation. + $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..e17e1a4 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 diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php index ce5afb0..a302062 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php @@ -33,7 +33,7 @@ class DisplayExtenderTest extends DisplayExtenderPluginBase { protected function defineOptions() { $options = parent::defineOptions(); - $options['test_extender_test_option'] = ['default' => 'Empty']; + $options['test_extender_test_option'] = ['default' => $this->t('Empty')]; return $options; }