I have a site with many people from around the world. The entire thing is UTF-8 so people are free to submit content and speak in any language they wish - from Greek to English.
Now the only thing that the user can't control is the built in site language used for things like navigation and instructions for registering. These strings are in a language file however and can easily be translated.
So now I need to know how I can build a system that will attempt to auto-detect the users preferred language while still allowing that to be changed.
The easiest way to do this is to check the Accept-Language
header the users browser sends. Most browsers will be installed in the language that the user wants - and even then they can change the language in the settings.
The problem is that Internet cafe users might want to change these settings but won't be able to or users may not be competent enough with the web to even know about them. Picture a dumb American tourist on some computer in another country. (I can laugh at them because I am one).
So these people need a better way change the language encase they can't override the browser. To answer that I was thinking that I could implement a URL based system like site.com/en_us/...
or site.com/fr_ca/...
.
Ok, so here is how I would imagine it working.
- New UserA comes to sight.
- My site finds no locale cookie set
- looks at and parses accept-language header
- checks for existing lang dir (to make sure I support fr_ca!)
- sets cookie with language as fr_ca
redirects user to
site.com/fr_ca
UserA now loads
site.com/fr_ca
- My site finds locale cookie
- Locale cookie matches URL locale
- User must want this locale
continue loading page
UserB gets link from UserA pointing to
site.com/fr_ca
- UserB loads page and my site finds no locale cookie
Here is where I'm kind of lost as what to do next
- My site finds UserB browser says en_us so it redirects them or
- My site creates a locale cookie with fr_ca and the user will have to visit en_US to change that.
Does this seem like a pretty solid way to handle language detection so I know whether to say register or registre?