After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 106703 - Please use ngettext for handling plurals in nautilus-media
Please use ngettext for handling plurals in nautilus-media
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: [obsolete] nautilus-media
unspecified
Other All
: Normal normal
: ---
Assigned To: Thomas Vander Stichele
Nautilus Maintainers
Depends on:
Blocks: 116236
 
 
Reported: 2003-02-21 10:03 UTC by Christian Rose
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Makes use of ngettext() calls where appropriate; incorrect for fractions (1.83 KB, patch)
2003-07-09 12:30 UTC, Danilo Segan
none Details | Review
Make audio-properties-view use ngettext where possible and sane (1.42 KB, patch)
2003-08-12 23:07 UTC, Danilo Segan
none Details | Review
Another proposed patch based on Danilo's work. Should work fine. Untested (I haven't got gst 0.7 installed). (1.67 KB, patch)
2004-01-11 11:53 UTC, Christian Neumair
none Details | Review
New patch, hardcoded order. Onliest advantage over Danilo's solution: min/secs are ngettextized independently. Untested again. (1.80 KB, patch)
2004-01-11 12:00 UTC, Christian Neumair
none Details | Review
Use ngettext in nautilus-media (compiles fine; improves on Manny's patch) (2.12 KB, patch)
2004-01-13 02:39 UTC, Danilo Segan
none Details | Review

Description Christian Rose 2003-02-21 10:03:57 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);
Comment 1 Thomas Vander Stichele 2003-04-23 15:08:13 UTC
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.
Comment 2 Christian Rose 2003-04-23 15:29:15 UTC
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).
Comment 3 Christian Rose 2003-07-09 09:53:16 UTC
dsegan@gmx.net, perhaps you could help providing a patch?
Comment 4 Danilo Segan 2003-07-09 12:20:39 UTC
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.
Comment 5 Danilo Segan 2003-07-09 12:30:33 UTC
Created attachment 18171 [details] [review]
Makes use of ngettext() calls where appropriate; incorrect for fractions
Comment 6 Thomas Vander Stichele 2003-08-12 16:12:06 UTC
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 ?
Comment 7 Danilo Segan 2003-08-12 16:45:45 UTC
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).
Comment 8 Danilo Segan 2003-08-12 16:50:10 UTC
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.
Comment 9 Thomas Vander Stichele 2003-08-12 16:58:54 UTC
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.
Comment 10 Danilo Segan 2003-08-12 23:05:00 UTC
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.
Comment 11 Danilo Segan 2003-08-12 23:07:13 UTC
Created attachment 19159 [details] [review]
Make audio-properties-view use ngettext where possible and sane
Comment 12 Christian Rose 2003-11-10 11:40:39 UTC
Any news on this?
Comment 13 Christian Neumair 2003-12-30 16:55:37 UTC
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
Comment 14 Christian Rose 2004-01-10 18:00:27 UTC
Could we have this revisited RSN before freezes apply?
Comment 15 Thomas Vander Stichele 2004-01-11 10:49:42 UTC
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 ?
Comment 16 Christian Neumair 2004-01-11 11:53:45 UTC
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).
Comment 17 Christian Neumair 2004-01-11 11:57:03 UTC
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
Comment 18 Christian Neumair 2004-01-11 12:00:36 UTC
Created attachment 23226 [details] [review]
New patch, hardcoded order. Onliest advantage over Danilo's solution: min/secs are ngettextized independently. Untested again.
Comment 19 Danilo Segan 2004-01-11 18:14:51 UTC
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 ;).
Comment 20 Danilo Segan 2004-01-13 02:39:30 UTC
Created attachment 23295 [details] [review]
Use ngettext in nautilus-media (compiles fine; improves on Manny's patch)
Comment 21 Christian Neumair 2004-01-14 16:22:53 UTC
Looks nice.

regs,
 Chris
Comment 22 Danilo Segan 2004-02-01 20:35:53 UTC
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?
Comment 23 Thomas Vander Stichele 2004-02-13 10:58:47 UTC
forgot to close this when commiting.  will be in 0.5.3 release today.
Comment 24 Danilo Segan 2004-02-13 22:25:28 UTC
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.)