Allow correct translation of plurals

Bug #901051 reported by Richard Mansfield on 2011-12-07
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Medium
Richard Mansfield

Bug Description

With the current language pack format, it's impossible to translate many plurals correctly unless the language uses the same rules as English. We need to let translations specify plurals via a function over the number, as described in http://www.gnu.org/s/hello/manual/gettext/Plural-forms.html

The following emails have more detail about how we propose to fix this in Mahara:

---------------------------- Original Message ----------------------------
Subject: Re: Using PluralForms in Mahara strings + DWOO problem/question
From: "Richard Mansfield"
Date: Tue, September 13, 2011 12:16 pm
To: Gregor Anzelj, Francois Marier
--------------------------------------------------------------------------

Thanks very much for this Gregor, I've now had time to have a good look
at those links you sent, and done a bit of playing around on Mahara.

I'd like to propose that we change Mahara along the lines of this commit:

https://github.com/richardmansfield/richardms-mahara/commit/157c384b2860553ab78fad88f7a32b30d4af0ec2

And the following commit shows how the strings would look in the default
langpack:

https://github.com/richardmansfield/richardms-mahara/commit/b0aba7671669ab996008a0c65cc11538dc529bda

It's all pretty much the same as your scheme, but just closer to the
gettext/PO format, using a php array to store the different plural forms
rather than special codes inside the string. So to use your example,
this string:

$string['notsosimpleplural'] = "%d
{{PLURAL:%d|sporocilo|sporocili|sporocila|sporocil}}";

would be specified like this in the php langpack:

$string['notsosimpleplural'] = array(
    '%d sporocilo',
    '%d sporocili',
    '%d sporocila',
    '%d sporocil',
);

and like this in our PO files:

#: lang/en.utf8/mahara.php notsosimpleplural
msgctxt "lang/en.utf8/mahara.php notsosimpleplural"
msgid "%d message"
msgid_plural "%d messages"
msgstr[0] "%d sporocilo"
msgstr[1] "%d sporocili"
msgstr[2] "%d sporocila"
msgstr[3] "%d sporocil"

Keeping our scheme similar to PO & gettext has the advantage that it'll
make the conversion of langpacks to/from PO a lot easier, and the other
advantage is that we won't need to rely on special characters like { and
| inside the translated strings themselves (these characters could
legitimately appear in strings too, and one day that might require us to
dream up some escaping rules).

The disadvantage I see, compared to your scheme, is that we're removing
the option to put multiple plural forms anywhere inside a string. For
example in the second patch above, I had to split a string up, because
"Created %s folders and %s files" contains two plurals. However, I
don't think PO can deal with that nicely (correct me if I'm wrong on
that). If we're expecting people to translate Mahara using standard PO
editing tools and Launchpad, I don't see that we've got much choice but
to limit ourselves to one plural per string.

What do you guys think?

On 29/08/11 19:49, Gregor Anzelj wrote:
> > Regarding plural forms and gettext/ .po files...
> >
> > I think these pages contain all the info needed:
> >
> > * http://www.gnu.org/s/hello/manual/gettext/Plural-forms.html
> > *
http://www.gnu.org/s/hello/manual/gettext/Translating-plural-forms.html#Translating-plural-forms
> >
> > But I think we need to be careful to cover all possible cases:
> >
> > * simple one, e.g.: $string['simpleplural'] =
> > "{{PLURAL:%d|view|views}}"; as well as
> > * not so simple one, e.g.: $string['notsosimpleplural'] = "%d
> > {{PLURAL:%d|message|messages}}";
> >
> > or in Slovenian:
> >
> > * simple one, e.g.: $string['simpleplural'] =
> > "{{PLURAL:%d|pogled|pogleda|pogledi|pogledov}}"; as well as
> > * not so simple one, e.g.: $string['notsosimpleplural'] = "%d
> > {{PLURAL:%d|sporocilo|sporocili|sporocila|sporocil}}";
> >
> > HTH,
> > Gregor
> > --
> > ----------
> > Gregor Anzelj, prof.
> > Gimnazija Ledina, Ljubljana

tags: added: translations
François Marier (fmarier) wrote :
Changed in mahara:
status: Confirmed → In Progress

Reviewed: https://reviews.mahara.org/923
Committed: http://gitorious.org/mahara/mahara/commit/526e469835876d958e1f1f1dcf5dad680168ffec
Submitter: Richard Mansfield (<email address hidden>)
Branch: master

commit 526e469835876d958e1f1f1dcf5dad680168ffec
Author: Richard Mansfield <email address hidden>
Date: Tue Sep 13 10:32:37 2011 +1200

    Use the plural form translations for selected strings (bug #901051)

    Minor changes to several strings in the default language pack to use
    plural forms. This commit is intended as an example to demonstrate
    the use of plural forms.

    Change-Id: I425fbdaa10496c747b415e07e18aeb23736967b8
    Signed-off-by: Richard Mansfield <email address hidden>

Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/922
Committed: http://gitorious.org/mahara/mahara/commit/52a6e7e19632665fe037b0a44134045773e5bb78
Submitter: Richard Mansfield (<email address hidden>)
Branch: master

commit 52a6e7e19632665fe037b0a44134045773e5bb78
Author: Richard Mansfield <email address hidden>
Date: Tue Sep 13 10:25:57 2011 +1200

    Modify get_string to take plural forms (bug #901051)

    Allows language packs to specify an array of strings (one for each
    plural form in the language) instead of a single string.

    The first of the variable (sprintf) arguments is assumed to be the
    number we need to check to choose a plural form. This argument is
    passed into a language-specific function defined in langconfig.php,
    which returns the appropriate plural form based on a formula.

    A similar scheme is used for strings formatted by the javascript
    get_string function in mahara.js.

    See http://www.gnu.org/s/hello/manual/gettext/Plural-forms.html

    Change-Id: Ifb58ac4f1e13a54edbc57e5c0a9faaf8454e53a4
    Signed-off-by: Richard Mansfield <email address hidden>

Changed in mahara:
status: In Progress → Fix Committed
Melissa Draper (melissa) on 2012-04-18
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers