| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.translate.adapter">
- <title>Adapters for Zend_Translate</title>
- <para>
- <classname>Zend_Translate</classname> can handle different adapters for translation.
- Each adapter has its own advantages and disadvantages.
- Below is a comprehensive list of all supported adapters for
- translation source files.
- </para>
- <table id="zend.translate.adapter.table">
- <title>Adapters for Zend_Translate</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>Adapter</entry>
- <entry>Description</entry>
- <entry>Usage</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Array</entry>
- <entry>Use PHP arrays</entry>
- <entry>Small pages; simplest usage; only for programmers</entry>
- </row>
- <row>
- <entry>Csv</entry>
- <entry>Use comma seperated (*.csv/*.txt) files</entry>
- <entry>Simple text file format; fast; possible problems with unicode characters</entry>
- </row>
- <row>
- <entry>Gettext</entry>
- <entry>Use binary gettext (*.mo) files</entry>
- <entry>GNU standard for linux; thread-safe; needs tools for translation</entry>
- </row>
- <row>
- <entry>Ini</entry>
- <entry>Use simple ini (*.ini) files</entry>
- <entry>Simple text file format; fast; possible problems with unicode characters</entry>
- </row>
- <row>
- <entry>Tbx</entry>
- <entry>Use termbase exchange (*.tbx/*.xml) files</entry>
- <entry>Industry standard for inter application terminology strings; XML format</entry>
- </row>
- <row>
- <entry>Tmx</entry>
- <entry>Use tmx (*.tmx/*.xml) files</entry>
- <entry>Industry standard for inter application translation; XML format; human readable</entry>
- </row>
- <row>
- <entry>Qt</entry>
- <entry>Use qt linguist (*.ts) files</entry>
- <entry>Cross platform application framework; XML format; human readable</entry>
- </row>
- <row>
- <entry>Xliff</entry>
- <entry>Use xliff (*.xliff/*.xml) files</entry>
- <entry>A simpler format as TMX but related to it; XML format; human readable</entry>
- </row>
- <row>
- <entry>XmlTm</entry>
- <entry>Use xmltm (*.xml) files</entry>
- <entry>Industry standard for XML document translation memory; XML format; human readable</entry>
- </row>
- <row>
- <entry>Others</entry>
- <entry>*.sql</entry>
- <entry>Different other adapters may be implemented in the future</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <sect2 id="zend.translate.adapter.decision">
- <title>How to decide which translation adapter to use</title>
- <para>
- You should decide which Adapter you want to use for <classname>Zend_Translate</classname>.
- Frequently, external criteria such as a project requirement or
- a customer requirement determines this for you, but if you are in
- the position to do this yourself, the following hints may simplify
- your decision.
- </para>
- <note>
- <para>
- When deciding your adapter you should also be aware of the used
- encoding. Even if Zend Framework declares UTF-8 as default
- encoding you will sometimes be in the need of other encoding.
- <classname>Zend_Translate</classname> will not change any encoding which is defined
- within the source file which means that if your Gettext source
- is build upon ISO-8859-1 it will also return strings in this encoding
- without converting them. There is only one restriction:
- </para>
- <para>
- When you use a xml based source format like TMX or XLIFF you must
- define the encoding within the xml files header because xml files
- without defined encoding will be treated as UTF-8 by any xml parser
- by default. You should also be aware that actually the encoding of
- xml files is limited to the encodings supported by PHP which are
- UTF-8, ISO-8859-1 and US-ASCII.
- </para>
- </note>
- <sect3 id="zend.translate.adapter.array">
- <title>Zend_Translate_Adapter_Array</title>
- <para>
- The Array Adapter is the Adapter which is simplest to use for
- programmers.
- But when you have numerous translation strings or many
- languages you should think about another Adapter.
- For example, if you have 5000 translation strings,
- the Array Adapter is possibly not the best choice for you.
- </para>
- <para>
- You should only use this Adapter for small sites with a handful
- of languages, and if you or your programmer team creates the
- translations yourselves.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.csv">
- <title>Zend_Translate_Adapter_Csv</title>
- <para>
- The Csv Adapter is the Adapter which is simplest to use for
- customers.
- CSV files are readable by standard text editors, but
- text editors often do not support utf8 character sets.
- </para>
- <para>
- You should only use this Adapter if your customer wants to do
- translations himself.
- </para>
- <note>
- <para>
- Beware that the Csv Adapter has problems when your Csv files are encoded differently than
- the locale setting of your environment. This is due to a Bug of PHP itself which will not
- be fixed before PHP 6.0 (http://bugs.php.net/bug.php?id=38471). So you should be aware
- that the Csv Adapter due to PHP restrictions is not locale aware.
- </para>
- </note>
- </sect3>
- <sect3 id="zend.translate.adapter.gettext">
- <title>Zend_Translate_Adapter_Gettext</title>
- <para>
- The Gettext Adapter is the Adapter which is used most
- frequently. Gettext is a translation source format which was
- introduced by GNU, and is now used worldwide.
- It is not human readable, but there are several freeware tools
- (for instance, <ulink url="http://sourceforge.net/projects/poedit/">POEdit</ulink>), which are very helpful.
- The <classname>Zend_Translate</classname> Gettext Adapter is not implemented using
- PHP's gettext extension.
- You can use the Gettext Adapter even if you do not have
- the PHP gettext extension installed.
- Also the Adapter is thread-safe and the PHP gettext extension
- is currently not thread-safe.
- </para>
- <para>
- Most people will use this adapter.
- With the available tools, professional translation is
- very simple. But gettext data are is stored in a
- machine-readable format, which is not readable without tools.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.ini">
- <title>Zend_Translate_Adapter_Ini</title>
- <para>
- The Ini Adapter is a very simple Adapter which can even be used
- directly by customers.
- INI files are readable by standard text editors, but
- text editors often do not support utf8 character sets.
- </para>
- <para>
- You should only use this Adapter when your customer wants to do translations
- himself. Do not use this adapter as generic translation source.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.tbx">
- <title>Zend_Translate_Adapter_Tbx</title>
- <para>
- The Tbx Adapter is an Adapter which will be used by customers
- which already use the TBX format for their internal translation
- system. Tbx is no standard translation format but more a collection
- of already translated and pre translated source strings. When you
- use this adapter you have to be sure that all your needed source
- string are translated.
- TBX is a XML file based format and a completly new format.
- XML files are human-readable, but the parsing is not as fast
- as with gettext files.
- </para>
- <para>
- This adapter is perfect for companies when pre translated
- source files already exist.
- The files are human readable and system-independent.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.tmx">
- <title>Zend_Translate_Adapter_Tmx</title>
- <para>
- The Tmx Adapter is the Adapter which will be used by most
- customers which have multiple systems which use the same
- translation source, or when the translation source must be
- system-independent.
- TMX is a XML file based format, which is announced to be the
- next industry standard.
- XML files are human-readable, but the parsing is not as fast
- as with gettext files.
- </para>
- <para>
- Most medium to large companies use this adapter.
- The files are human readable and system-independent.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.qt">
- <title>Zend_Translate_Adapter_Qt</title>
- <para>
- The Qt Adapter is for all customers which have TS files as their
- translation source which are made by QtLinguist.
- QT is a XML file based format.
- XML files are human-readable, but the parsing is not as fast
- as with gettext files.
- </para>
- <para>
- Several big players have build software upon the QT framework.
- The files are human readable and system-independent.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.xliff">
- <title>Zend_Translate_Adapter_Xliff</title>
- <para>
- The Xliff Adapter is the Adapter which will be used by most
- customers which want to have XML files but do not have tools
- for TMX.
- XLIFF is a XML file based format, which is related to TMX but
- simpler as it does not support all possibilities of it.
- XML files are human-readable, but the parsing is not as fast
- as with gettext files.
- </para>
- <para>
- Most medium companies use this adapter.
- The files are human readable and system-independent.
- </para>
- </sect3>
- <sect3 id="zend.translate.adapter.xmltm">
- <title>Zend_Translate_Adapter_XmlTm</title>
- <para>
- The XmlTm Adapter is the Adapter which will be used by customers
- which do their layout themself. XmlTm is a format which allows the
- complete html source to be included in the translation source, so
- the translation is coupled with the layout.
- XLIFF is a XML file based format, which is related to XLIFF but
- its not as simple to read.
- </para>
- <para>
- This adapter should only be used when source files already exist.
- The files are human readable and system-independent.
- </para>
- </sect3>
- </sect2>
- <sect2 id="zend.translate.adapter.selfwritten">
- <title>Integrate self written Adapters</title>
- <para>
- <classname>Zend_Translate</classname> allows you to integrate and use self written Adapter
- classes. They can be used like the standard Adapter classes which
- are already included within <classname>Zend_Translate</classname>.
- </para>
- <para>
- Any adapter class you want to use with <classname>Zend_Translate</classname> must be a subclass
- of <classname>Zend_Translate_Adapter</classname>. <classname>Zend_Translate_Adapter</classname> is an abstract class
- which already defines all what is needed for translation. What has to be
- done by you, is the definition of the reader for translation datas.
- </para>
- <para>
- The usage of the prefix "Zend" should be limited to Zend Framework.
- If you extend <classname>Zend_Translate</classname> with your own adapter, you should name it
- like "Company_Translate_Adapter_MyFormat". The following code shows an
- example of how a self written adapter class could be implemented:
- </para>
- <programlisting language="php"><![CDATA[
- try {
- $translate = new Zend_Translate('Company_Translate_Adapter_MyFormat',
- '/path/to/translate.xx',
- 'en',
- array('myoption' => 'myvalue'));
- } catch (Exception $e) {
- // File not found, no adapter class...
- // General failure
- }
- ]]></programlisting>
- </sect2>
- <sect2 id="zend.translate.adapter.caching">
- <title>Speedup all Adapters</title>
- <para>
- <classname>Zend_Translate</classname> allows you use internally <classname>Zend_Cache</classname> to
- fasten the loading of translation sources. This comes very handy if you use many
- translation sources or extensive source formats like XML based files.
- </para>
- <para>
- To use caching you will just have to give a cache object to the
- <classname>Zend_Translate::setCache()</classname> method. It takes a instance of
- <classname>Zend_Cache</classname> as only parameter. Also if you use any adapter direct you
- can use the <code>setCache()</code> method. For convenience there are also the static methods
- <code>getCache()</code>, <code>hasCache()</code>, <code>clearCache()</code> and
- <code>removeCache()</code>.
- </para>
- <programlisting language="php"><![CDATA[
- $cache = Zend_Cache::factory('Core',
- 'File',
- $frontendOptions,
- $backendOptions);
- Zend_Translate::setCache($cache);
- $translate = new Zend_Translate('gettext',
- '/path/to/translate.mo',
- 'en');
- ]]></programlisting>
- <note>
- <para>
- You must set the cache <emphasis>before</emphasis> you use or initiate
- any adapter or instance of <classname>Zend_Translate</classname>. Otherwise your translation
- source will not be cached until you add a new source with the
- <code>addTranslation()</code> method.
- </para>
- </note>
- </sect2>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|