diff --git a/core/modules/views/src/Views.php b/core/modules/views/src/Views.php index 525177f..1a3ff3c 100644 --- a/core/modules/views/src/Views.php +++ b/core/modules/views/src/Views.php @@ -419,6 +419,7 @@ public static function pluginList() { * - ltitle: The lowercase title of the handler type. * - stitle: A singular title of the handler type. * - lstitle: A singular lowercase title of the handler type. + * - otitle: The original untranslated title of the handler type. * - plural: Plural version of the handler type. * - (optional) type: The actual internal used handler type. This key is * just used for header,footer,empty to link to the internal type: area. @@ -437,6 +438,8 @@ public static function getHandlerTypes() { 'stitle' => static::t('Field'), // Singular lowercase title for mid sentence 'lstitle' => static::t('field'), + // Original title. + 'otitle' => 'Fields', 'plural' => 'fields', ), 'argument' => array( @@ -444,6 +447,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('contextual filters'), 'stitle' => static::t('Contextual filter'), 'lstitle' => static::t('contextual filter'), + 'otitle' => 'Contextual filters', 'plural' => 'arguments', ), 'sort' => array( @@ -451,6 +455,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('sort criteria'), 'stitle' => static::t('Sort criterion'), 'lstitle' => static::t('sort criterion'), + 'otitle' => 'Sort criteria', 'plural' => 'sorts', ), 'filter' => array( @@ -458,6 +463,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('filter criteria'), 'stitle' => static::t('Filter criterion'), 'lstitle' => static::t('filter criterion'), + 'otitle' => 'Filter criteria', 'plural' => 'filters', ), 'relationship' => array( @@ -465,6 +471,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('relationships'), 'stitle' => static::t('Relationship'), 'lstitle' => static::t('Relationship'), + 'otitle' => 'Relationships', 'plural' => 'relationships', ), 'header' => array( @@ -472,6 +479,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('header'), 'stitle' => static::t('Header'), 'lstitle' => static::t('Header'), + 'otitle' => 'Header', 'plural' => 'header', 'type' => 'area', ), @@ -480,6 +488,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('footer'), 'stitle' => static::t('Footer'), 'lstitle' => static::t('Footer'), + 'otitle' => 'Footer', 'plural' => 'footer', 'type' => 'area', ), @@ -488,6 +497,7 @@ public static function getHandlerTypes() { 'ltitle' => static::t('no results behavior'), 'stitle' => static::t('No results behavior'), 'lstitle' => static::t('No results behavior'), + 'otitle' => 'No results behavior', 'plural' => 'empty', 'type' => 'area', ), diff --git a/core/modules/views_ui/src/Tests/ViewsUITourTest.php b/core/modules/views_ui/src/Tests/ViewsUITourTest.php index 86533b3..7030cac 100644 --- a/core/modules/views_ui/src/Tests/ViewsUITourTest.php +++ b/core/modules/views_ui/src/Tests/ViewsUITourTest.php @@ -8,6 +8,7 @@ namespace Drupal\views_ui\Tests; use Drupal\tour\Tests\TourTestBase; +use Drupal\language\Entity\ConfigurableLanguage; /** * Tests the Views UI tour. @@ -28,11 +29,11 @@ class ViewsUITourTest extends TourTestBase { * * @var array */ - public static $modules = array('views_ui', 'tour'); + public static $modules = array('views_ui', 'tour', 'language', 'locale'); protected function setUp() { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour')); + $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour', 'administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->adminUser); } @@ -50,4 +51,77 @@ public function testViewsUiTourTips() { $this->assertTourTips(); } + /** + * Tests views_ui tour tip availability in a different language. + */ + public function testViewsUiTourTipsTranslated() { + $langcode = 'nl'; + + // Enable import of translations. By default this is disabled for automated + // tests. + $this->config('locale.settings') + ->set('translation.import_enabled', TRUE) + ->save(); + + // Add Dutch language programmatically. + ConfigurableLanguage::createFromLangcode($langcode)->save(); + // Import a .po file. + $this->importPoFile($this->getPoFile(), array( + 'langcode' => $langcode, + )); + + // Create a basic view that shows all content, with a page and a block + // display. + $view['label'] = $this->randomMachineName(16); + $view['id'] = strtolower($this->randomMachineName(16)); + $view['page[create]'] = 1; + $view['page[path]'] = $this->randomMachineName(16); + // Load the page in dutch. + $this->drupalPostForm($langcode . '/admin/structure/views/add', $view, t('Save and edit')); + $this->assertTourTips(); + } + + /** + * Helper function: import a standalone .po file in a given language. + * + * @param string $contents + * Contents of the .po file to import. + * @param array $options + * (optional) Additional options to pass to the translation import form. + */ + public function importPoFile($contents, array $options = array()) { + $name = tempnam('temporary://', "po_") . '.po'; + file_put_contents($name, $contents); + $options['files[file]'] = $name; + $this->drupalPostForm('admin/config/regional/translate/import', $options, t('Import')); + drupal_unlink($name); + } + + /** + * Helper function that returns a proper .po file. + */ + public function getPoFile() { + return <<< EOF +msgid "" +msgstr "" +"Project-Id-Version: Drupal 8\\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=UTF-8\\n" +"Content-Transfer-Encoding: 8bit\\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\\n" + +msgid "Format" +msgstr "Formaat" + +msgid "Fields" +msgstr "Velden" + +msgid "Sort criteria" +msgstr "Sorteercriteria" + +msgid "Filter criteria" +msgstr "Filtercriteria" +EOF; + } + } diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index cdacd9c..f2a1c07 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -556,7 +556,7 @@ public function getDisplayDetails($view, $display) { $build['columns'][$column][$id] = $bucket['build']; $build['columns'][$column][$id]['#theme_wrappers'][] = 'views_ui_display_tab_bucket'; $build['columns'][$column][$id]['#title'] = !empty($bucket['title']) ? $bucket['title'] : ''; - $build['columns'][$column][$id]['#name'] = !empty($bucket['title']) ? $bucket['title'] : $id; + $build['columns'][$column][$id]['#name'] = $id; } } @@ -932,7 +932,8 @@ public function getFormBucket(ViewUI $view, $type, $display) { $build['#overridden'] = FALSE; $build['#defaulted'] = FALSE; - $build['#name'] = $build['#title'] = $types[$type]['title']; + $build['#name'] = $types[$type]['otitle']; + $build['#title'] = $types[$type]['title']; $rearrange_url = Url::fromRoute('views_ui.form_rearrange', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type]); $class = 'icon compact rearrange';