multilingual functionality on simple site in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
awelch
Forum Newbie
Posts: 3
Joined: Wed Nov 18, 2009 7:55 am

multilingual functionality on simple site in php

Post 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
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: multilingual functionality on simple site in php

Post 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).
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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.
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re:

Post 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!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

Good point.
Post Reply