View Full Version : Multi-Language Support

01-19-2008, 01:53 AM

I have a website, written in PHP/MySQL, that I need to add support for multiple languages to. There isn't a lot of text on it, mostly a bunch of short sentences and phrases, so I don't want to make a copy of all of the files, I'd just like to have a setting, probably a session variable, that stores the current display language, and based on the value of that variable output the page in the correct language.

What are everyone's opinions on the best way to do this, (at least everyone who cares to contribute)?

Should I dump all of my text into an include file and assign it to variables or constants - then just include the file for the correct language? (This is how oscommerce does it).

Should I store all the text in a DB table "LANGUAGE" or something and only retrieve the stuff I need for a particular page? (this gives me easier storage for some info, and I don't have to worry about manually escaping stuff the same way, but it makes it harder to edit the text).

Are there other options? I want to create a system that is scalable so that languages can be added or removed easily.

Thanks in advance for the input!


01-19-2008, 07:16 AM
You have the right idea mate.
Only done one before, I used a prefetched DB design. Not sure if anything I can compare it to, but all I do is determine from a script level which "groups" of languages are required, this was necessary for the staggering amount of text involved, and it would have been far too much overhead to query the entire database for all languages for all text phrases.
Then I just shoved those into variables (more specifically, a language object variable so I could access via a language object), and replaced those into my templates.

However, my templates are also stored in the database, so storing the text also seemed like a logical route to follow. If you are currently on a filesytem based templates, I'd recommend sticking with it and simply storing your phrases in a files instead (one per line kind of idea).

If this is your first time doing this, I'd say your already well on your way, most of what you where talking about is exactly what I did with mine (balancing the overhead with the required values)

Good luck on the project mate!

01-19-2008, 08:35 AM
That's encouraging!

I'm thinking about going the DB route because then the site won't have to load all of the text all of the time, and because there are a couple of longer items that need to be stored, (terms of use, privacy policy, that stuff), that would require an alternate system if I was storing stuff in files.

I'm already using the DB pretty heavily - just not for text, ironically, so a lot of the code is already in place.

01-19-2008, 11:15 PM
Good idea, you won't have any problem putting one together.
Best of luck to you!