Zend_Translate-Plurals.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.translate.plurals">
  4. <title>Plural notations for Translation</title>
  5. <para>
  6. As of Zend Framework 1.9, <classname>Zend_Translate</classname> is able to provide plural
  7. support. Professional translation will always have the need to use plurals as they are
  8. native in almost all languages.
  9. </para>
  10. <para>
  11. So what are plurals? Generally spoken plurals are words which take into account numeric
  12. meanings. But as you may imaging each language has it's own definition of plurals.
  13. English, for example, supports one plural. We have a singular definition, for example
  14. "car", which means implicit one car, and we have the plural definition, "cars" which could
  15. mean more than one car but also zero cars. Other languages like russian or polish have
  16. more plurals and also the rules for plurals are different.
  17. </para>
  18. <para>
  19. When you want to use plurals with <classname>Zend_Translate</classname> you must not need
  20. to know how the plurals are defined, only the translator must know as he does the
  21. translation. The only information you need to have is the language.
  22. </para>
  23. <para>
  24. There are two way for using plurals... the traditional one, which means that you use a own
  25. method, and a modern one, which allows you to do plural translations with the same method
  26. as normal translations.
  27. </para>
  28. <sect2 id="zend.translate.plurals.traditional">
  29. <title>Traditional plural translations</title>
  30. <para>
  31. People who worked with gettext in past will be more common with traditional plural
  32. translations. There is a own <methodname>plural()</methodname> method which can be
  33. used for plural translations.
  34. </para>
  35. <example id="zend.translate.plurals.traditional.example1">
  36. <title>Example of traditional plural translations</title>
  37. <para>
  38. The <methodname>plural()</methodname> method accepts 4 parameters. The first
  39. parameter is the singular messageId, the second is the plural messageId and the
  40. third is the number or amount.
  41. </para>
  42. <para>
  43. The number will be used to detect the plural which has to be returned. A optional
  44. forth parameter can be used to give a locale which will be used to return the
  45. translation.
  46. </para>
  47. <programlisting language="php"><![CDATA[
  48. $translate = new Zend_Translate('gettext', '/path/to/german.mo', 'de');
  49. $translate->plural('Car', 'Cars', $number);
  50. ]]></programlisting>
  51. </example>
  52. </sect2>
  53. <sect2 id="zend.translate.plurals.modern">
  54. <title>Modern plural translations</title>
  55. <para>
  56. As traditional plural translations are restricted to source code using english plurals
  57. we added a new way for plural translations. It allows to use the same
  58. <methodname>translate()</methodname> for standard and for plural translations.
  59. </para>
  60. <para>
  61. To use plural translations with <methodname>translate()</methodname> you need to give
  62. an array as messageId instead of an string. This array must have the original plural
  63. messageId's, then the amount and at last an optional locale when your given messageId's
  64. are not in english notation.
  65. </para>
  66. <example id="zend.translate.plurals.modern.example1">
  67. <title>Example of modern plural translations</title>
  68. <para>
  69. When we want to translate the same plural definitions like in the previous our
  70. example would have to be defined like below.
  71. </para>
  72. <programlisting language="php"><![CDATA[
  73. $translate = new Zend_Translate('gettext', '/path/to/german.mo', 'de');
  74. $translate->translate(array('Car', 'Cars', $number));
  75. ]]></programlisting>
  76. </example>
  77. <para>
  78. Using modern plural translations it is also possible to use any language as source
  79. for messageId's.
  80. </para>
  81. <example id="zend.translate.plurals.modern.example2">
  82. <title>Example of modern plural translations using a different source language</title>
  83. <para>
  84. Let's expect we want to use russian and let's also expect that the given
  85. messageId's are russian and not english.
  86. </para>
  87. <programlisting language="php"><![CDATA[
  88. $translate = new Zend_Translate('gettext', '/path/to/german.mo', 'de');
  89. $translate->translate(array('Car',
  90. 'Cars first plural',
  91. 'Cars second plural',
  92. $number,
  93. 'ru'));
  94. ]]></programlisting>
  95. </example>
  96. <para>
  97. As you can see you can give more than just the one english plural. But you must give
  98. the source language in this case so <classname>Zend_Translate</classname> knows which
  99. plural rules it has to apply.
  100. </para>
  101. <para>
  102. When you omit the plural language then english will be used per default and any
  103. additional plural definition will be ignored.
  104. </para>
  105. </sect2>
  106. <sect2 id="zend.translate.plurals.source">
  107. <title>Plural source files</title>
  108. <para>
  109. Not all source formats support plural forms. Look into this list for details:
  110. </para>
  111. <table id="zend.translate.plurals.source.supportedadapters">
  112. <title>Plural support</title>
  113. <tgroup cols="4">
  114. <thead>
  115. <row>
  116. <entry>Adapter</entry>
  117. <entry>Plurals supported</entry>
  118. </row>
  119. </thead>
  120. <tbody>
  121. <row>
  122. <entry>Array</entry>
  123. <entry><emphasis>yes</emphasis></entry>
  124. </row>
  125. <row>
  126. <entry>Csv</entry>
  127. <entry><emphasis>yes</emphasis></entry>
  128. </row>
  129. <row>
  130. <entry>Gettext</entry>
  131. <entry><emphasis>yes</emphasis></entry>
  132. </row>
  133. <row>
  134. <entry>Ini</entry>
  135. <entry><emphasis>no</emphasis></entry>
  136. </row>
  137. <row>
  138. <entry>Qt</entry>
  139. <entry><emphasis>no</emphasis></entry>
  140. </row>
  141. <row>
  142. <entry>Tbx</entry>
  143. <entry><emphasis>no</emphasis></entry>
  144. </row>
  145. <row>
  146. <entry>Tmx</entry>
  147. <entry><emphasis>no</emphasis></entry>
  148. </row>
  149. <row>
  150. <entry>Xliff</entry>
  151. <entry><emphasis>no</emphasis></entry>
  152. </row>
  153. <row>
  154. <entry>XmlTm</entry>
  155. <entry><emphasis>no</emphasis></entry>
  156. </row>
  157. </tbody>
  158. </tgroup>
  159. </table>
  160. <para>
  161. Below you can find examples of plural defined source files.
  162. </para>
  163. <sect3 id="zend.translate.plurals.source.array">
  164. <title>Array source with plural definitions</title>
  165. <para>
  166. An array with plural definitions has to look like the following example.
  167. </para>
  168. <programlisting language="php"><![CDATA[
  169. array(
  170. 'plural_0' => array(
  171. 'plural_0 (ru)',
  172. 'plural_1 (ru)',
  173. 'plural_2 (ru)',
  174. 'plural_3 (ru)'
  175. ),
  176. 'plural_1' => ''
  177. );
  178. ]]></programlisting>
  179. <para>
  180. In the above example <code>plural_0</code> and <code>plural_1</code> are the
  181. plural definitions from the source code. And the array at <code>plural_0</code>
  182. has all translated plural forms available. Take a look at the following example
  183. with real content and translation from english source to german.
  184. </para>
  185. <programlisting language="php"><![CDATA[
  186. array(
  187. 'Car' => array(
  188. 'Auto',
  189. 'Autos'
  190. ),
  191. 'Cars' => ''
  192. );
  193. ]]></programlisting>
  194. <para>
  195. When your translated language supports more plural forms then simply add them to
  196. the array below the first plural form. When your source language suppors more
  197. plural forms, than simply add a new empty translation.
  198. </para>
  199. </sect3>
  200. <sect3 id="zend.translate.plurals.source.csv">
  201. <title>Csv source with plural definitions</title>
  202. <para>
  203. A csv file with plural definitions has to look like the following example.
  204. </para>
  205. <programlisting language="php"><![CDATA[
  206. "plural_0";"plural_0 (ru)";"plural_1 (ru)";"plural_2 (ru)";"plural_3 (ru)"
  207. "plural_1";
  208. ]]></programlisting>
  209. <para>
  210. All translated plural forms have to be added after the first plural of the source
  211. language. And all further plural forms of the source language have to be added
  212. below but without translation. Note that you must add a delimiter to empty
  213. source plurals.
  214. </para>
  215. </sect3>
  216. <sect3 id="zend.translate.plurals.source.gettext">
  217. <title>Gettext source with plural definitions</title>
  218. <para>
  219. Gettext sources support plural forms out of the box. There is no need for adoption
  220. as the <filename>*.mo</filename> file will contain all necessary data.
  221. </para>
  222. <note>
  223. <para>
  224. Note that gettext does not support the usage of source languages which are not
  225. using english plural forms. When you plan to use a source language which
  226. supports other plural forms like russian for example, then you can not use
  227. gettext sources.
  228. </para>
  229. </note>
  230. </sect3>
  231. </sect2>
  232. </sect1>
  233. <!--
  234. vim:se ts=4 sw=4 et:
  235. -->