[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ngettext usability issue - how to fix?
From: |
Eddy Petrișor |
Subject: |
Re: ngettext usability issue - how to fix? |
Date: |
Sat, 02 Jun 2007 13:18:12 +0300 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.0.10) Gecko/20070328 Thunderbird/1.5.0.10 Mnenhy/0.7.5.0 |
Bruno Haible wrote:
> 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)
>
> ...
So having a function WeaponWin(char *team, int wonitemscount) and having this
instead:
..txt <<
WeaponsList::GetInstance()->PrintGetWeapon(contents)->WeaponWin(equipe.GetName().c_str(),
nbr_ammo)...
char *Helmet::WeaponWin(char *teamname, int wonitemscount)
{
return Format( ngettext("%s team has won %d helmet!",
"%s team has won %d helmets!",
nbr_ammo), teamname, wonitemscount);
}
char *NinjaRope::WeaponWin(char *teamname, int wonitemscount)
{
return Format( ngettext("%s team has won %d ninja rope!",
"%s team has won %d ninja ropes!",
nbr_ammo), teamname, wonitemscount);
}
.. (or something of this sort) would be ok?
> 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.
I agree, I wasn't sure which would have been the right approach...
--
Regards,
EddyP
=============================================
"Imagination is more important than knowledge" A.Einstein
signature.asc
Description: OpenPGP digital signature