On a 404 page, none of the language switcher links have the 'is-active' class

Created on 19 September 2016, about 8 years ago
Updated 5 April 2023, over 1 year ago

Problem/Motivation

On a default installation configured with at least 2 languages, if you go to a non-existing URL, such as http://site.com/nosuchpage, the language switcher has no 'is-active' class on the current language.

The error message is displayed in the correct language, but the language switcher links do not reflect the current language.

Expected behaviour:
The language switcher link for the current language should have the 'is-active' class, in the same way as it does for existing URLs.

Steps to reproduce

Proposed resolution

TBA

Remaining tasks

Patch
Add tests
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

10.1

Component
Language system 

Last updated about 15 hours ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇬🇧United Kingdom nicrodgers Monmouthshire, UK

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • 🇳🇿New Zealand quietone

    I tested this on Drupal 10.1.x, standard install, with English, Italian and German. I was able to reproduce the problem.

    I applied the latest patch at #2775651-41: No active language in language switcher for URL with query string and that does work. I do not know if it is the correct fix.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @quietone, for that reason I reopened the issue you linked, as it doesn't seem to have been a duplicate then. We should check both issues for a solution and if it is or should be combined fix or not.

  • I have a multilingual site, but my background admin page uses only one language, using '$current_language_code = $this->languageManager->getCurrentLanguage()->getId(); 'will not get the exact language, So I'll change it to '$current_language_code = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId();' , using the url to determine the language.

  • 🇮🇳India manish.upadhyay

    Hi Everyone,

    Here is the updated patch for 9.5.x.

    Thanks,

  • 🇦🇹Austria enorm

    Hello and thank you for your work!

    One issue for drupal 9.5 and the language switcher when 403 or 404 pages:

    Result of the patch #32: Only the <a gets the is-active class BUT for a working lang-switcher you also need the parent <li as active!

  • the html should look like this:

    <ul class="links list-unstyled mb-0">
    <li hreflang="de" data-drupal-link-system-path="node/956" class="is-active">
    <a href="/de/start" class="language-link is-active" hreflang="de" data-drupal-link-system-path="node/956">Deutsch</a>
    </li><li hreflang="en" data-drupal-link-system-path="node/956">
    <a href="/en/node/956" class="language-link" hreflang="en" data-drupal-link-system-path="node/956">English</a>
    </li></ul>

    please can you have a look again at this problem for a new patch, thanks, Erich!

Production build 0.71.5 2024