GNOME Bugzilla – Bug 106703
Please use ngettext for handling plurals in nautilus-media
Last modified: 2004-12-22 21:47:04 UTC
#: audio-properties-view/audio-properties-view.c:241 #, c-format msgid "%d channels" #: audio-properties-view/audio-properties-view.c:256 #, c-format msgid "%d minutes %02d.%03d seconds" As mentioned in http://developer.gnome.org/doc/tutorials/gnome-i18n/developer.html#plurals, this way of handling plurals is broken for many locales. A way to solve this is by using ngettext instead as mentioned in that document. A simple code example of code using ngettext: g_printf (ngettext ("Found %d file.", "Found %d files.", nbr_of_files), nbr_of_files);
Can you explain to me how this would work in the specific case above, where I have both minutes and seconds, with seconds having three decimals ? I'm having a hard time figuring out what it would end up as.
Please note that the use of ngettext in GNOME core components is for now to be avoided due to portability reasons, as per discussion on the desktop-devel mailing list (http://mail.gnome.org/archives/desktop-devel-list/2003-February/msg00886.html).
dsegan@gmx.net, perhaps you could help providing a patch?
I can provide a patch that would work for some languages, but I think there's no an easy way out. According to http://mathforum.org/library/drmath/view/57224.html (and the pages it references), in English one may use both: -- 0.543 seconds -- 0.543 second but, one should use -- 1.000 second and not 1.000 seconds (I guess) -- 1.543 seconds (and not 1.543 second) In other languages (for instance Serbian), one ought to use something along the lines of (note the use of *msec* for choosing the plural form): -- g_strdup_printf(ngettext("%02d.%03d seconds","%02d.%03d seconds",msec),sec,msec) While perhaps in others (maybe French?) one might use: -- g_strdup_printf(ngettext("%02d.%03d seconds","%02d.%03d seconds",sec),sec,msec) One can implement both of these with some sort of context marker (where just one will need to be translated), but I am not sure for how many languages this would work (it wouldn't work for English case of 1.000, if my interpretation is correct). Perhaps in some languages it would work to have function fgettext that would work with floats instead of integers (according to http://webster.commnet.edu/grammar/numbers.htm this might be case in English)? Finally, there's another option to write it like: "%d seconds, %d milliseconds" because I cannot seem to find any pattern in how different languages treat plurality of fractional numbers. Of course, we might at least go for simple "fix" (I'll attach a patch). I just used the "sec" for matching plurals instead of "msec" which would work for Serbian. Before applying this patch (at least the second part: the first part concerning "%d channels" and even "%d minutes" is not troublesome), I think we should raise this issue at the gnome-i18n list. Hope this can help at least a bit.
Created attachment 18171 [details] [review] Makes use of ngettext() calls where appropriate; incorrect for fractions
checked the patch, it is wrong. Among other things, g_strconcat needs to be NULL terminated, which leads me to believe this patch didn't get tested properly. Can you redo it and test to make sure it works ? Also, if seconds are fractional, I don't see any value into pluralize-checking it. Also, if we already cover channels == 1 and 2, do we need to check for singular/plural still ?
Sorry about that (the patch was *not* tested; actually, it was tested to compile and install, but I don't remember if I run it). Though, ngettext should return a NULL terminated string, so there should be no problem at that point (perhaps I'm wrong). On the issue of pluralizing fractions, I've mentioned above that there's no a true "solution", because it depends on the language how the fractional number should be pluralized. I'd go for just pluralizing the "%d minutes" part. As for the number of channels different than 1 or 2, it would still be required. Eg. a Serbian language (and many other Slavic languages) uses the same form for "1", "21", "231" ("1 kanal", "21 kanal"... versus "4 kanala", "22 kanala"). Also, quite a few languages have *different* forms based on the *last* digit (eg. if it's 2, 3, 4), and sometimes, it depends on other things. Please see a gettext info manual where many examples are given. In short, yes, it's neccessary to use plural forms. I'll update a patch with the one which doesn't use strconcat, because that's not a good solution (rules for fractional numbers differ among languages, and they cannot be expressed with ngettext handling), so it's as good as not having seconds pluralized. (I'll test the patch this time before sending it, but I need to update my gstreamer first).
And I must also add that strconcat-ing is a bad solution in terms of software localization, and one of its basic rules: don't break strings, and don't compose them from parts if you can avoid it. In the solution I proposed earlier, this would break it for languages that eg. write seconds before minutes, because they wouldn't be able to revert the order.
ok, I follow for the "everything ending in 1 might be plural" part, so let's keep that. About g_strconcat; what I meant is, the last ARGUMENT in the argument list needs to be NULL, not just all of the strings' termination before it.
Urgh, I had to patch nautilus-media to be able to compile it with GCC 2.95.3 (I'll make a separate bug report about that, if you wish -- it's just a simple declaration-n-assignment-in-the-middle-of-the-block-in-c99-style-which-gcc295-doesn't-support stuff in media-info/media-info.c (gst_media_info_read_idler), concerning "priv" variable). Unfortunately, I cannot test this because I don't have all the needed libraries (it shows just "Unknown" for the length of the MP3, I'm probably lacking some id3 library). I'll attach a patch because it's now much simpler, and I really believe it should work without problems.
Created attachment 19159 [details] [review] Make audio-properties-view use ngettext where possible and sane
Any news on this?
Patch looks good code-wise - but I think you should ngettext minutes and seconds individually and then concat those strings in variable order (/* comment telling translators what to do to swap min/sec */\n_("%$1s %$2s")). regs Chris
Could we have this revisited RSN before freezes apply?
I have no clue on what Christian is saying on Danilo, could someone please decide this for me and tell me if the patch should go in as is, or needs a change ?
Created attachment 23225 [details] [review] Another proposed patch based on Danilo's work. Should work fine. Untested (I haven't got gst 0.7 installed).
Now, after submitting the patch I came to the conclusion that the patch isn't completely fine: "_("%$1s %$2s")," should probably NOT be ngettextized. Instead, it should simply be hardcoded ("%s %s"), since it would probably raise swapping issues, because minutes/seconds/mseconds could be inserted in the wrong place. regs, Chris
Created attachment 23226 [details] [review] New patch, hardcoded order. Onliest advantage over Danilo's solution: min/secs are ngettextized independently. Untested again.
Manny, You could do it better if you introduce a new variable (just like you did in other ngettext patches), something along the following: string1 = ngettext("%d minute", "%d minutes", mins); /* translators: change order if decimal part comes before integral part */ string2 = ngettext("%d.%d seconds", "%d.%d seconds", msec); /* translators: change order if seconds come before minutes */ c_string = g_strdup_printf(_("%s %s"), string1, string2); (I don't want to send out another patch, or Thomas will become very confused, and discouraged ;).
Created attachment 23295 [details] [review] Use ngettext in nautilus-media (compiles fine; improves on Manny's patch)
Looks nice. regs, Chris
String freeze time is fast approaching (February 9th), and this is one of the rare outstanding ngettext related bugs for Gnome 2.6. Could we have this revisited ASAP?
forgot to close this when commiting. will be in 0.5.3 release today.
Thanks Thomas. I suggest you also notify gnome-i18n of the change, because this still constitutes a string freeze break, and translators will want to know that they need to update their translations. (Btw, Christian Rose "menthos" is THE authority for approving string freeze breakages -- my opinion here is just that: *my* opinion.)