Problem/Motivation
In English, in the Views UI, at the top there is a list of links that lets you add Block, Page, etc. displays to your view. It looks like this:
If you look at the HTML though, actually each entry in the list has a link that says "Add Block", "Add page", etc. But something is being done in JavaScript to remove the word Add.
This doesn't work in Hungarian, because the order is reversed -- instead of "Add ____" it says "____ hozzaadaza" (forgive me for butchering the Hungarian). And the Add at the top says Hozzaadas -- capitalized and not the same word. I haven't looked at the JavaScript, but I think it must be somehow looking for the word "Add" at the beginning to be repeated in each link and removing it? Anyway, it doesn't work in at least this one other language. Here is what it looks like:
(I noticed this because I was making automated screenshots for the User Guide in Hungarian, and it didn't look the same as my English screenshot.)
Proposed resolution
Either:
(a) make the links actually say just "Block", "Page", etc. without the funky JavaScript thing going on
(b) fix the funky JavaScript thing so it will work in other languages
(c) decide this is unimportant and do not worry about it in other languages
(d) don't do it at all even in English
Remaining tasks
Decide what to do, and do it. Or close this as "Won't fix".
User interface changes
Possibly.
API changes
No.
Data model changes
No.
Comment | File | Size | Author |
---|---|---|---|
#40 | 2807241_40.patch | 5.45 KB | Stefdewa |
#40 | interdiff_38_40.txt | 564 bytes | Stefdewa |
#38 | 2807241_38.patch | 5.46 KB | Stefdewa |
#38 | interdiff_32_38.txt | 651 bytes | Stefdewa |
#37 | 2807241_37.patch | 5.6 KB | Stefdewa |
Comments
Comment #2
jhodgdonAnd by the way, it doesn't work in Catalan either. In this case, the word "Add" apparently comes first in the strings, unlike Hungarian where it comes last, but it is still not removed from "Afegeix Bloc" etc. See screenshot:
Comment #3
jhodgdonHere's the code that is doing this. It's in core/modules/views_ui/js/vies-admin.js in class/objectDrupal.behaviors.viewsUiRenderAddViewButton:
So. The comment here is incorrect, because the variable $addDisplayDropdown a few lines up is actually translating the word "Add".
And what really needs to happen here is ... Hm. The label here is actually coming from a call in PHP to t('Add @type') with the @type substituted in from a call to something like t('Block') or t('Page') or t('Attachment') [the defined types of displays you can add]. So the JavaScript needs to call Drupal.t('Add @type') and then figure out where the "@type" appears in the string for the current language. Then it can extract that out.
For instance, if the translation of "Add @type" is something like "Foo @type barz", then it would need to take a substring that chops off the first 4 characters and the last 5, to find the "@type" portion of the label. If @type is at the start, then don't chop off anything at the start; if it's at the end, then don't chop off anything at the end. Pretty easy to calculate and achieve, using the JavaScript substr() method on strings. str.length(4) would take everything starting at character 4 to the end of the string, and str.length(-5) would take everything but the last 5 characters.
Let's see... how about this patch? I'm testing it in English, Hungarian, and Catalan by making User Guide screenshots, and will posts them when the tests finish. Or post a better patch if it doesn't work right. ;)
Comment #4
jhodgdonThat patch wasn't quite right. Here's a new one that works for English, Hungarian (where "Add" is a suffix), and Catalan (where "Add" is a prefix, but not 3 characters long). And some screenshots.
English:
Hungarian:
Catalan:
Comment #5
jhodgdonAdding some tags.
Also note that the CSS for this drop-down needs some adjustment probably, but that was present in the "Before" screenshots in the issue summary, and fixing it is probably out of scope for this issue. (The left side of the buttons in the drop-down list is cut off for some reason by the CSS.)
Comment #6
dawehnerInteresting, nice catch!
Comment #7
droplet CreditAttribution: droplet commentedwill it work?
Comment #8
dawehnerThis is just beatiful! Thank you @droplet. Can we add some javascript test to ensure the UI works in the other language as well?
Comment #9
jhodgdonYes, it definitely makes the JS code much less funky! A good thing.
Comment #10
droplet CreditAttribution: droplet commentedAny D8MI member could suggest me an efficient way (programmatically, I guess?) or help to write a patch for "Enable & Import second UI Lang" part.
Comment #11
jhodgdonYou'll need to have the modules language and locale enabled.
Then in your test you can go to admin/config/regional/language/add and submit the form there with drupalPostForm, using something like
and hitting the button 'Add language'.
Comment #15
LendudeReroll. Still needs those tests.
Comment #16
borisson_Needs work based to add the tests.
Comment #22
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedStarting work on test.
Comment #23
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedRerolled patch for 9.4.x. Now continue with tests.
Comment #24
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedAdded test. It checks for 'Blokk' in the dropdown inside the view in Hungarian. Without the patch this will fail because it will find 'Blokk hozzáadása'.
Comment #25
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedAdding a test-only patch to show a failing test for the current codebase.
Added the complete patch also so testbot checks this patch last.
Comment #26
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedSetting back to "Needs work", will fix CSpell error tomorrow.
Comment #27
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedCouldn't wait till tomorrow. Added CSpell ignore.
Comment #28
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedFixed es6 error in JS fix.
Comment #30
dwwThis looks interesting. Will try to review when I have a chance.
Comment #31
Lendude@Stefdewa nice job, great talking to you at DDD! Just some nitpicking:
Doc block needs something more specific.
I think this can just be one findAll('css', '.add ul input'), no need to chain it
Might be better to use getText here so we are sure we are testing what the user is seeing.
Comment #32
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedAdded an interdiff between 28 and 32.
Comment #34
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedSetting "Needs review" again. Tests are green.
Comment #35
Lendude@Stefdewa thanks for working on this.
Looks good to me now, we got tests, RTBC.
Comment #36
alexpottI think we can do
'data-drupal-dropdown-label' => $label,
here.'@display'
is not really a translatable string - ie. there's nothing to add. And $label is already a translatable string.Comment #37
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedUpdated per #36.
Comment #38
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedA new line got in there somewhere. Removed it and created patch again.
Comment #39
pjbaertI found one more nitpick:
The test title is too long. I suggest we rewrite this to: "Test if 'add' translations are filtered from multilingual display options."
Comment #40
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedGood catch. Updated comment.
Comment #41
Stefdewa CreditAttribution: Stefdewa at Calibrate commentedComment #42
pjbaertGreat work!
Since only a comment was updated (& nothing functional was changed & all test passed on previous patch), I feel it safe to assume this is RTBC again.
Comment #43
alexpottCommitted 9182f0a and pushed to 10.0.x. Thanks!
Committed 7953bb5 and pushed to 9.4.x. Thanks!
Not porting to 9.3.x because JS change and UI change.