[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Multilingual site

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
2 Solutions
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 http://translate.google.com/translate_tools

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!
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

Ray PaseurCommented:
AlexSoftware EngineerAuthor Commented:
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.
AlexSoftware EngineerAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now