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 :

  1. Enable and select french language
  2. Go to admin/config/regional/language/add or fr/admin/config/regional/language/add if french is not default
  3. 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

GoZ created an issue. See original summary.

duaelfr’s picture

Bugs always need tests ;)

goz’s picture

Issue summary: View changes
goz’s picture

Status: Active » Needs review
StatusFileSize
new3.89 KB

Actually, languages are translated during render, so the sort is made on english values.
I based translation on CountryManager->getStandardList() way, so replace New TranslationMarkup() by t() to have translation instead of empty translate markup.

Tests has been created to check order is correct.

JulienD’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new56.05 KB
new52.47 KB

Works fine for me, the patch fix the issue, allowing the language list to be correctly ordered (See attached screenshots)

duaelfr’s picture

Status: Reviewed & tested by the community » Needs work

Nop sorry.
I have some changes to suggest/post but I'm on my phone right now.
I'll post that tomorrow.

goz’s picture

Here is a patch with tests only. This test should fail.

goz’s picture

Status: Needs work » Needs review
goz’s picture

Status: Needs review » Needs work

Waiting for DuaelFr suggestions

The last submitted patch, 7: core-language-locale-list-order-2580177-6-tests-only.patch, failed testing.

The last submitted patch, 7: core-language-locale-list-order-2580177-6-tests-only.patch, failed testing.

duaelfr’s picture

Let'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 StringTranslationTrait in a class to have access to $this->t() instead of calling the t() function directly.
You can have a look at \Drupal\taxonomy\TaxonomyPermissions to have a short example.

See the related change record: https://www.drupal.org/node/2079611

goz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.5 KB
new1.17 KB

I can't use what is defined in change record : https://www.drupal.org/node/2079611

So i use the same implementation as \Drupal\taxonomy\TaxonomyPermissions

duaelfr’s picture

Status: Needs review » Reviewed & tested by the community

Excellent, that was exactly what I meant.
Thank you, you made a good job :)

duaelfr’s picture

Issue tags: +Needs screenshots, +Novice

By 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

goz’s picture

Issue tags: -Needs screenshots, -Novice

@DuaelFr, you needs a coffee, @JulienD already make screenshots #5 ;)

duaelfr’s picture

True ;)
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

goz’s picture

Issue summary: View changes
goz’s picture

Issue summary: View changes

Before / After screenshots by @JulienD.

  1. Before patch, language list not ordered by translated label

  2. After patch, language list is ordered by translated label

xjm’s picture

Thanks for the patch, test coverage, and manual testing. Seems like a helpful fix.

+++ b/core/modules/language/src/Tests/LanguageLocaleListTest.php
@@ -0,0 +1,83 @@
+    // Delete French.
+    $this->drupalPostForm('admin/config/regional/language/delete/fr', array(), t('Delete'));

It's not immediately clear to me why this is included at the end of the test.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/language/src/ConfigurableLanguageManager.php
@@ -13,7 +13,7 @@
-use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\Core\StringTranslation\StringTranslationTrait;

@@ -24,6 +24,8 @@
+  use StringTranslationTrait;

@@ -470,9 +472,9 @@ public function getStandardLanguageListWithoutConfigured() {
-      $predefined[$key] = new TranslatableMarkup($value[0]);
+      $predefined[$key] = $this->t($value[0]);

Why is this change necessary? $this->t() just returns a TranslatableMarkup object so I can't see what the difference is.

duaelfr’s picture

#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 TranslatableMarkup objects have a __toString() magic method, the natcasesort() function just works.

Run testbot, run!

duaelfr’s picture

I forgot to remove the use statement for StringTranslationTrait.

The last submitted patch, 22: core-language-locale-list-order-2580177-22-tests-only.patch, failed testing.

goz’s picture

Status: Needs review » Reviewed & tested by the community

Seems good. Both tests fails or success like expected.

Tested and approved in my instance.

Thanks all

The last submitted patch, 22: core-language-locale-list-order-2580177-22-tests-only.patch, failed testing.

xjm’s picture

Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs work

Thanks for the test-only patch to expose the failure. I only found a few minor points:

  1. +++ b/core/modules/language/src/Tests/LanguageLocaleListTest.php
    @@ -0,0 +1,80 @@
    + * Adds a new language with translations and tests language list is correctly
    + * ordered.
    

    Nit: This should be a single line of 80 characters or fewer. Reference: https://www.drupal.org/node/1354#drupal

  2. +++ b/core/modules/language/src/Tests/LanguageLocaleListTest.php
    @@ -0,0 +1,80 @@
    +   * Functional tests for adding, editing and deleting languages.
    

    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

  3. +++ b/core/modules/language/src/Tests/LanguageLocaleListTest.php
    @@ -0,0 +1,80 @@
    +    $this->assertText('French', 'Language added successfully.');
    

    Two things here:

    1. The assertion message parameter is not necessary and actually obscures details of the assertion.
    2. The assertion seems too broad; generically matching the word "French" could result in false positives.
  4. +++ b/core/modules/language/src/Tests/LanguageLocaleListTest.php
    @@ -0,0 +1,80 @@
    +    // Translate Spanish language to french (Espagnol).
    

    Very minor nit: "French" should be capitalized.

NW for the third point in particular.

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new1.49 KB
new3.13 KB

All fixed :)

goz’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @Duaelfr @xjm.
Patch apply for both 8.0.x and 8.1.x.

  • catch committed 64415a6 on 8.2.x
    Issue #2580177 by DuaelFr, GoZ: Language list is not correctly ordered...

  • catch committed 6bcfe04 on 8.1.x
    Issue #2580177 by DuaelFr, GoZ: Language list is not correctly ordered...

  • catch committed 3c02d42 on 8.0.x
    Issue #2580177 by DuaelFr, GoZ: Language list is not correctly ordered...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.2.x and cherry-picked to 8.1.x and 8.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.