Localization via database or flat file? Localization via database or flat file? database database

Localization via database or flat file?


Loading data from a file is way faster than loading from a database. You just shave many layers of abstraction between your data and your application. If you profile your application for performance, you will see that database access is usually one of the slowest operation.

If you don't want to load all your localization string every time you display something, you always have the options to put them in differents files. For example, a "global" file for string displayed everywhere, and a localization file specific to the page/section your on.

That said, as with anything concerning performance, don't take my word for it, but mesure it yourself. Maybe in your particuliar context, with your particuliar application, a database will do just fine.


Database allows you to select only the record you're interested in...
But :

  • You need to insert /update the data to the database each time you want to change a translation -- it's harder than with a flat-file.
  • YOu'll need a lot of selects, to build a fully-translated page -- which is not quite good for performances (and means you'll have to put some caching mecanism in place)


Out of curiosity, why not take a look at something else -- something which goal is translations ?

Here, I'm thinking about Gettext, which is widely used -- and there is a Gettext extension for PHP (I should add there are other classes available -- in Zend Framework, for example).