[D 10.1.4] Error when trying to translate banner

Created on 5 February 2024, 11 months ago

Problem/Motivation

When I go to "/admin/config/system/eu-cookie-compliance/settings/translate/xx/add", an error is thrown. I can't translate the banner because of it. I tried to translate it to different languages present on my website but it's still not working.

Steps to reproduce

I just freshly installed the module on a website, configured it and now, I'm just trying to translate the entity normally.

🐛 Bug report
Status

Active

Version

1.24

Component

Code

Created by

🇨🇭Switzerland zilloww

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @zilloww
  • 🇨🇭Switzerland zilloww

    I fixed this issue by noticing that in the config/install folder of the module, there is a eu_cookie_compliance.settings.yml file that contains the key 'langcode' defaulted to 'en'. Since I don't have English language on my website, Drupal doesn't recognize the langcode 'en'. That's the source of the error.

    To fix this:

    1. Go to your drupal/config/sync
    2. Open the file "eu_cookie_compliance.settings.yml"
    3. Add the "langcode: xx" (replace 'xx' by whatever is your default website language for example "langcode: fr"
    4. drush cim
    5. Clear cache
    6. The issue should be fixed
  • Status changed to Needs review 11 months ago
  • Status changed to Active 24 days ago
  • 🇳🇴Norway svenryen

    Hi!

    Thanks for the report, I was able to reproduce.

    For the record, here are the exact steps:

    • I installed Drupal 10.1.4 (most likely the specific version isn't needed in order to reproduce the bug) using "drush site:install"
    • I installed EU Cookie Compliance, causing the module to have English settings.
    • Then I installed Configuration Translation, Content Translation, Interface Translation and Language (note that we might not need all of them)
    • I added French and Norwegian languages, setting French as default
    • I removed the English language (this is what causes the bug to appear)
    • Then I configured the site to have Norwegian as the main language, French as available for translation
    • I navigated to nb/admin/config/system/eu-cookie-compliance/settings/translate

    Result:

     TypeError: Drupal\config_translation\FormElement\ListElement::getTranslationBuild(): Argument #1 ($source_language) must be of type Drupal\Core\Language\LanguageInterface, null given, called in /var/www/html/web/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php on line 178 in Drupal\config_translation\FormElement\ListElement->getTranslationBuild() (line 48 of core/modules/config_translation/src/FormElement/ListElement.php).
    Drupal\config_translation\Form\ConfigTranslationFormBase->buildForm(Array, Object, Object, 'eu_cookie_compliance.settings', 'en') (Line: 26)
    Drupal\config_translation\Form\ConfigTranslationAddForm->buildForm(Array, Object, Object, 'eu_cookie_compliance.settings', 'fr')
     

    Note: Please leave the Issue Status as "Active" unless there's code to review in the issue as a gitlab branch or a patch file.

  • 🇳🇴Norway svenryen

    I checked, and I can reproduce in Drupal 11.0.9/PHP 8.3.12.

    I'm not sure what we can do in the module, as we're not in control of the translation system.I'll see if there's a core issue for this bug, otherwise I'll create an issue in the Drupal core project.

  • 🇳🇴Norway svenryen

    I found this issue in the core issue queue, which seems related.

    https://www.drupal.org/project/drupal/issues/3184569 🐛 Can't translate config when source language does not exists Needs work

    Please post any follow-up discussion there. There's nothing we can do in this module.

  • 🇳🇴Norway svenryen

    The patch in the Drupal core issue ( https://www.drupal.org/files/issues/2023-02-06/3184569_14.patch ) solves the bug.

    If anybody wants to write a test for the core fix, it could perhaps be committed.

Production build 0.71.5 2024