bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ngettext usability issue - how to fix?


From: Bruno Haible
Subject: Re: ngettext usability issue - how to fix?
Date: Sat, 2 Jun 2007 01:52:37 +0200
User-agent: KMail/1.5.4

Hello,

I'm CCing the bug-gnu-gettext list, so that others can learn from your
question as well.

Eddy Petrișor wrote:
> I found at some point this bit of code:
> 
>         txt << Format(ngettext(
>                 "%s team has won %u %s!",
>                 "%s team has won %u %ss!",
>                 nbr_ammo),
>             equipe.GetName().c_str(), nbr_ammo, 
> WeaponsList::GetInstance()->GetWeapon(contents)->GetName().c_str());
> 
> 
> Of course, this is broken, ...

Yes, this is broken. This code assumes that the plural form can be made the
same way for all nouns, but this is not true for many languages. Take for
example German:
   Rüstung - Rüstungen              - suffix "en"
   Schwert - Schwerter              - suffix "er"
   Helm - Helme                     - suffix "e"
   Messer - Messer                  - no suffix
   Sense - Sensen                   - suffix "n"
   Gans - Gänse                     - suffix and vowel change

> The way I was thinking to fix this was to split the string in two
> ""%s team has won" and "%u %s!" with the last part
> somehow specified as a ngettext call

No, this is not a solution. Please see the GNU gettext manual, section
"Preparing Translatable Strings". The second-most important recommendation
is: Entire sentences!

The solution is to have xgettext see an ngettext call for each possible value
of the weapon noun:

   ngettext("%s team has won %u sword!",
            "%s team has won %u swords!",
            nbr_ammo)

   ...

   
   ngettext("%s team has won %u helmet!",
            "%s team has won %u helmets!",
            nbr_ammo)

   ...

Where to put these in the source code (into a single file, or spread, one
in each weapon class) is best decided by the programmer familiar with the
source code.

> I was thinking that I could use something in the syle of N_() alias

The only effect of doing this is to save a few bytes of executable code
in the final program. It's more important to get the code working right in
the first place.

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]