Can't change the language on front page anymore

Created on 28 February 2024, 9 months ago
Updated 31 May 2024, 6 months ago

Problem/Motivation

I have a multilingual website. I want my visitors to watch the website in their previously preferred language/browser language settings. That's why I installed this module.
When I visit the homepage it gets displayed as intended. However, I can't change the language for the landing page anymore.
For instance, my browser language is German, I get always redirected to the German version no matter what language I choose. I can change the language on all other pages, but as soon as I return to the home page, I get redirected to German again.
Not sure, if that's the intention of this module or if I made some mistake I didn't realize yet. I also tested it on a fresh Drupal installation, same result.

Steps to reproduce

Installed newest version of Drupal 10.
Enabled all modules of the multilingual section.
Configured content type Basic Page to be translatable.
Added language switcher (content) block.
Edited the language detection and selection options.
Created two nodes with translations.
Uninstalled page cache module.
Installed Homepage Redirection by Language.
Enabled Browser Fallback redirection.

Proposed resolution

Use the currently selected language for the front page.

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Closed: cannot reproduce

Version

1.0

Component

Miscellaneous

Created by

🇩🇪Germany JorgeClayton

Live updates comments and jobs are added and updated live.
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.

  • 🇨🇭Switzerland wengerk Lausanne

    Do you use the standard Drupal language switcher or your own switcher ?

    If you use the standard Drupal language switcher, do you have some error in your Console ?

  • 🇩🇪Germany JorgeClayton

    Thank you for your reply!
    I'm using the standard language switcher for Drupal with no modificatons at all.
    The block's name is " Language switcher (Content)".
    Unfortunately there are no errors shown in the console, if you were referring to the one in dev tools.

  • 🇨🇭Switzerland wengerk Lausanne

    I'll take a look when used with the default language switcher.

    We use this module on 2 huge projects without any problems, but we use a custom approach as described in the README/Module description with our own JS. I think the default JS given by the module does not work anymore with the Drupal default language switcher, since Drupal changed the default language switcher when released Olivero.

    If you want to fix it quicly, I suggest you to add a custom JS that triggered when clicking on the language link

    // Prevent attempting to attach cookie if the common library is not available.
    if (typeof Drupal.homeRedirectLang == "undefined") {
      return;
    }
    
    # Change the selector here for your own class on <a> of language switcher.
    let links = document.querySelectorAll('.language-link');
    
    links.forEach(link => {
      link.addEventListener('click', function (event) {
        var hreflang = event.target.getAttribute('hreflang');
        Drupal.homeRedirectLang.setPreferredLanguage(hreflang);
      });
    });
    
  • 🇨🇭Switzerland wengerk Lausanne

    I tested following your given steps in the issue summary and on my side, everythings works as intended. When I change my lang from any page (homepage or any other) then when navigating the Homepage I'm redirected to the last language I visit the website.

    When you inspect your Cookies, you should see a Cookie nammed home_redirect_lang_preferred_langcode that should be filled with the last choosen language - does it works ?

    What are the language you enabled ? I tested with French (fr) and English (en). Maybe the module have an issue with some language, could you provide me the language you enabled on step "Enabled all modules of the multilingual section".

  • 🇨🇭Switzerland wengerk Lausanne

    I suspect that the cookie is not being set on your browser. ... And since you have activated the Fallback browser, you are constantly redirected to the language of your browser. On this production site https://shop.swisstopo.admin.ch, when you switch languages and navigate the site, then return to the homepage with https://shop.swisstopo.admin.ch, are you properly redirected to your last navigation language? If not, then it seems that your browser or an extension of it is preventing the home_redirect_lang_preferred_langcode cookie from being set.

  • Status changed to Closed: cannot reproduce 6 months ago
  • 🇨🇭Switzerland wengerk Lausanne
Production build 0.71.5 2024