Multilingual site

Posted on 2012-04-06
Last Modified: 2012-05-18
I want to build a php multilingual site. Let's say I want 3 languages for the beggining and then a smart way to add new languages when it needed.

Database VS Language files.

As I know there is two options.

1) I can use database tables with languages, translations, etc and every time based on user preferred language to retrieve data from the db which means lots of database requests.

2) I can use extrernal language php files with define (like some e-commerce frameworks who has different languages files into a language folder such us fr.php eng.php etc)

I want opinions about what is better using the following arguments.

1) Best performance
2) More flexible
3) More efficient
4) Intelligent way

Thanks in advance
Question by:alex_code

Expert Comment

Comment Utility
In my opinion, considering all of the options that you have mentioned, adding Google Translate to you pages seems to be the best option.

You can add the translate option to you page using the guidelines show on

Make sure that all your labels are text based and are not images so that the translation engine can easily take care of that.

Good Luck!

Assisted Solution

ee_reach earned 150 total points
Comment Utility
I've tried it both ways now.  Here's what I've discovered.

If the structure of each page per language is exacty the same, and if there isn't a lot of text on each page, then I would use a database.

If the structure of each page may vary depending on the language and/or if there is a ton of text on each page, then I would use files.

Why, you ask, does it matter how much text there is?
Because each language is structurally different.  Some langs are subject->object->verb, others some other order (e.g. verb subject object,  or ver object subject.) Or perhaps the language is right-to-left instead of left to right, etc.  This means that you have to have a bunch of short phrases stored in your database, with three different versions, one for each language.

So if you are storing all these little strings in your database, you have all these little pieces of text that you have to put into different fields in your database and then you must piece them together in the right order at run time, depending on the language.  

This works fine if it is mostly navigational text, titles, photo labels, or the like.  But if it is long pages of instructions (such as a manual), writing the whole page in whatever language and then formatting it nicely in a single file saves a lot of work and will probably yield a more satisfactory result for the user.

For the same reason, it matters if each page is structurally the same for each language.  This is for a similar reason.  If you are getting the content from a database, you need to know in advance exactly where the content of each field goes for each language.  If the structure of the page varies depending on the language (e.g, in certain languages, you decide to put the navigation panel on the left but in another language it's on the right), or if the content of the page will vary depending  on the language (e.g, maybe certain content isn't supposed to be displayed in some languages), then you will be doing a bunch of tests at run time to see whether each field is needed in each spot for each language.  This is not only db intensive, but it is also error prone from a coding perspective.  In which case, you are better off with separate files.

Of course, if you have a ton of text, like manual pages, you could still store the translation of entire text of each page in a separate entry in the database.  That is somewhat of a hybrid approach.  Which isn't really what you were looking for, but it is to say that just because you have a ton of text that doesn't mean you can't use a database.  The key here is that the entire body of a single page is stored together.  At that point, whether that is a file or a database is really irrelevant, except that if you are doing the same thing for everything on the page, that will make your life much better.

In my experience, these very practical matters about language structure can eventually make you very happy or very unhappy about your choice of db or files.  But this is very site specific, so if I weren't sure, I would try creating a prototype using the approach I think would work.  (Be sure to think about different types of pages you would have - e.g., some may have a bunch of photos as icons with labels on them, but when you click on them, they may be all text at that point.)  Then I would go through the translation process with the translators (or at least someone else who knows the other languages very well) and see how that goes.  

It will help a lot if you know all three languages pretty well.  But if you don't, you will be dependent on your translators to tell you how the words in each sentence in each language are pieced together.  So it is worth going through the translation process of the prototype so you can get a good feel for what will work best with each option.

Hope this helps

LVL 108

Accepted Solution

Ray Paseur earned 350 total points
Comment Utility

Author Comment

Comment Utility
Thank you all for your responses. Give me some days in order to check them and I'll come back with a feedback.
Please have in mind that it's a critical decision for me so I have to examine every case therefore I'll leave the Q for a few days open.

Author Comment

Comment Utility
Thank you all for your posts again. For some personal reasons I coulnd't even test any of your proposals and I'll close this Q by splitting points to  Ray_Paseur for his awesome article and ee_reach for her effort to explain some things on her side.

PS : @wasiftoor Thank you for your post but your solution it's too far from what I want :-)

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now