Problem/Motivation
If you are NOT in English language interface like french for example, language list is ordered by english names and not currently displayed language (french).
Looking at screenshot, you can see first character names are A, B, C, T, D, N, D, E, F...
Language list should be ordered depending of current language display.
Steps to reproduce :
- Enable and select french language
- Go to admin/config/regional/language/add or fr/admin/config/regional/language/add if french is not default
- Languages list is ordered by english name and not french name (Anglais is ordered near e for english and not a for Anglais)
Remaining tasks
Create a WebBaseTest test to check the rendering list is well ordered depending of language display and not language key.
Create a patch to solve the issue.
Review patch and fix.
User interface changes
Language list is now ordered by translated language name. See 2. in #19.
Comments
Comment #2
duaelfrBugs always need tests ;)
Comment #3
goz commentedComment #4
goz commentedActually, languages are translated during render, so the sort is made on english values.
I based translation on CountryManager->getStandardList() way, so replace
New TranslationMarkup()byt()to have translation instead of empty translate markup.Tests has been created to check order is correct.
Comment #5
JulienD commentedWorks fine for me, the patch fix the issue, allowing the language list to be correctly ordered (See attached screenshots)
Comment #6
duaelfrNop sorry.
I have some changes to suggest/post but I'm on my phone right now.
I'll post that tomorrow.
Comment #7
goz commentedHere is a patch with tests only. This test should fail.
Comment #8
goz commentedComment #9
goz commentedWaiting for DuaelFr suggestions
Comment #12
duaelfrLet's comment that in a row.
Two times I lose my comment being stupid, that's enough!
First, your change removes the only call to
TranslatableMarkup. You should remove the related "use" at the top of the file.Then, the good practice is to use
StringTranslationTraitin a class to have access to$this->t()instead of calling thet()function directly.You can have a look at
\Drupal\taxonomy\TaxonomyPermissionsto have a short example.See the related change record: https://www.drupal.org/node/2079611
Comment #13
goz commentedI can't use what is defined in change record : https://www.drupal.org/node/2079611
So i use the same implementation as
\Drupal\taxonomy\TaxonomyPermissionsComment #14
duaelfrExcellent, that was exactly what I meant.
Thank you, you made a good job :)
Comment #15
duaelfrBy the way, if someone wants to make before/after screenshots, that'd fully complete the issue.
See https://www.drupal.org/contributor-tasks/add-screenshots
Comment #16
goz commented@DuaelFr, you needs a coffee, @JulienD already make screenshots #5 ;)
Comment #17
duaelfrTrue ;)
Can you embed them in the issue summary or in a comment to make them more noticeable?
See steps 7 and 8 of the contributor task I linked in #15
Comment #18
goz commentedComment #19
goz commentedBefore / After screenshots by @JulienD.
Before patch, language list not ordered by translated label
After patch, language list is ordered by translated label
Comment #20
xjmThanks for the patch, test coverage, and manual testing. Seems like a helpful fix.
It's not immediately clear to me why this is included at the end of the test.
Comment #21
alexpottWhy is this change necessary? $this->t() just returns a TranslatableMarkup object so I can't see what the difference is.
Comment #22
duaelfr#20: I don't think it's needed. I removed it.
#21: you're right, I think we thought that $this->t() returned a string as D7 did but as the
TranslatableMarkupobjects have a__toString()magic method, thenatcasesort()function just works.Run testbot, run!
Comment #23
duaelfrI forgot to remove the
usestatement forStringTranslationTrait.Comment #25
goz commentedSeems good. Both tests fails or success like expected.
Tested and approved in my instance.
Thanks all
Comment #27
xjmThanks for the test-only patch to expose the failure. I only found a few minor points:
Nit: This should be a single line of 80 characters or fewer. Reference: https://www.drupal.org/node/1354#drupal
Nit: This should start with a verb. I'd suggest "Tests adding, editing, and deleting languages." (Also note the two commas.) Reference: https://drupal.org/node/1354#functions
Two things here:
Very minor nit: "French" should be capitalized.
NW for the third point in particular.
Comment #28
duaelfrAll fixed :)
Comment #29
goz commentedThanks @Duaelfr @xjm.
Patch apply for both 8.0.x and 8.1.x.
Comment #33
catchCommitted/pushed to 8.2.x and cherry-picked to 8.1.x and 8.0.x. Thanks!