NFDI4Chem / knowledge_base

A place for all knowledge regarding Research Data Management (RDM) in Chemistry
https://knowledgebase.nfdi4chem.de/
11 stars 27 forks source link

Change language #365

Closed tilfischer closed 3 months ago

tilfischer commented 3 months ago

Dear all,

Changing the language does not work anymore, possibly due to the Rewrite rule. Connected to #364 .

Best, Tillmann

jliermann commented 3 months ago

Using the locale queryString option, I was able to partially fix that (rewrite will not happen when this query string is present). However, the setting is lost once a new page is accessed. I’m continuing to investigate solutions.

jliermann commented 3 months ago

The locale queryString is now saved to a session cookie, therefore the language choice by the user overrides the automatic locale detection.

Rules:

RewriteCond %{QUERY_STRING} userLocale=true [NC]
RewriteRule ^.*$ - [CO=userLocale:true:%{HTTP_HOST}]

RewriteCond %{HTTP:Accept-Language} ^de [NC]        # Redirect if Accept-Language is de
RewriteCond %{QUERY_STRING} !userLocale=true [NC]   # Don't redirect if userLocale query string is present
RewriteCond %{HTTP_COOKIE} !userLocale=true [NC]    # Don't redirect if userLocale cookie is already set
RewriteCond %{REQUEST_URI} !^/knowledge_base/de/ [NC]
RewriteRule ^/knowledge_base/(.*)$ /knowledge_base/de/$1 [R=301,END] 

RewriteCond %{HTTP:Accept-Language} !^de [NC]       # Redirect if Accept-Language is not de
RewriteCond %{QUERY_STRING} !userLocale=true [NC]   # Don't redirect if userLocale query string is present
RewriteCond %{HTTP_COOKIE} !userLocale=true [NC]    # Don't redirect if userLocale cookie is already set
RewriteCond %{REQUEST_URI} ^/knowledge_base/de/ [NC]    
RewriteRule ^/knowledge_base/de/(.*)$ /knowledge_base/$1 [R=301,END]