Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Mulilingual application design

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,

like image 562
Mark Avatar asked Nov 16 '09 16:11

Mark


1 Answers

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.

like image 86
karim79 Avatar answered Oct 30 '22 18:10

karim79