0

Language switching fails after enabling browser on Detection and selection

/admin/config/regional/language/detection

Exisiting :

On switching language from the browser the url changes but the content remains the same

E.g, Default language browser is Germen.

mywebsite.com mywebsite.com/about etc shows German content.

While swiched to English url changes to mywebsite.com/en mywebsite.com/en/about etc

It shows Germen content instead of English.

Expected

On browser configured with Germen as default language, the site url should be mywebsite.com/de.

When I swich to the English website, it should show English content

Please find the configuration.

enter image description here

3
  • 1
    Post a screenshot of your negotiation settings. Browser negotiation must be after URL detection. And you should have a prefix for all languages. Basically the first option there that returns something wins. And you should combine with the redirect.module, which will then redirect example.com to example.com/en if it detects english or /de.
    – Berdir
    Sep 11, 2017 at 16:48
  • Sorry for thge delay in reply. I have implemented it with .htaccess.Could you please explain how to combine it with redirect module.
    – developer
    Sep 14, 2017 at 4:09
  • Just enable the module and make sure that the Enforce clean and canonical URLs option is enabled
    – Berdir
    Sep 14, 2017 at 7:53

2 Answers 2

0

It is very obvious why this is happening. Language selection process the language detection systems from top to bottom. (Top has highest priority.) Your configuration means that the browser will always be selected first and that url and user settings are ignored.

If you move browser below user (drag with the arrows icon), the processing order will be:

  • url
  • user (if url resolved no language)
  • browser (if user had no language configured)
1
  • Modified configuration in the given order.But issues still exists.
    – developer
    Sep 18, 2017 at 6:37
-1

I have fixed the issue with htaccess.Please refer this code,it may be helpful for similar issues.

  ## On frontpage redirect to /de if the browser language start with de
  RewriteCond %{HTTP:Accept-Language} ^de.*$ [NC]
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} !(^q\=) [NC]
  RewriteRule ^(.*)$ /de [L,R=302]

  ## On frontpage redirect to /en if the browser language start with en
  RewriteCond %{HTTP:Accept-Language} ^en [NC]
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} !(^q\=) [NC]
  RewriteRule ^(.*)$ /en [L,R=302]

  ## To make all other requests (that is, URLs not starting with /en/ or /de/) redirect to a default language (say en)
  RewriteCond %{HTTP:Accept-Language} () [NC]
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} !(^q\=) [NC]
  RewriteRule ^(.*)$ /en [L,R=302]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.