#102 gettext plural forms are not supported

open
nobody
None
5
2006-02-19
2004-08-30
No

Some languages can use different syntax with numbers.

For example (sr_YU translation):
1 new message:
Login OK: Inbox sadrzi 1 novu poruku

2 - 4 messages:
Login OK: Inbox sadrzi 2(3,4) nove poruke

5 or more new messages:
Login OK: Inbox sadrzi 5(or more) novih poruka

So it gets different for 1 message, 2-4 messages or
more than 5 messages.

php provides support of gettext plural forms
(http://www.php.net/ngettext) only in php 4.2.0.

I don't want to increase squirrelmail php requirrements
until Debian Stable provides supported php version.

Discussion

  • Danilo Segan

    Danilo Segan - 2004-09-11

    Logged In: YES
    user_id=219596

    FWIW, Serbian uses a bit more complicated rule:
    1, 21, 31, 101 all use one form
    2/3/4, 22/23/24, ... use another form
    and rest of the numbers (5, 7, 11, 12, 13, 14, 15, 27, 37,
    ...) use another form.

    If you're not going to depend on ngettext being available,
    you may want to check if this function is defined. If you
    dislike that, you can emulate ngettext easily:
    1. gettext(""); will return you the PO file header, and you
    need to parse "Plural-Forms: nplurals=...; ..." field.
    2. next, create your own ngettext():
    function my_ngettext($singulartxt, $pluraltxt, $number) {
    $str = gettext($singulartxt . chr(0) . $pluraltxt);
    $translations = split(chr(0), $str);
    // now, based on plural-forms field, select one of the
    translations
    return $translations[get_my_plural_form($number)];
    }
    3. mark all the relevant messages with my_ngettext, eg.:
    $msgstr = my_ngettext("%d new message", "%d new messages",
    $msgcount);
    4. Finally, you'd only need to pass
    --keyword=my_ngettext:1,2 to xgettext.

    The trick is that plural forms in gettext are simply
    messages concatenated into one with NULL separating them
    (that's possible because MO file format uses offsets and
    lengths for locating messages, not null-terminated strings).
    I'm not sure though if gettext() function would let it pass
    through.

    If not, you may want to take a look at my php-gettext which
    emulates most of the gettext library (it's hosted on
    savannah.nongnu.org).

     
  • Tomas Kuliavas

    Tomas Kuliavas - 2004-09-19

    Logged In: YES
    user_id=225877

    php-gettext classes are a little bit slower (20%-50%) than
    current squirrelmail implementation. I suspect, that
    translation caching in session improves speed of our functions.

    Also php-gettext classes have to be rechecked, because some
    tests are not sufficient and cause php E_ALL errors.

    I think I'll talk to others about adding them. If people
    agree to add libraries that are slower in unoptimized
    squirrelmail version, we will use php-gettext classes.

     
  • Tomas Kuliavas

    Tomas Kuliavas - 2004-10-04

    Logged In: YES
    user_id=225877

    from 1.5.1cvs (function/i18n.php v.1.190) squirrelmail uses
    modified php-gettext classes, if php does not have gettext
    support or ngettext support is not present in php gettext
    module.

    Patches and some comments are posted on savannah.

     
  • Tomas Kuliavas

    Tomas Kuliavas - 2004-11-15
    • labels: 382878 -->
    • milestone: 102172 -->
     
  • Tomas Kuliavas

    Tomas Kuliavas - 2006-02-19
    • assigned_to: tokul --> nobody
     
  • Danilo Segan

    Danilo Segan - 2006-02-20

    Logged In: YES
    user_id=219596

    Latest PHP-gettext provides detection if both gettext() and
    required locale is present: you just need to make use of
    gettext.inc and T_* family of functions (i.e. it might be
    possible that gettext() is compiled in, but setlocale()
    can't set the locale which doesn't exist, so it switches to
    emulation in that case as well).

    Just so you don't have to reimplement everything. :)

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks