Skip to content

[Translation] Make plural translations more standard #10152

Closed
@goetas

Description

@goetas

Hi everybody.

I'm developing a multilingual site. We are using pootle (http://pootle.translatehouse.org/) to provide a web interface to translators.

Pootle and many other tools use a different convention than symfony to define translation strings.

Gettext PO file using plural forms can be something like:

msgid untranslated-string-singular
msgid_plural untranslated-string-plural
msgstr[0] translated-string-case-0
...
msgstr[N] translated-string-case-n

XLIFF file using plural forms can be something like:

<group restype="x-gettext-plurals" id="untranslated-string-singular">
    <trans-unit id="untranslated-string-singular[0]">
      <source>untranslated-string-singular</source>
      <target>translated-string-case-0</target>
    </trans-unit>
    <trans-unit id="untranslated-string-singular[N]">
      <source>untranslated-string-singular</source>
      <target state="translated">translated-string-case-n</target>
    </trans-unit>
</group>

While using symfony conventions:

$translatos->transChoice(
  "{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples", 
$number);

we have always one rappresentation:
Gettext:

msgid "{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples"
msgstr "{0} Translated...|{1} Translated...|]1,Inf] Translated..."

XLIFF

<trans-unit id="untranslated-string-singular[0]">
  <source>{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples</source>
  <target>{0} Translated...|{1} Translated...|]1,Inf] Translated...</target>
</trans-unit>

Using symfony plurals, tools like http://virtaal.translatehouse.org/ or http://pootle.locamotion.org/ can't detect plural forms and can't present those sentences in a good way.

For example: http://pootle.locamotion.org/fr/pootle/translate/pootle.po#search=Please%20correct%20&sfields=source,target&unit=182009
Here pootle automatically splits the translation into many textarea based on the number of French plurals (Polish has three plural forms).
This approach avoids translators' mistakes, and does not relay on translators' ability to manipulate plural expressions (1]10] | ]10],inf[).

I'm going to make some changes to transChoice implementations.
I suggest to pass an array as first parameter (instead of a string). Example:

$translator->transChoice(array("There is one apple", "There are %count% apples"),
    10, array('%count%' => 10)
);

Also twig templates can take advantage from this change.

Since I'm thinking to use arrays, this change would be BC compatible.

Involved parts should be also:

  • MessageCatalogue: messages can be an array... (this can be difficult)
  • LoaderInterface: have to read correctly msgstr[N] or <group restype="x-gettext-plurals"> expressions.. and save data into MessageCatalogue
  • DumperInterface: have to read MessageCatalogue, and arrays should be saved correctly

May this change be accepted?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions