Zend_Translate-Adapters.xml 19 KB

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