views:

78

answers:

2

There are many ways to design a multilingual application in PHP. Some language file based, others database based.

  • I am looking to use it for mostly small amounts of text e.g errors - at most a paragraph.

  • I guess I will need twenty or so
    languages.

Really I am looking for recommendations rather than a definitive answer. What have you used before, what is fastest, easiest to update etc.

Many thanks,

+7  A: 

The Gettext family of functions is a good starting point:

The gettext functions implement an NLS (Native Language Support) API which can be used to internationalize your PHP applications.

Zend_Translate is extremely flexible and has a thread-safe implementation of gettext. The manual states that it addresses the following problems with native internationalization implementations:

  • Inconsistent API: There is no single API for the different source formats. The usage of gettext for example is very complicated.
  • PHP supports only gettext and native array: PHP itself offers only support for array or gettext. All other source formats have to be coded manually, because there is no native support.
  • No detection of the default language:The default language of the user cannot be detected without deeper knowledge of the backgrounds for the different web browsers.
  • Gettext is not thread-safe: PHP's gettext library is not thread safe, and it should not be used in a multithreaded environment. This is due to problems with gettext itself, not PHP, but it is an existing problem.

It is worth noting that the Zend Framework is not a full-stack framework - in other words, you will not need to use the whole thing just to make use of its internationalization API.

What I really like about it is its support for multiple adapters for different data sources, which you can easily mix, match, and change only having to apply very light modifications to your application. Hope that helps.

karim79
A: 

I dealt with both solutions. (database and flat file.) But i will give you another view angle. when you design your application or software there is an another important point you should think from the beginning. You will save your language items in database and flat file. the language support of database (or table) and text file is important. If you try to keep Turkish characters in latin 1 database you will face character some problems. Turkish is an example. The database must support your language item's characters.

Erkan BALABAN