Commit e3003f60 authored by webchick's avatar webchick

Issue #2424445 by geertvd, dobrzyns, rpayanm, Gábor Hojtsy, Cottser, alexpott,...

Issue #2424445 by geertvd, dobrzyns, rpayanm, Gábor Hojtsy, Cottser, alexpott, jmauro8ac: Views default options such as pager options are not translated
parent e748ee2a
......@@ -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:
......
......@@ -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');
......
......@@ -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',
);
......
......@@ -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');
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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(
......
......@@ -43,13 +43,13 @@ abstract class ExposedFormPluginBase extends PluginBase {
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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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.
......@@ -30,6 +31,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.
*
......@@ -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();
}
}
......@@ -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
......@@ -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;
}
......
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