Language label logic when installing with language, adding and editing languages is confusing

Created on 29 November 2017, about 7 years ago
Updated 16 February 2023, almost 2 years ago

Problem/Motivation

Creating languages right now is very inconsistent. I started looking into it because we have an issue in our install profile that the language was English and wouldn't update automatically when importing translations. What followed is a fun ride through language module and its history ;)

1. When installing Drupal in a specific language, the language label is created in English while everything else (as much as possible) is translated. This is related to #2031197: Language configuration entities should be created in English at all times , but that is a very old issue and we do *not* create them with langcode en anymore, the argument there is also wrong about selecting from an english list, see 2.. What we should do at that point is create the entity with the localized language label, which we do have access to.

2. When then adding a second language, the language label list is being translated to the current language, so I see e.g. "Französisch" there.

3. When then adding that language, it is again created with the english label and the config entity has the langcode of my current language (de in my case). At that point, I would expect that it is created as "Französisch" since langcode is de. It could also be in french, if the langcode would be french. Optimaly, we'd also already create a french translation after importing the french translations.

4. When I now edit that language and save it, whether or not I change the label, the langcode is changed to fr. That's because of some strange/old code in \Drupal\language\Form\LanguageFormBase that defines a hidden langcode property, which then accidently overwrites the langcode when it is actually supposed to be a hidden property for the ID. This predates the rename of the langcode property to id on the language config entity. There is also no reason to have that in the first place, this is an entity form and we have the entity object already available.

Proposed resolution

1. Create the language entity in the installer with the localized language code.
3. Create additional languages with the translated label into the correct language (==langcode property). Look into creating a translation. Maybe that could be a follow-up because it is likely more complicated.
4. Remove the langcode property for existing language entities to avoid accidently overriding that.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

10.0

Component
Language system 

Last updated about 1 hour ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Does this require a change record?

    Apologize if I missed it but has

    Create additional languages with the translated label into the correct language (==langcode property). Look into creating a translation. Maybe that could be a follow-up because it is likely more complicated.

    been addressed or a follow up made?

    Also are the steps in the IS still the best way to test this?

  • Status changed to Needs review over 1 year ago
  • 🇨🇭Switzerland berdir Switzerland

    There's no follow-up, but I'm not sure about if we even need to do that. The first part happens here, it's only that we could also create a translation already of that language, but that sounds more a feature than a bugfix to me.

    The steps should still be accurate and this still applies.

  • last update over 1 year ago
    29,877 pass
  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Fun seeing my boilerplate message from when the #needs-review-queue started

    Thanks @berdir for following up.

    Verified the tests fail without the fixes
    Applied the patch #36
    Did an install of Standard profile with a different language other then English and no issues there
    Added another language without issue.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,341 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,341 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,341 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,341 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,341 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,337 pass, 2 fail
  • 🇨🇭Switzerland berdir Switzerland

    Updated and created a merge request.

  • Status changed to Needs review 3 months ago
  • Pipeline finished with Failed
    3 months ago
    Total: 92s
    #341254
  • Pipeline finished with Success
    3 months ago
    Total: 7273s
    #341450
  • 🇺🇸United States smustgrave

    Was previous RTBC so restoring status.

  • 🇳🇿New Zealand quietone

    After reading the issue summary here and the comments I still did not understand what this is fixing. To figure that out I installed in Italian on two sites, one without the diff applied and one with the diff applied. I then saw that there is a change to the text in the in the language switcher. So, this affects what is displayed in the language switcher. What else is affected?

    Should the title then be, 'Display the translated language name when installing, adding or editing a language' ?

  • Status changed to Needs work 16 days ago
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇨🇭Switzerland berdir Switzerland

    Added phpcs exclude like the the referenced case.

  • Pipeline finished with Canceled
    16 days ago
    Total: 86s
    #400811
  • Pipeline finished with Success
    16 days ago
    Total: 467s
    #400812
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇨🇭Switzerland berdir Switzerland

    Fixed new phpcs fail.

    > Should the title then be, 'Display the translated language name when installing, adding or editing a language' ?

    That's one aspect of it, but it's more. It's also about preventing that the config entity langcode property changes. No strong feelings on the title, whatever helps to finally land this :)

  • Pipeline finished with Failed
    5 days ago
    Total: 454s
    #411620
  • 🇺🇸United States smustgrave

    Tried to take both suggestions hope it works!

    Re-ran failures and they were random, so restoring status

Production build 0.71.5 2024