| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.translate.plurals">
- <title>Plural notations for Translation</title>
- <para>
- As of Zend Framework 1.9, <classname>Zend_Translate</classname> is able to provide plural
- support. Professional translation will always have the need to use plurals as they are
- native in almost all languages.
- </para>
- <para>
- So what are plurals? Generally spoken plurals are words which take into account numeric
- meanings. But as you may imaging each language has it's own definition of plurals.
- English, for example, supports one plural. We have a singular definition, for example
- "car", which means implicit one car, and we have the plural definition, "cars" which could
- mean more than one car but also zero cars. Other languages like russian or polish have
- more plurals and also the rules for plurals are different.
- </para>
- <para>
- When you want to use plurals with <classname>Zend_Translate</classname> you must not need
- to know how the plurals are defined, only the translator must know as he does the
- translation. The only information you need to have is the language.
- </para>
- <para>
- There are two way for using plurals... the traditional one, which means that you use a own
- method, and a modern one, which allows you to do plural translations with the same method
- as normal translations.
- </para>
- <sect2 id="zend.translate.plurals.traditional">
- <title>Traditional plural translations</title>
- <para>
- People who worked with gettext in past will be more common with traditional plural
- translations. There is a own <methodname>plural()</methodname> method which can be
- used for plural translations.
- </para>
- <example id="zend.translate.plurals.traditional.example1">
- <title>Example of traditional plural translations</title>
- <para>
- The <methodname>plural()</methodname> method accepts 4 parameters. The first
- parameter is the singular messageId, the second is the plural messageId and the
- third is the number or amount.
- </para>
- <para>
- The number will be used to detect the plural which has to be returned. A optional
- forth parameter can be used to give a locale which will be used to return the
- translation.
- </para>
- <programlisting language="php"><![CDATA[
- $translate = new Zend_Translate('gettext', '/path/to/german.mo', 'de');
- $translate->plural('Car', 'Cars', $number);
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.translate.plurals.modern">
- <title>Modern plural translations</title>
- <para>
- As traditional plural translations are restricted to source code using english plurals
- we added a new way for plural translations. It allows to use the same
- <methodname>translate()</methodname> for standard and for plural translations.
- </para>
- <para>
- To use plural translations with <methodname>translate()</methodname> you need to give
- an array as messageId instead of an string. This array must have the original plural
- messageId's, then the amount and at last an optional locale when your given messageId's
- are not in english notation.
- </para>
- <example id="zend.translate.plurals.modern.example1">
- <title>Example of modern plural translations</title>
- <para>
- When we want to translate the same plural definitions like in the previous our
- example would have to be defined like below.
- </para>
- <programlisting language="php"><![CDATA[
- $translate = new Zend_Translate('gettext', '/path/to/german.mo', 'de');
- $translate->translate(array('Car', 'Cars', $number));
- ]]></programlisting>
- </example>
- <para>
- Using modern plural translations it is also possible to use any language as source
- for messageId's.
- </para>
- <example id="zend.translate.plurals.modern.example2">
- <title>Example of modern plural translations using a different source language</title>
- <para>
- Let's expect we want to use russian and let's also expect that the given
- messageId's are russian and not english.
- </para>
- <programlisting language="php"><![CDATA[
- $translate = new Zend_Translate('gettext', '/path/to/german.mo', 'de');
- $translate->translate(array('Car',
- 'Cars first plural',
- 'Cars second plural',
- $number,
- 'ru'));
- ]]></programlisting>
- </example>
- <para>
- As you can see you can give more than just the one english plural. But you must give
- the source language in this case so <classname>Zend_Translate</classname> knows which
- plural rules it has to apply.
- </para>
- <para>
- When you omit the plural language then english will be used per default and any
- additional plural definition will be ignored.
- </para>
- </sect2>
- <sect2 id="zend.translate.plurals.source">
- <title>Plural source files</title>
- <para>
- Not all source formats support plural forms. Look into this list for details:
- </para>
- <table id="zend.translate.plurals.source.supportedadapters">
- <title>Plural support</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Adapter</entry>
- <entry>Plurals supported</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Array</entry>
- <entry><emphasis>yes</emphasis></entry>
- </row>
- <row>
- <entry>Csv</entry>
- <entry><emphasis>yes</emphasis></entry>
- </row>
- <row>
- <entry>Gettext</entry>
- <entry><emphasis>yes</emphasis></entry>
- </row>
- <row>
- <entry>Ini</entry>
- <entry><emphasis>no</emphasis></entry>
- </row>
- <row>
- <entry>Qt</entry>
- <entry><emphasis>no</emphasis></entry>
- </row>
- <row>
- <entry>Tbx</entry>
- <entry><emphasis>no</emphasis></entry>
- </row>
- <row>
- <entry>Tmx</entry>
- <entry><emphasis>no</emphasis></entry>
- </row>
- <row>
- <entry>Xliff</entry>
- <entry><emphasis>no</emphasis></entry>
- </row>
- <row>
- <entry>XmlTm</entry>
- <entry><emphasis>no</emphasis></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- Below you can find examples of plural defined source files.
- </para>
- <sect3 id="zend.translate.plurals.source.array">
- <title>Array source with plural definitions</title>
- <para>
- An array with plural definitions has to look like the following example.
- </para>
- <programlisting language="php"><![CDATA[
- array(
- 'plural_0' => array(
- 'plural_0 (ru)',
- 'plural_1 (ru)',
- 'plural_2 (ru)',
- 'plural_3 (ru)'
- ),
- 'plural_1' => ''
- );
- ]]></programlisting>
- <para>
- In the above example <code>plural_0</code> and <code>plural_1</code> are the
- plural definitions from the source code. And the array at <code>plural_0</code>
- has all translated plural forms available. Take a look at the following example
- with real content and translation from english source to german.
- </para>
- <programlisting language="php"><![CDATA[
- array(
- 'Car' => array(
- 'Auto',
- 'Autos'
- ),
- 'Cars' => ''
- );
- ]]></programlisting>
- <para>
- When your translated language supports more plural forms then simply add them to
- the array below the first plural form. When your source language suppors more
- plural forms, than simply add a new empty translation.
- </para>
- </sect3>
- <sect3 id="zend.translate.plurals.source.csv">
- <title>Csv source with plural definitions</title>
- <para>
- A csv file with plural definitions has to look like the following example.
- </para>
- <programlisting language="php"><![CDATA[
- "plural_0";"plural_0 (ru)";"plural_1 (ru)";"plural_2 (ru)";"plural_3 (ru)"
- "plural_1";
- ]]></programlisting>
- <para>
- All translated plural forms have to be added after the first plural of the source
- language. And all further plural forms of the source language have to be added
- below but without translation. Note that you must add a delimiter to empty
- source plurals.
- </para>
- </sect3>
- <sect3 id="zend.translate.plurals.source.gettext">
- <title>Gettext source with plural definitions</title>
- <para>
- Gettext sources support plural forms out of the box. There is no need for adoption
- as the <filename>*.mo</filename> file will contain all necessary data.
- </para>
- <note>
- <para>
- Note that gettext does not support the usage of source languages which are not
- using english plural forms. When you plan to use a source language which
- supports other plural forms like russian for example, then you can not use
- gettext sources.
- </para>
- </note>
- </sect3>
- </sect2>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|