Chapter 4. Zend_Translate

Table of Contents

4.1. Introduction
4.1.1. Starting multilingual
4.2. Adapters for Zend_Translate
4.2.1. How to decide which translation adapter to use
4.3. Using translation Adapters
4.3.1. Translation Source structures
4.3.2. Creating array source files
4.3.3. Creating gettext source files
4.3.4. Creating tmx source files
4.3.5. Creating csv source files
4.4. Introduction

4.1. Introduction

Zend_Translate is the answer of the Zend Framework to the problem of multilingual sites.

Multilingual sites are having the problem that the content has to be translated into several languages and depending on the users language the proper content has to be displayed. PHP itself offers already several ways to handle such problems.

Actual problems of PHP are:

  • No API

    There is no API for the different source formats. The useage of gettext for example is for a beginner very complicated.

  • Only gettext and array native supported

    PHP itself offers only support for array or gettext. All other source formats have to be coded per hand, as there is no native support.

  • No detection of the default language

    The default language of the user can not be detected without deeper knowledge of the beackgrounds for the different web browsers.

  • Gettext is not thread save

    PHP's gettext library is not tread save. So PHP's gettext library 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 itself does not have these problems. This is why we announce anyone to use Zend_Translate instead of PHP's native functions. The benefits are:

  • Multiple source formats supported

    Multiple different source formats are supported within Zend_Translate. So when the format of the source files change from Gettext to Tmx the only thing to do is just change one line.

  • Threadsave gettext

    The gettext reader of Zend_Translate is threadsave. There will be no problems by using it in multithreaded environments.

  • Easy and generic API

    The API of Zend_Translate is very simple and supports only a hand full of functions. So it's easy to learn and easy to maintain. All source formats are handled the same way.

  • Detection of the users standard language

    The preferred language of the user accessing the site can be detected and used by Zend_Translate.

4.1.1. Starting multilingual

So let's get started with Multilingual business. What we want to do is translating our string output so the view produces the translated output. Otherwise we would have to write one view per every language, and no one would like to do this. Principially multilingual sites are very simple in their design. There are only 4 steps you would have to do...

  • Decide which adaptor 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 wished language

We will guide you through all 4 steps so just read through the next few pages to create your own multilingual site.