Translations not displayed when accessing /admin/config/regional/babel without specifying the language

Created on 8 August 2025, 25 days ago

Problem/Motivation

When accessing the Babel configuration page without specifying a language in the URL, existing translations are not displayed.

If the URL includes the language (e.g., /it), translations are shown correctly.

This happens because the code uses:

$language ??= $this->languageManager->getCurrentLanguage();

which sets the language to the site's default language instead of 'it', the only option available in the select list.

Steps to reproduce

  1. Navigate to https://babel.ddev.site/admin/config/regional/babel/it.
    Translations are displayed as expected.
  2. Navigate to https://babel.ddev.site/admin/config/regional/babel.
    No translations are displayed.

Proposed resolution

If no language is provided in the URL, automatically use the language available in the select list (in this case 'it') instead of defaulting to the site's default language.

Suggested code adjustment:

Instead of:

$language ??= $this->languageManager->getCurrentLanguage();

Consider checking the available languages from the select list and defaulting to the first one if none is provided:

if (!$language) {
  $available_languages = array_keys($this->languageManager->getLanguages());
  $language = reset($available_languages) ?: $this->languageManager->getCurrentLanguage();
}

Where $this->languageManager->getLanguages() returns the languages displayed in the dropdown.

Remaining tasks

  • Update the logic that sets $language to use the first available language from the select list when none is provided in the URL.
  • Ensure $this->languageManager->getLanguages() retrieves the same set used to populate the dropdown.
  • Test to ensure translations are displayed correctly when the language is omitted from the URL.

User interface changes

  • None expected, but the default selection in the language dropdown will match the loaded translations.

API changes

  • None.

Data model changes

  • None.
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇵🇹Portugal saidatom Lisbon

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

Comments & Activities

Production build 0.71.5 2024