Wprowadzenie do Zend Framework

     Nauka Zend Framework

    appendix

     Przewodnik po Zend Framework


  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Translation 21.3% Update 2011-11-16 - Revision 24356 - Version ZF 1.11.x

    Rozdział 71. Zend_Translate

    Spis treści

    71.1. Introduction
    71.1.1. Starting multi-lingual
    71.2. Adapters for Zend_Translate
    71.2.1. How to decide which translation adapter to use
    71.2.1.1. Zend_Translate_Adapter_Array
    71.2.1.2. Zend_Translate_Adapter_Csv
    71.2.1.3. Zend_Translate_Adapter_Gettext
    71.2.1.4. Zend_Translate_Adapter_Ini
    71.2.1.5. Zend_Translate_Adapter_Tbx
    71.2.1.6. Zend_Translate_Adapter_Tmx
    71.2.1.7. Zend_Translate_Adapter_Qt
    71.2.1.8. Zend_Translate_Adapter_Xliff
    71.2.1.9. Zend_Translate_Adapter_XmlTm
    71.2.2. Integrate self written Adapters
    71.2.3. Speedup all Adapters
    71.3. Using Translation Adapters
    71.3.1. Translation Source Structures
    71.4. Creating source files
    71.4.1. Creating Array source files
    71.4.2. Creating Gettext source files
    71.4.3. Creating TMX source files
    71.4.4. Creating CSV source files
    71.4.5. Creating INI source files
    71.5. Additional features for translation
    71.5.1. Options for adapters
    71.5.2. Handling languages
    71.5.2.1. Automatical handling of languages
    71.5.2.2. Using a country as language
    71.5.3. Automatic source detection
    71.5.3.1. Language through naming directories
    71.5.3.2. Language through filenames
    71.5.3.2.1. Complete filename
    71.5.3.2.2. Extension of the file
    71.5.3.2.3. Filename tokens
    71.5.3.3. Ignoring special files and directories
    71.5.3.3.1. Ignore a special directory or file
    71.5.3.3.2. Ignore several directories or files
    71.5.3.3.3. Ignore specific names
    71.5.4. Routing for translations
    71.5.5. Combining multiple translation sources
    71.5.6. Checking for translations
    71.5.7. How to log not found translations
    71.5.8. Accessing source data
    71.6. Plural notations for Translation
    71.6.1. Traditional plural translations
    71.6.2. Modern plural translations
    71.6.3. Plural source files
    71.6.3.1. Array source with plural definitions
    71.6.3.2. Csv source with plural definitions
    71.6.3.3. Gettext source with plural definitions
    71.6.4. Custom plural rules

    71.1. Introduction

    Zend_Translate is Zend Framework's solution for multilingual applications.

    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 recommend using Zend_Translate instead of PHP's native functions. The benefits of Zend_Translate are:

    • Supports multiple source formats: Zend_Translate supports several source formats, including those supported by PHP, and other formats including TMX and CSV files.

    • Thread-safe gettext: 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 storage adapter.

    • Detection of the user's standard language: The preferred language of the user accessing the site can be detected and used by Zend_Translate.

    • 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.

    71.1.1. Starting multi-lingual

    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:

    1. Decide which adapter you want to use;

    2. Create your view and integrate Zend_Translate in your code;

    3. Create the source file from your code;

    4. 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.

    digg delicious meneame google twitter technorati facebook

    Comments

    Loading...