Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at docs.zendframework.com
Zend_Translate is Zend Framework's solution for multilingual
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_Translate does not have the above problems. This is why we
Zend_Translate instead of PHP's native functions.
The benefits of
Supports multiple source formats:
Zend_Translate supports several source formats, including
those supported by PHP, and other formats including TMX
and CSV files.
The gettext reader of
Zend_Translate is thread-safe.
There are no problems using it in multi-threaded environments.
Easy and generic API:
The API of
Zend_Translate is very simple and requires only a
handful of functions.
So it's easy to learn and easy to maintain.
All source formats are handled the same way, so if the format
of your source files change from Gettext to TMX,
you only need to change one line of code to specify the
Detection of the user's standard language:
The preferred language of the user accessing the site can be
detected and used by
Automatic source detection:
Zend_Translate is capable of detecting and integrating multiple source files
and additionally detect the locale to be used depending on directory or filenames.
So let's get started with multi-lingual business. What we want to do is translate our string output so the view produces the translated output. Otherwise we would have to write one view for each language, and no one would like to do this. Generally, multi-lingual sites are very simple in their design. There are only four steps you would have to do:
Decide which adapter you want to use;
Create your view and integrate
Zend_Translate in your code;
Create the source file from your code;
Translate your source file to the desired language.
The following sections guide you through all four steps. Read through the next few pages to create your own multi-lingual web application.
Table of Contents