PHP Localization Question
I'm building a Open Sour开发者_如何学Cce product and I thinking about Localization, I've read about gettext but there seems to be a lot of problem to get it to work in different systems (servers,os etc).
How would you handle this? Is there a secure way to help gettext work on several systems? Perhaps it already is?
Regards from Sweden / Tobias
I recommend you take a look at Zend_translate, Zend_locale and Zend_Date. I'm only starting to dabble with them myself, but to me, they already look like a really good, clean and modern solution to internationalization, in contrast to the chaos that is gettext.
The introduction to Zend_translate lists a number of strong arguments why to choose it (or something similar) over gettext.
In multilingual applications, the content must be translated into several languages and display content depending on the user's language. PHP offers already several ways to handle such problems, however the PHP solution has some problems:
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.
Zend Framework's Zend_Translate is most flexible what I've seen. It doesn't necessarily need gettext support module in PHP's side as it reads the .mo-binary format itself.
The language blocks should be kept external to the program. They may be in a database or in XML files. This will enable further languages to be added at a later point in time.
Then all your application needs to do is identify the localisation by the user and serve up the appropriate text for each situation.
精彩评论