Problem/Motivation
Install Drupal in Dutch (Nederlands). Go edit a view. Go to view the tour on the top right of the page. The view has 4 pages instead of the 10 expected.
This is due to how the tour expects class names and IDs to match on the page to place tips. Views however uses the translated name label of the UI section to add a class, see views-ui-display-tab-bucket.html.twig where the class is added and template_preprocess_views_ui_display_tab_bucket where the name is copied from the element and ViewsEditForm::getDisplayDetails() where the #name is taken from a bucket title. The bucket title is only available in a translated form and may be coming from a handler label as well in Views::getHandlerTypes().

Proposed resolution
Add some way to pass on a non-translated value to use for a class so CSS and tour can tie to something predictable.
Remaining tasks
Agree on approach. Implement. Review. Commit.
| Comment | File | Size | Author |
|---|---|---|---|
| #59 | views_translated_class_names-2409581-59-complete.patch | 7.63 KB | geertvd |
| #59 | views_translated_class_names-2409581-59-tests.patch | 2.62 KB | geertvd |
| #59 | interdiff.txt | 4.01 KB | geertvd |
| #55 | views_translated_class_names-2409581-55-complete.patch | 8.24 KB | geertvd |
| #55 | interdiff.txt | 676 bytes | geertvd |
Comments
Comment #1
balagan commentedJust a wild guess, is it related to https://www.drupal.org/node/2363099 ?
Comment #2
balagan commentedComment #3
balagan commentedComment #4
gábor hojtsyTours are not content, so #2363099: Using translated field definition descriptions in entity schema results in different schema definitions, resulting in update.php changes should not be related. I'm surprised if this this happens because we merge translations into original config, so it should not remove items.
Comment #5
gábor hojtsyComment #6
balagan commentedI had difficulties to reproduce this issue. I had to reroll to commit 6efd90c8dced579e1624f35e86f75a17ea71cf04, but even then, the problem only appeared after adding the hebrew language, and the Hungarian language added earlier had correct number of pages (10).
Comment #7
balagan commentedSteps to reproduce: Install D8, enable language module, enable interface translation, add a language (af), add another language (nl), the tour for the second language I have added only had 4 pages. The first language added had 10 pages. This only occured on the admin/structure/views/view/content tour pages, for example on admin/config/regional/translate the tours had same number of pages.
Comment #8
gábor hojtsyPlease export all your configuration at Admin > Configuration > Configuration management. You get a package download. Unzip that and look at the language directory and the yml files there. Can you post the two overrides for those two languages here?
Comment #9
gábor hojtsyComment #10
balagan commentedOk, I have removed the languages, and added back in different order (nl first, then af) the problem did not occured. (I am tearing my hair already). I will export config when I manage to reproduce the problem again.
Comment #11
balagan commentedAfter adding af and nl in this sequence this issue appeared again. I did a full export and zipped the language directory containing the two language overrides.
Comment #12
gábor hojtsySo the Afrikaans has one item in the override:
The Dutch one has three:
Neither has 10 page titles translated. In fact the Afrikaans has less translated. So that that would display 10 and the Dutch would display 4 sounds strange still :) I am glad it is reproducible.
Comment #13
balagan commentedYeah, and as I mentioned above, if I add them in different order (nl first, then af), everything is fine.
Comment #14
gábor hojtsyLooked into this. Tour steps are generated into the page markup at the end:
<div class="item-list"><ol id="tour" class="hidden"><li ....</div>When you load the bogus page BEFORE you hit the Tour button, it has 10 steps, ie "4 van 10", "8 van 10" etc. When you hit the tour button, it is reduced to 4 steps visible int the rewritten page as well.
Comment #15
gábor hojtsytour.js has a _removeIrrelevantTourItems() method which does the removal of items based on some criteria and the renumbering of steps which is happening in this case.
Comment #16
gábor hojtsyIndeed, what I found stepping into this is that the tour items with ID attachments were kept. The tour items with class attachments are not. The classes in the markup are translated. Should not be:
I think this may lead to bigger problems, therefore major.
Comment #17
balagan commentedMy classes are not translated. Interestingly, the condition:
itemClass && $document.find('.' + itemClass).lengthwill not equal true, because $document.find('.' + itemClass).length is zero. On the correct 'af' page it is 1.Comment #18
gábor hojtsy@balagan: those are the class name that are being looked for (as defined in the tour). Go up in the markup and look at the class names in views. The problem is tour looks for class names not in the document, because views translates them.
The bug seems to be in
core/modules/views_ui/templates/views-ui-display-tab-bucket.html.twig:Comment #19
gábor hojtsyBetter title. The translated handler / bucket names come from eg. Views.php (static::t('Sort criteria')), (static::t('Filter criteria')) as well as displays such as DisplayPluginBase ($this->t('Format')).
Comment #20
gábor hojtsyUpdated issue summary.
Comment #21
balagan commentedI've got as far, that the name variable in \core\modules\views_ui\templates\views-ui-display-tab-bucket.html.twig is already translated.
Don't know where that is coming from.
Comment #22
balagan commentedComment #23
balagan commentedOk, name comes from here: https://api.drupal.org/api/drupal/core%21modules%21views_ui%21views_ui.t...
Now I know what Gábor was talking about :)
Comment #24
geertvd commentedNot sure if this is the way since the class names are not so descriptive anymore to go but this fixes it.
Comment #25
geertvd commentedComment #27
gábor hojtsy@geertvd: that seems to be failing on this test:
Comment #28
geertvd commentedApparently changing those class names wasn't a good idea since this breaks some other tests.
In this one I'm just passing the untranslated title along.
Comment #29
geertvd commentedComment #31
geertvd commentedignore interdiff failing, I should use txt extension there.
Comment #33
geertvd commentedComment #34
balagan commentedIt looks good now, I will try manual testing of the patch.
Comment #35
balagan commentedComment #36
balagan commentedI can confirm that with the patch applied the tour translations display with proper number of pages.
Comment #38
dawehnerGood catch!
Comment #39
balagan commentedI guess this causes the tests to fail.
Comment #40
balagan commentedI guess this causes the tests to fail.
Comment #42
balagan commentedSince after rerunning the test it is successful, and by testing it manually I see that the problem is solved, I change it to RTBC.
Comment #43
alexpottNice find. Looks like a test would be good.
Comment #44
geertvd commentedAdded test to
ViewsUITourTestComment #45
geertvd commentedComment #47
gábor hojtsyLooks really good. Some notes:
Let's name this variable $langcode, that is our usual variable naming for this.
Indentation is off. Should not end up indented twice.
Wow I did not know this exists. Wow. Huh. Nice.
Comment #48
geertvd commentedComment #49
geertvd commentedComment #50
gábor hojtsyLooks great, thanks!
Comment #52
alexpottI'm not sure that adding yet another thing to this array is worth it. How about using the key instead? Yes that will change the class names but we storing the original title for class names feels ott.
Comment #53
geertvd commentedI agree, should have sticked with my thoughts on #24 and just fix the breaking tests.
Hope this one passes.
Comment #54
gábor hojtsyNow that we are modifying CSS classes, are there CSS selector matching to those classes?
Comment #55
geertvd commentedFound one in a js file, this is supposed to hide the "contextual filter"-textfield in preview but that feature seems broken perhaps a new (minor) issue should be opened for that?
Comment #56
gábor hojtsyI also looked around and did not find other CSS/JS affected. This should be all good now.
Comment #57
dawehnerIs there a reason we don't just save the translated strings via an API function?
Comment #58
gábor hojtsyYeah that is possible to do, although that test would need to make sure to clear all caches proper to reproduce the bug then which may not be very nice either :) #1785086: Introduce a generic API for interface translation strings provided an API.
Comment #59
geertvd commentedFixed this based based on #1785086: Introduce a generic API for interface translation strings. I didn't have to clear the cache to make this work locally though. Don't know if the testbot is going to do this differently.
Comment #60
geertvd commentedComment #62
gábor hojtsyLooks good. Indeed simpler than importing a .po file.
Comment #63
dawehnerGreat, thank you!
Comment #64
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed fca50d2 and pushed to 8.0.x. Thanks!
Comment #66
gábor hojtsyYay and congrats geertvd, balagan!