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

Localisation: auto select language based on browser setting #364

Closed tilfischer closed 4 months ago

tilfischer commented 4 months ago

Dear all,

The N4C KB currently seems to always present the English language edition by default. The KB should detect the language based on the browser setting of the users and should display the German language version, if the language set for the browser is German and should show the English language version for any other language the browser is set to.

Best, Tillmann

BTW: https://www.nfdi4chem.de/repos/ got updated. For the repos where we got a subpage in the KB, this is linked. However, we cannot have other links in the German language edition than in the English language edition, hence, links on https://www.nfdi4chem.de/de/chemie-repositorien/ also link to the English language edition of the KB. Detection of language in the N4C KB would most probably also solve this issue.

jliermann commented 4 months ago

Docusaurus does not offer locale detection according to the documentation and suggests to do this through server redirection rules. I will look into that.

jliermann commented 4 months ago

Apache is now configured to redirect according to a user's HTTP:Accepted-Language request header - if it begins with de (i. e. German as prefered language, the request is redirected to /knowledge_base/de/. If the request header does NOT begin with de, the request is redirected to /knowledge_base/. By this, links become completely agnostic of the user's browser settings.

If anybody is interested in the technical detail, these Rewrite rules are now in place:

RewriteEngine On

RewriteRule ^/$ /knowledge_base [R=301,L]

RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteCond %{REQUEST_URI} !^/knowledge_base/de/
RewriteRule ^/knowledge_base/(.*)$ /knowledge_base/de/$1 [R=301,L]

RewriteCond %{HTTP:Accept-Language} !^de [NC]
RewriteCond %{REQUEST_URI} ^/knowledge_base/de/
RewriteRule ^/knowledge_base/de/(.*)$ /knowledge_base/$1 [R=301,L]