View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Translate
{zone-data}

{zone-data:proposer-list}
* [~thomas]
** Team lead and main author
* [~alexander]
** (Zend-liaison)
{zone-data}

{zone-data:revision}
1.0 - 19 September 2006: Extracted from Zend_Locale
{zone-data}

{zone-data:overview}
The Zend_Translate component provides the [Zend Framework|http://framework.zend.com] with message translation functionality, where pre-translated strings are stored in a structured manner suitable for algorithmic use by ZF developers. It can handle different source file formats for translation. Locale-awareness is achieved using [Zend_Locale|Zend_Locale Proposal - Thomas Weidner].
{zone-data}

{zone-data:references}
h3. +Source Integration+
Details on Translation Source Standards which have to be integrated.

{anchor:tmx}
h4. TMX Standard
TMX is a XML based industry standard for translating issues.
* [Localization Industry Standard Association - Funder of the TMX Standard|http://lisa.org/standards/tmx/]
* [Open Source Extension of Java Ressource Bundle Class for direct access to TMX|http://sourceforge.net/projects/tmxphpbridge/]
* [Working example of TMX with PHP|http://www.evolt.org/PHP-Localization-with-TMX-standard]

{anchor:gettext}
h4. GetText Standard
Gettext is a popular standard for open-source translation support.
* [PHP GetText Project|http://savannah.nongnu.org/projects/php-gettext/] - pure PHP solution avoiding idiosyncrasies of traditional gettext() library
* [O'Reilly article about using gettext with php|http://www.onlamp.com/pub/a/php/2002/06/13/php.html]
* [A blog about benchmarking different gettext implementations|http://mel.melaxis.com/devblog/2006/04/10/benchmarking-php-localization-is-gettext-fast-enough/#more-13]
* [Savant3 Project approach for templates using gettext|http://svn.cyberlot.net/Savantgettext]

{anchor:ldml}
h3. +Common Language Data Repository+
For details on CLDR and it's implementation in the framework look at [Zend_Locale|Zend_Locale Proposal - Thomas Weidner]

h3. +Additional Informations and International Standards+
The following international standards must be used with Zend_Translate in order to maintain compatibility with Zend_Locale.

{anchor:iso639}
h4. ISO 639
International Language Code Definition
ISO 639-1 for 2 letter, ISO 639-2 for 3 letter language codes
* [Home of ISO 639|http://www.loc.gov/standards/iso639-2/]
* [Language codes from ISO 639-1 and ISO 639-2|http://www.loc.gov/standards/iso639-2/langcodes.html]

{anchor:iso3166}
h4. ISO 3166
International Country Code Definitions
ISO 3166-1 for 2 letter country codes
* [Home of ISO 3166|http://www.iso.org/iso/en/prods-services/iso3166ma/index.html]
* [Country List from ISO 3166-1|http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html]

{anchor:rfc3066}
h4. RFC 3066
Identification of languages
* [Memo of language identification|http://www.ietf.org/rfc/rfc3066.txt]
* [Language Tag List for RFC 3066|http://www.evertype.com/standards/iso639/iana-lang-assignments.html]

h3. +I18N General+
* [I18N Gurus - Open international ressources directory|http://www.i18ngurus.com/]

h3. +Mailing Lists+
Mailinglist discussions in past:

h4. Unicode Discussion for upcoming PHP6
* [PHP 6 Unicode Discussion|http://marc.theaimsgroup.com/?l=php-i18n]

h4. Discussions for Zend Framework
* [Johannes Orth - first thoughts about locale support|http://www.zend.com/lists/fw-general/200605/msg00273.html]
* [Jason Mynard - general I18N thoughts|http://www.zend.com/lists/fw-general/200605/msg00787.html]
* [Garvin Vess - first summary of needed functions|http://www.zend.com/lists/fw-general/200605/msg00814.html]
* [Thomas Weidner - summarize functionality for Zend_Locale|http://www.zend.com/lists/fw-general/200605/msg00974.html]
* [Gavin Vess - simplifying I18N needs|http://www.zend.com/lists/fw-general/200605/msg01020.html]
* [Gavin Vess - First response of pre-proposal for Zend_Locale|http://www.zend.com/lists/fw-general/200606/msg00040.html]
{zone-data}

{zone-data:requirements}
* Wrapper functionality
* Lightweight and fast implementation
* Simple use for ZF-user
* Handling of different source formats
* Automatic recognition of language the browser requests
{zone-data}

{zone-data:dependencies}
* [Zend_Locale|Zend_Locale Proposal - Thomas Weidner]
* Zend_Exception
{zone-data}

{zone-data:operation}
h4. *+Basics+*
Zend_Translate is a wrapper for string message translating mechanisms in the [Zend Framework|http://framework.zend.com]. It has to be simple to use and as lightweight as possible. Phrases (string messages) are translated by a simple mapping of phrases from one language to other languages, instead of using linguistics or semantic translation mechanisms. The phrases and mappings are created by people for their applications, possibly using software editing tools, such as [poEdit|http://www.poedit.org].

h4. *+Source formats/Abstraction+*
Zend_Translate must work with different source formats. The initial supported source formats will be:
* [Gettext|#gettext]
* [Tmx|#tmx]
* Sql Databases (MySql, Mssql, SqLite) through Zend_DB

Each translation source will be integrated as Adaptor, so each source format has to implement the same functionality. The handling is equal for each source format, so the user has only to know the base layer Zend_Translate, and not the details for [Gettext|#gettext], [Tmx|#tmx] and so on.

h4. *+Locale awareness+*
Zend_Translate must be locale-aware, and must therefore use Zend_Locale.

h4. *+Automatic language recognition+*
This will be done using Zend_Locale.

h4. *+Locale aware formatting+*
Zend_Translate should be aware of localized date/time and number strings by using Zend_Locale_Format.
{zone-data}

{zone-data:milestones}
* Milestone 2: \[DONE\] Core implementation
* Milestone 3: \[DONE\] Zend_Translate base class implementation
* Milestone 4: \[DONE\] Zend_Translate_Gettext, unit tests, and docs
* Milestone 5: \[DONE\] Zend_Translate_Array, unit tests, and docs
* Milestone 6: \[DONE\] Documentation
* Milestone 7: \[DONE\] Zend_Translate_TMX implementation, unit tests, and docs.
* Milestone 8: \[0%\] Zend_Translate_Sql implementation, unit tests, and docs.

Already implemented milestones:
* Milestone 1: \[DONE\] Design notes
{zone-data}

{zone-data:class-list}
* Zend_Translate - base class
* Zend_Translate_Exception- exception handling
* Zend_Translate_Adapter - base adapter class
* Zend_Translate_Array - Array adapter
* Zend_Translate_Core - Core adapter
* Zend_Translate_Gettext - Gettext adapter
* Zend_Translate_Tmx - Tmx adapter
* Zend_Translate_Sql - Sql adapte
{zone-data}

{zone-data:use-cases}
Use of translation - HTTP_ACCEPT_LANGUAGE: de_AT
{code}
$lang = new Zend_Translate(Zend_Translate::GETTEXT, '\home\www\lang\');
print $lang->_('Do you speak german ?'); // Prints: Sprichst Du deutsch ?
{code}

Set temporary other language
{code}
$lang = new Zend_Translate(Zend_Translate::GETTEXT, '\home\www\lang\');
print $lang->_('Do you speak german ?'); // Prints: Sprichst Du deutsch ?
print $lang->_('Do you speak german ?',Zend_Locale::fr_FR); // Prints: Parles-vu allemand ?
{code}

Set other language not temporary
{code}
$lang = new Zend_Translate(Zend_Translate::GETTEXT, '\home\www\lang\');
print $lang->_('Do you speak german ?'); // Prints: Sprichst Du deutsch ?
$lang->setLanguage(Zend_Locale::fr_FR);
print $lang->_('Do you speak german ?'); // Prints: Parles-vu allemand ?
{code}

Get actual locale settings
{code}
$lang = new Zend_Translate(Zend_Translate::SQL, 'mysql', 'admin', 'sa', 'translatedb');
$language = $lang->getLanguage(); // returns de
$language = $lang->getCountry(); // returns AT
{code}

Set a different locale source
{code}
$lang = new Zend_Translate(Zend_Translate::GETTEXT, '\home\www\lang\');
print $lang->_('Do you speak german ?'); // Prints: Sprichst Du deutsch ?
$lang->setSource(Zend_Translate::TMX, '\home\www\tmx');
print $lang->_('Do you also speak german ?'); // Prints: Sprichst Du auch deutsch ?
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Translate_Exception extends Zend_Exception {}


class Zend_Translate {

/**
* Constructor for the Zend_Translate Module
* Sets the default locale automaticaly with HTTP_ACCEPT_LANGUAGE
* Can get the default locale source from Config or Connection if set
*
* @param object $connection - OPTIONAL a connection can be defined
* @param string $locale - OPTIONAL default locale
*/
public function __construct($connection,$locale) {}

/**
* Serializes the object
*/
public function serialize() {}

/**
* Unserialized the object
*/
public function unserialize($serialized) {}

/**
* Sets a different connection source
*
* @param object $connection
* @param string $locales - OPTIONAL for which locales this connection is
*/
public function setSource($connection,$locales) {}

/**
* Returns the actual connection source
*
* @param string $locale - OPTIONAL the locale for which we search connection
* @return object $connection
*/
public function getSource($locale) {}

/**
* Sets a new locale which has to be used for translation
*
* @param string $locale
*/
public function setLocale($locale) {}

/**
* Returns the actual set locale for translation
*
* @return string $locale
*/
public function getLocale() {}

/**
* Returns a list of all avaiable locales which can be used for translation
* by this Framework in a well formed array. This depends on the locales
* which are integrated in the source files.
*
* This function could, for example, be used to find the avaiable
* locales, and then display only the supported country flags on a page.
*
* @return array $locales
*/
public function getList() {}

/**
* Returns if a specified locale is avaiable for translation
*
* @param string $locale - Locale to search
* @return boolean
*/
public function isAvaiable($locale) {}

/**
* Returns the actual set Language
*
* @return string $language
*/
public function getLanguage() {}

/**
* Returns the actual set Regioncode
*
* @return string $regionCode
*/
public function getRegion() {}

/**
* Returns the default locale.
* With type the source looking for the default locale could be seperated.
*
* Returns the default locale
*
* @return locale
*/
public function getDefault($type) {}

/**
* _ is a shortcut for translate()
* I know that Zend does not permitt Underscores in function names
* but it is a standard shortcut in php for the translating function
* It's Zend's decision if we could use this or not
*
* @see translate($string,$locale)
*/
public function _($string,$locale) {}

/**
* Translates a given string to the defined locale
*
* @param string $translationString
* @param string $locale - optional
* @return string $translatedString
*/
public function translate($translationString,$locale) {}
}


abstract class Zend_Translate_Abstract {

/**
* Abstract definition class for all source formats
* the Framework will integrate. So in future
* the framework could be expanded with new source formats
* and users has everytime the same interface
*/

/**
* Constructor defines the connection parameters
*
* @params mixed $parameters - parameters for this source connection
*/
abstract protected function __constructor($parameters);

/**
* Returns the actual connection parameters
*
* @return object
*/
abstract protected function getConnection ()

/**
* Connects to a new source target within the same format
*
* @params mixed $parameters - new connection parameters
*/
abstract protected function setConnection($parameters)

/**
* Sets a new locale for useage
*
* @param string $locale
*/
abstract protected function setLocale ($locale)

/**
* Returns the actual set locale
*
* @return string
*/
abstract protected function getLocale ()

/**
* Returns a translated string
*
* @return string $translated
*/
abstract protected function translate ($translation)
}


class Zend_Translate_Gettext extends Zend_Translate_Abstract {}
class Zend_Translate_Tmx extends Zend_Translate_Abstract {}
class Zend_Translate_Sql extends Zend_Translate_Abstract {}

{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>