Zend_Translate-Adapters.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 <acronym>PHP</acronym> 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; <acronym>XML</acronym> 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; <acronym>XML</acronym> 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; <acronym>XML</acronym> 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 <constant>TMX</constant> but related to it; <acronym>XML</acronym> format; human readable</entry>
  61. </row>
  62. <row>
  63. <entry>XmlTm</entry>
  64. <entry>Use xmltm (*.xml) files</entry>
  65. <entry>Industry standard for <acronym>XML</acronym> document translation memory; <acronym>XML</acronym> 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 <acronym>PHP</acronym> 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 <acronym>PHP</acronym> itself which will not
  135. be fixed before <acronym>PHP</acronym> 6.0 (http://bugs.php.net/bug.php?id=38471). So you should be aware
  136. that the Csv Adapter due to <acronym>PHP</acronym> 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. <acronym>PHP</acronym>'s gettext extension.
  150. You can use the Gettext Adapter even if you do not have
  151. the <acronym>PHP</acronym> gettext extension installed.
  152. Also the Adapter is thread-safe and the <acronym>PHP</acronym> 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. <acronym>INI</acronym> 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. <warning>
  175. <title>Regression in PHP 5.3</title>
  176. <para>
  177. Prior to <acronym>PHP</acronym> 5.3, <function>parse_ini_file()</function> and
  178. <function>parse_ini_string()</function> handled non-ASCII characters
  179. within <acronym>INI</acronym> option keys worked without an issue. However, starting with <acronym>PHP</acronym> 5.3,
  180. any such keys will now be silently dropped in the returned array from either
  181. function. If you had keys utilizing UTF-8 or Latin-1 characters, you may find
  182. your translations no longer work when using the <acronym>INI</acronym> adapter. If this is the
  183. case, we recommend utilizing a different adapter.
  184. </para>
  185. </warning>
  186. </sect3>
  187. <sect3 id="zend.translate.adapter.tbx">
  188. <title>Zend_Translate_Adapter_Tbx</title>
  189. <para>
  190. The Tbx Adapter is an Adapter which will be used by customers
  191. which already use the TBX format for their internal translation
  192. system. Tbx is no standard translation format but more a collection
  193. of already translated and pre translated source strings. When you
  194. use this adapter you have to be sure that all your needed source
  195. string are translated.
  196. TBX is a <acronym>XML</acronym> file based format and a completely new format.
  197. <acronym>XML</acronym> files are human-readable, but the parsing is not as fast
  198. as with gettext files.
  199. </para>
  200. <para>
  201. This adapter is perfect for companies when pre translated
  202. source files already exist.
  203. The files are human readable and system-independent.
  204. </para>
  205. </sect3>
  206. <sect3 id="zend.translate.adapter.tmx">
  207. <title>Zend_Translate_Adapter_Tmx</title>
  208. <para>
  209. The Tmx Adapter is the Adapter which will be used by most
  210. customers which have multiple systems which use the same
  211. translation source, or when the translation source must be
  212. system-independent.
  213. TMX is a <acronym>XML</acronym> file based format, which is announced to be the
  214. next industry standard.
  215. <acronym>XML</acronym> files are human-readable, but the parsing is not as fast
  216. as with gettext files.
  217. </para>
  218. <para>
  219. Most medium to large companies use this adapter.
  220. The files are human readable and system-independent.
  221. </para>
  222. </sect3>
  223. <sect3 id="zend.translate.adapter.qt">
  224. <title>Zend_Translate_Adapter_Qt</title>
  225. <para>
  226. The Qt Adapter is for all customers which have TS files as their
  227. translation source which are made by QtLinguist.
  228. QT is a <acronym>XML</acronym> file based format.
  229. <acronym>XML</acronym> files are human-readable, but the parsing is not as fast
  230. as with gettext files.
  231. </para>
  232. <para>
  233. Several big players have build software upon the QT framework.
  234. The files are human readable and system-independent.
  235. </para>
  236. </sect3>
  237. <sect3 id="zend.translate.adapter.xliff">
  238. <title>Zend_Translate_Adapter_Xliff</title>
  239. <para>
  240. The Xliff Adapter is the Adapter which will be used by most
  241. customers which want to have <acronym>XML</acronym> files but do not have tools
  242. for TMX.
  243. XLIFF is a <acronym>XML</acronym> file based format, which is related to TMX but
  244. simpler as it does not support all possibilities of it.
  245. <acronym>XML</acronym> files are human-readable, but the parsing is not as fast
  246. as with gettext files.
  247. </para>
  248. <para>
  249. Most medium companies use this adapter.
  250. The files are human readable and system-independent.
  251. </para>
  252. </sect3>
  253. <sect3 id="zend.translate.adapter.xmltm">
  254. <title>Zend_Translate_Adapter_XmlTm</title>
  255. <para>
  256. The XmlTm Adapter is the Adapter which will be used by customers
  257. which do their layout themself. XmlTm is a format which allows the
  258. complete html source to be included in the translation source, so
  259. the translation is coupled with the layout.
  260. XLIFF is a <acronym>XML</acronym> file based format, which is related to XLIFF but
  261. its not as simple to read.
  262. </para>
  263. <para>
  264. This adapter should only be used when source files already exist.
  265. The files are human readable and system-independent.
  266. </para>
  267. </sect3>
  268. </sect2>
  269. <sect2 id="zend.translate.adapter.selfwritten">
  270. <title>Integrate self written Adapters</title>
  271. <para>
  272. <classname>Zend_Translate</classname> allows you to integrate and use self written Adapter
  273. classes. They can be used like the standard Adapter classes which
  274. are already included within <classname>Zend_Translate</classname>.
  275. </para>
  276. <para>
  277. Any adapter class you want to use with <classname>Zend_Translate</classname> must be a subclass
  278. of <classname>Zend_Translate_Adapter</classname>. <classname>Zend_Translate_Adapter</classname> is an abstract class
  279. which already defines all what is needed for translation. What has to be
  280. done by you, is the definition of the reader for translation datas.
  281. </para>
  282. <para>
  283. The usage of the prefix "Zend" should be limited to Zend Framework.
  284. If you extend <classname>Zend_Translate</classname> with your own adapter, you should name it
  285. like "Company_Translate_Adapter_MyFormat". The following code shows an
  286. example of how a self written adapter class could be implemented:
  287. </para>
  288. <programlisting language="php"><![CDATA[
  289. try {
  290. $translate = new Zend_Translate('Company_Translate_Adapter_MyFormat',
  291. '/path/to/translate.xx',
  292. 'en',
  293. array('myoption' => 'myvalue'));
  294. } catch (Exception $e) {
  295. // File not found, no adapter class...
  296. // General failure
  297. }
  298. ]]></programlisting>
  299. </sect2>
  300. <sect2 id="zend.translate.adapter.caching">
  301. <title>Speedup all Adapters</title>
  302. <para>
  303. <classname>Zend_Translate</classname> allows you use internally <classname>Zend_Cache</classname> to
  304. fasten the loading of translation sources. This comes very handy if you use many
  305. translation sources or extensive source formats like <acronym>XML</acronym> based files.
  306. </para>
  307. <para>
  308. To use caching you will just have to give a cache object to the
  309. <methodname>Zend_Translate::setCache()</methodname> method. It takes a instance of
  310. <classname>Zend_Cache</classname> as only parameter. Also if you use any adapter direct you
  311. can use the <methodname>setCache()</methodname> method. For convenience there are also the static methods
  312. <methodname>getCache()</methodname>, <methodname>hasCache()</methodname>, <methodname>clearCache()</methodname> and
  313. <methodname>removeCache()</methodname>.
  314. </para>
  315. <programlisting language="php"><![CDATA[
  316. $cache = Zend_Cache::factory('Core',
  317. 'File',
  318. $frontendOptions,
  319. $backendOptions);
  320. Zend_Translate::setCache($cache);
  321. $translate = new Zend_Translate('gettext',
  322. '/path/to/translate.mo',
  323. 'en');
  324. ]]></programlisting>
  325. <note>
  326. <para>
  327. You must set the cache <emphasis>before</emphasis> you use or initiate
  328. any adapter or instance of <classname>Zend_Translate</classname>. Otherwise your translation
  329. source will not be cached until you add a new source with the
  330. <methodname>addTranslation()</methodname> method.
  331. </para>
  332. </note>
  333. </sect2>
  334. </sect1>
  335. <!--
  336. vim:se ts=4 sw=4 et:
  337. -->