[Spice-devel] [PATCH spice-gtk] gettext: fix ngettext usage
Jakub Janku
jjanku at redhat.com
Wed Apr 17 21:29:01 UTC 2019
On Wed, Apr 17, 2019 at 6:24 PM Frediano Ziglio <fziglio at redhat.com> wrote:
>
> >
> > _() should not be used in conjunction with ngettext(),
> > otherwise it's impossible to properly translate the message into
> > languages that have multiple plural forms, such as Czech.
> >
> > Fix ngettext usage in usb-device-widget.c and
> > update the PO files accordingly.
> >
> > Signed-off-by: Jakub Janků <jjanku at redhat.com>
> > ---
> > po/de.po | 9 +++------
> > po/fr.po | 11 ++++-------
> > po/it.po | 12 +++++-------
> > src/usb-device-widget.c | 4 ++--
> > 4 files changed, 14 insertions(+), 22 deletions(-)
> >
> > diff --git a/po/de.po b/po/de.po
> > index eb24de7..3ae6ae0 100644
> > --- a/po/de.po
> > +++ b/po/de.po
> > @@ -288,12 +288,9 @@ msgstr "Auswahl des USB-Geräts zum Weiterleiten"
> > #: src/usb-device-widget.c:393
> > #, c-format
> > msgid "Select USB devices to redirect (%d free channel)"
> > -msgstr "Auswahl des USB-Geräts zum Weiterleiten (%d freier Kanal)"
> > -
> > -#: src/usb-device-widget.c:394
> > -#, c-format
> > -msgid "Select USB devices to redirect (%d free channels)"
> > -msgstr "Auswahl des USB-Geräts zum Weiterleiten (%d freie Kanäle)"
> > +msgid_plural "Select USB devices to redirect (%d free channels)"
> > +msgstr[0] "Auswahl des USB-Geräts zum Weiterleiten (%d freier Kanal)"
> > +msgstr[1] "Auswahl des USB-Geräts zum Weiterleiten (%d freie Kanäle)"
> >
> > #: src/usb-device-widget.c:411
> > msgid "Redirecting USB Device..."
> > diff --git a/po/fr.po b/po/fr.po
> > index e2dd3ad..6120ee0 100644
> > --- a/po/fr.po
> > +++ b/po/fr.po
> > @@ -271,15 +271,12 @@ msgstr ""
> > msgid "Select USB devices to redirect"
> > msgstr ""
> >
> > -#: src/usb-device-widget.c:420
> > +#: src/usb-device-widget.c:393
> > #, c-format
> > msgid "Select USB devices to redirect (%d free channel)"
> > -msgstr ""
> > -
> > -#: src/usb-device-widget.c:421
> > -#, c-format
> > -msgid "Select USB devices to redirect (%d free channels)"
> > -msgstr ""
> > +msgid_plural "Select USB devices to redirect (%d free channels)"
> > +msgstr[0] ""
> > +msgstr[1] ""
> >
> > #: src/usb-device-widget.c:439
> > msgid "Redirecting USB Device..."
> > diff --git a/po/it.po b/po/it.po
> > index a4e40e9..b7899a8 100644
> > --- a/po/it.po
> > +++ b/po/it.po
> > @@ -16,6 +16,7 @@ msgstr ""
> > "MIME-Version: 1.0\n"
> > "Content-Type: text/plain; charset=UTF-8\n"
> > "Content-Transfer-Encoding: 8bit\n"
> > +"Plural-Forms: nplurals=2; plural=n != 1;\n"
> > "X-Generator: Poedit 1.8.8\n"
> >
> > #: src/channel-main.c:1868
> > @@ -286,15 +287,12 @@ msgstr "%s %s %s a %d-%d"
> > msgid "Select USB devices to redirect"
> > msgstr "Selezionare dispositivo USB da redirigere"
> >
> > -#: src/usb-device-widget.c:420
> > +#: src/usb-device-widget.c:393
> > #, c-format
> > msgid "Select USB devices to redirect (%d free channel)"
> > -msgstr "Selezionare dispositivo USB da redirigere (%d canale libero)"
> > -
> > -#: src/usb-device-widget.c:421
> > -#, c-format
> > -msgid "Select USB devices to redirect (%d free channels)"
> > -msgstr "Selezionare dispositivo USB da redirigere (%d canali liberi)"
> > +msgid_plural "Select USB devices to redirect (%d free channels)"
> > +msgstr[0] "Selezionare dispositivo USB da redirigere (%d canale libero)"
> > +msgstr[1] "Selezionare dispositivo USB da redirigere (%d canali liberi)"
> >
>
> Applied the patch, set lang to it_IT.utf-8, most strings work, this
> no way! I did an strace to check the file used are correct, they are.
> I removed all .gmo and .mo, rebuilt, reinstalled, checked I'm using
> the new. Still not working. Probably I'm doing something really silly
> but I cannot understand what I'm doing wrong.
> I also checked if that specific string is inside virt-viewer strings,
> no.
>
> It seems this hunk solve the issue:
>
>
> @@ -390,7 +390,7 @@ static gboolean spice_usb_device_widget_update_status(gpointer user_data)
> redirecting = spice_usb_device_manager_is_redirecting(priv->manager);
>
> g_object_get(priv->manager, "free-channels", &free_channels, NULL);
> - free_channels_str = ngettext("Select USB devices to redirect (%d free channel)",
> + free_channels_str = dngettext(GETTEXT_PACKAGE, "Select USB devices to redirect (%d free channel)",
> "Select USB devices to redirect (%d free channels)",
> free_channels);
> str = g_strdup_printf(free_channels_str, free_channels);
Ah, I see, so this is another mistake. Spice-gtk, as a library, should
be using the dngettext function instead of ngettext, otherwise the
translation string is searched in the "virt-viewer" domain and hence
not found.
I'll be sending v2.
Thanks,
Jakub
>
>
> > #: src/usb-device-widget.c:439
> > msgid "Redirecting USB Device..."
> > diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
> > index de62564..7979a2c 100644
> > --- a/src/usb-device-widget.c
> > +++ b/src/usb-device-widget.c
> > @@ -390,8 +390,8 @@ static gboolean
> > spice_usb_device_widget_update_status(gpointer user_data)
> > redirecting = spice_usb_device_manager_is_redirecting(priv->manager);
> >
> > g_object_get(priv->manager, "free-channels", &free_channels, NULL);
> > - free_channels_str = ngettext(_("Select USB devices to redirect (%d free
> > channel)"),
> > - _("Select USB devices to redirect (%d free
> > channels)"),
> > + free_channels_str = ngettext("Select USB devices to redirect (%d free
> > channel)",
> > + "Select USB devices to redirect (%d free
> > channels)",
> > free_channels);
> > str = g_strdup_printf(free_channels_str, free_channels);
> > markup_str = g_strdup_printf("<b>%s</b>", str);
>
> Frediano
More information about the Spice-devel
mailing list