Zend_Translate-Adapters.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.translate.adapter">
  4. <title>Adapters for Zend_Translate</title>
  5. <para>
  6. <classname>Zend_Translate</classname> can handle different adapters for translation.
  7. Each adapter has its own advantages and disadvantages.
  8. Below is a comprehensive list of all supported adapters for
  9. translation source files.
  10. </para>
  11. <table id="zend.translate.adapter.table">
  12. <title>Adapters for Zend_Translate</title>
  13. <tgroup cols="3">
  14. <thead>
  15. <row>
  16. <entry>Adapter</entry>
  17. <entry>Description</entry>
  18. <entry>Usage</entry>
  19. </row>
  20. </thead>
  21. <tbody>
  22. <row>
  23. <entry>Array</entry>
  24. <entry>Use PHP arrays</entry>
  25. <entry>Small pages; simplest usage; only for programmers</entry>
  26. </row>
  27. <row>
  28. <entry>Csv</entry>
  29. <entry>Use comma seperated (*.csv/*.txt) files</entry>
  30. <entry>Simple text file format; fast; possible problems with unicode characters</entry>
  31. </row>
  32. <row>
  33. <entry>Gettext</entry>
  34. <entry>Use binary gettext (*.mo) files</entry>
  35. <entry>GNU standard for linux; thread-safe; needs tools for translation</entry>
  36. </row>
  37. <row>
  38. <entry>Ini</entry>
  39. <entry>Use simple ini (*.ini) files</entry>
  40. <entry>Simple text file format; fast; possible problems with unicode characters</entry>
  41. </row>
  42. <row>
  43. <entry>Tbx</entry>
  44. <entry>Use termbase exchange (*.tbx/*.xml) files</entry>
  45. <entry>Industry standard for inter application terminology strings; XML format</entry>
  46. </row>
  47. <row>
  48. <entry>Tmx</entry>
  49. <entry>Use tmx (*.tmx/*.xml) files</entry>
  50. <entry>Industry standard for inter application translation; XML format; human readable</entry>
  51. </row>
  52. <row>
  53. <entry>Qt</entry>
  54. <entry>Use qt linguist (*.ts) files</entry>
  55. <entry>Cross platform application framework; XML format; human readable</entry>
  56. </row>
  57. <row>
  58. <entry>Xliff</entry>
  59. <entry>Use xliff (*.xliff/*.xml) files</entry>
  60. <entry>A simpler format as TMX but related to it; XML format; human readable</entry>
  61. </row>
  62. <row>
  63. <entry>XmlTm</entry>
  64. <entry>Use xmltm (*.xml) files</entry>
  65. <entry>Industry standard for XML document translation memory; XML format; human readable</entry>
  66. </row>
  67. <row>
  68. <entry>Others</entry>
  69. <entry>*.sql</entry>
  70. <entry>Different other adapters may be implemented in the future</entry>
  71. </row>
  72. </tbody>
  73. </tgroup>
  74. </table>
  75. <sect2 id="zend.translate.adapter.decision">
  76. <title>How to decide which translation adapter to use</title>
  77. <para>
  78. You should decide which Adapter you want to use for <classname>Zend_Translate</classname>.
  79. Frequently, external criteria such as a project requirement or
  80. a customer requirement determines this for you, but if you are in
  81. the position to do this yourself, the following hints may simplify
  82. your decision.
  83. </para>
  84. <note>
  85. <para>
  86. When deciding your adapter you should also be aware of the used
  87. encoding. Even if Zend Framework declares UTF-8 as default
  88. encoding you will sometimes be in the need of other encoding.
  89. <classname>Zend_Translate</classname> will not change any encoding which is defined
  90. within the source file which means that if your Gettext source
  91. is build upon ISO-8859-1 it will also return strings in this encoding
  92. without converting them. There is only one restriction:
  93. </para>
  94. <para>
  95. When you use a xml based source format like TMX or XLIFF you must
  96. define the encoding within the xml files header because xml files
  97. without defined encoding will be treated as UTF-8 by any xml parser
  98. by default. You should also be aware that actually the encoding of
  99. xml files is limited to the encodings supported by PHP which are
  100. UTF-8, ISO-8859-1 and US-ASCII.
  101. </para>
  102. </note>
  103. <sect3 id="zend.translate.adapter.array">
  104. <title>Zend_Translate_Adapter_Array</title>
  105. <para>
  106. The Array Adapter is the Adapter which is simplest to use for
  107. programmers.
  108. But when you have numerous translation strings or many
  109. languages you should think about another Adapter.
  110. For example, if you have 5000 translation strings,
  111. the Array Adapter is possibly not the best choice for you.
  112. </para>
  113. <para>
  114. You should only use this Adapter for small sites with a handful
  115. of languages, and if you or your programmer team creates the
  116. translations yourselves.
  117. </para>
  118. </sect3>
  119. <sect3 id="zend.translate.adapter.csv">
  120. <title>Zend_Translate_Adapter_Csv</title>
  121. <para>
  122. The Csv Adapter is the Adapter which is simplest to use for
  123. customers.
  124. CSV files are readable by standard text editors, but
  125. text editors often do not support utf8 character sets.
  126. </para>
  127. <para>
  128. You should only use this Adapter if your customer wants to do
  129. translations himself.
  130. </para>
  131. <note>
  132. <para>
  133. Beware that the Csv Adapter has problems when your Csv files are encoded differently than
  134. the locale setting of your environment. This is due to a Bug of PHP itself which will not
  135. be fixed before PHP 6.0 (http://bugs.php.net/bug.php?id=38471). So you should be aware
  136. that the Csv Adapter due to PHP restrictions is not locale aware.
  137. </para>
  138. </note>
  139. </sect3>
  140. <sect3 id="zend.translate.adapter.gettext">
  141. <title>Zend_Translate_Adapter_Gettext</title>
  142. <para>
  143. The Gettext Adapter is the Adapter which is used most
  144. frequently. Gettext is a translation source format which was
  145. introduced by GNU, and is now used worldwide.
  146. It is not human readable, but there are several freeware tools
  147. (for instance, <ulink url="http://sourceforge.net/projects/poedit/">POEdit</ulink>), which are very helpful.
  148. The <classname>Zend_Translate</classname> Gettext Adapter is not implemented using
  149. PHP's gettext extension.
  150. You can use the Gettext Adapter even if you do not have
  151. the PHP gettext extension installed.
  152. Also the Adapter is thread-safe and the PHP gettext extension
  153. is currently not thread-safe.
  154. </para>
  155. <para>
  156. Most people will use this adapter.
  157. With the available tools, professional translation is
  158. very simple. But gettext data are is stored in a
  159. machine-readable format, which is not readable without tools.
  160. </para>
  161. </sect3>
  162. <sect3 id="zend.translate.adapter.ini">
  163. <title>Zend_Translate_Adapter_Ini</title>
  164. <para>
  165. The Ini Adapter is a very simple Adapter which can even be used
  166. directly by customers.
  167. INI files are readable by standard text editors, but
  168. text editors often do not support utf8 character sets.
  169. </para>
  170. <para>
  171. You should only use this Adapter when your customer wants to do translations
  172. himself. Do not use this adapter as generic translation source.
  173. </para>
  174. </sect3>
  175. <sect3 id="zend.translate.adapter.tbx">
  176. <title>Zend_Translate_Adapter_Tbx</title>
  177. <para>
  178. The Tbx Adapter is an Adapter which will be used by customers
  179. which already use the TBX format for their internal translation
  180. system. Tbx is no standard translation format but more a collection
  181. of already translated and pre translated source strings. When you
  182. use this adapter you have to be sure that all your needed source
  183. string are translated.
  184. TBX is a XML file based format and a completly new format.
  185. XML files are human-readable, but the parsing is not as fast
  186. as with gettext files.
  187. </para>
  188. <para>
  189. This adapter is perfect for companies when pre translated
  190. source files already exist.
  191. The files are human readable and system-independent.
  192. </para>
  193. </sect3>
  194. <sect3 id="zend.translate.adapter.tmx">
  195. <title>Zend_Translate_Adapter_Tmx</title>
  196. <para>
  197. The Tmx Adapter is the Adapter which will be used by most
  198. customers which have multiple systems which use the same
  199. translation source, or when the translation source must be
  200. system-independent.
  201. TMX is a XML file based format, which is announced to be the
  202. next industry standard.
  203. XML files are human-readable, but the parsing is not as fast
  204. as with gettext files.
  205. </para>
  206. <para>
  207. Most medium to large companies use this adapter.
  208. The files are human readable and system-independent.
  209. </para>
  210. </sect3>
  211. <sect3 id="zend.translate.adapter.qt">
  212. <title>Zend_Translate_Adapter_Qt</title>
  213. <para>
  214. The Qt Adapter is for all customers which have TS files as their
  215. translation source which are made by QtLinguist.
  216. QT is a XML file based format.
  217. XML files are human-readable, but the parsing is not as fast
  218. as with gettext files.
  219. </para>
  220. <para>
  221. Several big players have build software upon the QT framework.
  222. The files are human readable and system-independent.
  223. </para>
  224. </sect3>
  225. <sect3 id="zend.translate.adapter.xliff">
  226. <title>Zend_Translate_Adapter_Xliff</title>
  227. <para>
  228. The Xliff Adapter is the Adapter which will be used by most
  229. customers which want to have XML files but do not have tools
  230. for TMX.
  231. XLIFF is a XML file based format, which is related to TMX but
  232. simpler as it does not support all possibilities of it.
  233. XML files are human-readable, but the parsing is not as fast
  234. as with gettext files.
  235. </para>
  236. <para>
  237. Most medium companies use this adapter.
  238. The files are human readable and system-independent.
  239. </para>
  240. </sect3>
  241. <sect3 id="zend.translate.adapter.xmltm">
  242. <title>Zend_Translate_Adapter_XmlTm</title>
  243. <para>
  244. The XmlTm Adapter is the Adapter which will be used by customers
  245. which do their layout themself. XmlTm is a format which allows the
  246. complete html source to be included in the translation source, so
  247. the translation is coupled with the layout.
  248. XLIFF is a XML file based format, which is related to XLIFF but
  249. its not as simple to read.
  250. </para>
  251. <para>
  252. This adapter should only be used when source files already exist.
  253. The files are human readable and system-independent.
  254. </para>
  255. </sect3>
  256. </sect2>
  257. <sect2 id="zend.translate.adapter.selfwritten">
  258. <title>Integrate self written Adapters</title>
  259. <para>
  260. <classname>Zend_Translate</classname> allows you to integrate and use self written Adapter
  261. classes. They can be used like the standard Adapter classes which
  262. are already included within <classname>Zend_Translate</classname>.
  263. </para>
  264. <para>
  265. Any adapter class you want to use with <classname>Zend_Translate</classname> must be a subclass
  266. of <classname>Zend_Translate_Adapter</classname>. <classname>Zend_Translate_Adapter</classname> is an abstract class
  267. which already defines all what is needed for translation. What has to be
  268. done by you, is the definition of the reader for translation datas.
  269. </para>
  270. <para>
  271. The usage of the prefix "Zend" should be limited to Zend Framework.
  272. If you extend <classname>Zend_Translate</classname> with your own adapter, you should name it
  273. like "Company_Translate_Adapter_MyFormat". The following code shows an
  274. example of how a self written adapter class could be implemented:
  275. </para>
  276. <programlisting language="php"><![CDATA[
  277. try {
  278. $translate = new Zend_Translate('Company_Translate_Adapter_MyFormat',
  279. '/path/to/translate.xx',
  280. 'en',
  281. array('myoption' => 'myvalue'));
  282. } catch (Exception $e) {
  283. // File not found, no adapter class...
  284. // General failure
  285. }
  286. ]]></programlisting>
  287. </sect2>
  288. <sect2 id="zend.translate.adapter.caching">
  289. <title>Speedup all Adapters</title>
  290. <para>
  291. <classname>Zend_Translate</classname> allows you use internally <classname>Zend_Cache</classname> to
  292. fasten the loading of translation sources. This comes very handy if you use many
  293. translation sources or extensive source formats like XML based files.
  294. </para>
  295. <para>
  296. To use caching you will just have to give a cache object to the
  297. <classname>Zend_Translate::setCache()</classname> method. It takes a instance of
  298. <classname>Zend_Cache</classname> as only parameter. Also if you use any adapter direct you
  299. can use the <code>setCache()</code> method. For convenience there are also the static methods
  300. <code>getCache()</code>, <code>hasCache()</code>, <code>clearCache()</code> and
  301. <code>removeCache()</code>.
  302. </para>
  303. <programlisting language="php"><![CDATA[
  304. $cache = Zend_Cache::factory('Core',
  305. 'File',
  306. $frontendOptions,
  307. $backendOptions);
  308. Zend_Translate::setCache($cache);
  309. $translate = new Zend_Translate('gettext',
  310. '/path/to/translate.mo',
  311. 'en');
  312. ]]></programlisting>
  313. <note>
  314. <para>
  315. You must set the cache <emphasis>before</emphasis> you use or initiate
  316. any adapter or instance of <classname>Zend_Translate</classname>. Otherwise your translation
  317. source will not be cached until you add a new source with the
  318. <code>addTranslation()</code> method.
  319. </para>
  320. </note>
  321. </sect2>
  322. </sect1>
  323. <!--
  324. vim:se ts=4 sw=4 et:
  325. -->