16
I’m developing a website that needs to be available in 3 languages (only static content, to be served by Apache). I would like to make use of the language detection features so that the user already falls into a version compatible with the language preferences of your browser, but I also want him to be able to choose a different language through special links. It is possible to do this by Apache without using any language server-side?
I started reading the documentation on negotiation content and on the mod_negotiation
, but I am quite lost because the examples given do not seem clear to me. What I understood so far (please correct me if I’m wrong) was the following:
- I should create my pages according to a specific convention, ex.:
index.html.pt
,index.html.en
,index.html.ja
; I must configure the
Directory
to enable content trading:<Directory /var/www/vhosts/example.com/httpdocs> Options Indexes FollowSymLinks MultiViews DirectoryIndex index.html AllowOverride None Order allow,deny allow from all LanguagePriority en pt ja ForceLanguagePriority Prefer Fallback </Directory>
Each page should link to the base name, without specifying the language, e.g..:
href="index.html"
.
With this, from what I understand the server will be able to choose a version based on header Accept-Language
that the browser sends. If this is correct, the first part is ok.
However, I have no idea how a link could change the current language of the page - and do so so so that it remains the current language even after the user clicks on other links. The documentation mentions "advanced techniques (such as cookies or special URL-paths)", but I couldn’t understand what it was about, and the linked documentation didn’t help much. Is there a simple way to do this? Give preference, without needing Javascript (but if there is no other way, fine).
To do directly in apache do not know, but it is also not necessary to javascript, can set cookies as soon as the page is sent in server-side language, depends on what you prefer, ie for example: meusite.com/pt (default if there are no cookies) has a link to meusite.com/en, there is soon part of the script (server side) that implements a cookie/session so that next times it is loaded meusite.com/en instead of meusite.com/en
– Miguel
I was noticing how the google algorithm works when it redirects from google.com to google.com or any other think it uses as criteria the ip and the accept-Language of the header of the requisicao think this would be the best way and put a language by default until there is a google application that automatically converts the language of the site without having to make changes on the pages so do not remember the name
– user45474
Let’s wait for someone to clear up this doubt of yours now. :)
– gato
@drmcarvalho Thanks! This is no longer mere curiosity, I really need this for a job I’m doing. In the next few days, if I don’t have an answer I’ll search and try some options myself, and if I discover something useful I share here with the rest of the community.
– mgibsonbr