[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gallery-devel
Subject:    Re: [Gallery-devel] ngettext
From:       Bharat Mediratta <bharat () menalto ! com>
Date:       2004-04-21 10:10:41
Message-ID: BCAB96B1.1A57B%bharat () menalto ! com
[Download RAW message or body]

On 4/21/04 2:28 AM, "Bharat Mediratta" <bharat@menalto.com> wrote:
> To say:   "I have apples"
> We write: gettext("I have apples")
> 
> To say:   "I have 0 apples", "I have 1 apple" and "I have 7 apples"
>         (where the number varies and is in the variable $count)
> We write:  ngettext(array("one" => "I have %d apple",
>                         "many" => "I have %d apples",
>                         count => $count,
>                         arg1 => $count));

I shouldn't have used gettext() and ngettext() directly in my examples
above.  Let me restate the second example:

To say:   "I have 0 apples", "I have 1 apple" and "I have 7 apples"
          (where the number varies and is in the variable $count)
We write:  my_ngettext(array("one" => "I have %d apple",
                             "many" => "I have %d apples",
                             count => $count,
                             arg1 => $count));


Then the my_ngettext function looks like this:

function my_ngettext($params) {
    // Have ngettext() give us the localized value
    $localized = ngettext($data['one'], $data['many'], $data['count']);

    // $localized is now "I have %d apples" if count == 7
    return sprintf($localized, $params['arg1']);
}

In G2, our my_ngettext function is a lot more complicated since we have
multiple translation domains, etc, etc.

-Bharat



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
__[ g a l l e r y - d e v e l ]_________________________

[ list info/archive --> http://gallery.sf.net/lists.php ]
[ gallery info/FAQ/download --> http://gallery.sf.net ]
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic