Page 1 of 1
multilingual functionality on simple site in php
Posted: Fri Nov 20, 2009 1:41 am
by awelch
hi I have a simple static website and I want to have a flag to change language. I've done this before but it was very crude and it meant having two copies of the website - not ideal- but I guess ok for a small website.
I want to know if there i a standard way of doing this?
Thanks
Andy
Re: multilingual functionality on simple site in php
Posted: Fri Nov 20, 2009 3:04 am
by Apollo
awelch wrote:it meant having two copies of the website
Wow hehe
Well obviously the idea is to only have the textual content twice (one in each language), but the layout, logic, etc. (all non-language dependent stuff) only once.
Put your texts in a database, store the language in a cookie or session, and when outputting a page, pick the required text for the current language from your DB.
If you're using a CMS, better pick one that already has multi-language support (there are plenty).
Posted: Fri Nov 20, 2009 10:02 am
by Jonah Bron
Another option is to automatically detect the user's preferable language with $_SERVER['HTTP_ACCEPT_LANGUAGE']
Then you can skip the cookies.
Re:
Posted: Fri Nov 20, 2009 10:31 am
by iankent
Jonah Bron wrote:Then you can skip the cookies.
good point, but preferably still give the users a choice - even if their header tells you they're using French or German, doesn't mean they won't want it in English instead!
Posted: Fri Nov 20, 2009 3:59 pm
by Jonah Bron
Good point.