Use gettext for translating user messages

Bug #619632 reported by Robert Ancell
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PolicyKit
Unknown
Wishlist
Ubuntu Translations
Fix Released
Medium
Unassigned
policykit-1 (Ubuntu)
Fix Released
Wishlist
Robert Ancell

Bug Description

Binary package hint: policykit-1

PolicyKit currently requires translations to be in the XML, e.g.:

    <description>Install system color profiles</description>
    <description xml:lang="cs">Instalovat systémové profily barev</description>

This makes it hard to modify translations after build-time and to provide only a set of translations (i.e. a language pack).

It would be better to have:

    <description gettext-domain="gnome-color-manager">Install system color profiles</description>

And use the standard gettext system.

Revision history for this message
In , Robert Ancell (robert-ancell) wrote :

Created an attachment (id=37938)
Use gettext for translations in .policy files

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Binary package hint: policykit-1

PolicyKit currently requires translations to be in the XML, e.g.:

    <description>Install system color profiles</description>
    <description xml:lang="cs">Instalovat systémové profily barev</description>

This makes it hard to modify translations after build-time and to provide only a set of translations (i.e. a language pack).

It would be better to have:

    <description gettext-domain="gnome-color-manager">Install system color profiles</description>

And use the standard gettext system.

Changed in policykit-1 (Ubuntu):
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Patch is in upstream bug, will see what feedback they give on it.

Revision history for this message
In , Robert Ancell (robert-ancell) wrote :

Created an attachment (id=38163)
Optionally use gettext for translations in .policy files

Updated to only use gettext if gettext-domain is defined. Falls back to current behaviour if it is not.

Revision history for this message
In , Robert Ancell (robert-ancell) wrote :

Created an attachment (id=38164)
Optionally use gettext for translations in .policy files

Fix accidental renaming of function parameter. Note there appears to be a copy-paste error where one function has "interactivee" instead of "locale". I had it in the original patch, I've removed it here for clarity.

Revision history for this message
In , Robert Ancell (robert-ancell) wrote :

Created an attachment (id=38166)
Optionally use gettext for translations in .policy files

Uses setlocale inside _localize as it didn't appear to work at the higher level. I've confirmed this works with the current translations and gettext translation. The Ubuntu 10.10 package is running with this.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package policykit-1 - 0.96-2ubuntu1

---------------
policykit-1 (0.96-2ubuntu1) maverick; urgency=low

  * debian/patches/02_gettext.patch:
    - Allow gettext to be used for translations (LP: #619632)
 -- Robert Ancell <email address hidden> Thu, 26 Aug 2010 11:19:22 +1000

Changed in policykit-1 (Ubuntu):
status: Triaged → Fix Released
Changed in policykit-1 (Ubuntu):
assignee: nobody → Robert Ancell (robert-ancell)
Revision history for this message
David Planella (dpm) wrote :

Just added an ubuntu-translations task for the translations team to easily keep track of progress on this.

Thanks a lot Robert for working on it!

Changed in ubuntu-translations:
status: New → Fix Released
importance: Undecided → Medium
Changed in policykit-1:
importance: Unknown → Wishlist
status: Unknown → Confirmed
Changed in policykit-1:
importance: Wishlist → Unknown
Changed in policykit-1:
importance: Unknown → Wishlist
Revision history for this message
In , Robert Ancell (robert-ancell) wrote :

Hi, any feedback on this patch?

Revision history for this message
In , Robert Ancell (robert-ancell) wrote :

Ping :)

Revision history for this message
In , Miloslav Trmac (mitr-redhat) wrote :

Thanks for the patch. The approach broadly makes sense, three points for now:

* The documentation should be updated as well.
* AFAICT _localize() is not handling the lang==NULL case correctly.
* The calls to setlocale() are worrisome; we do use threads at least in the JavaScript runtime. It seems that gettext can work with per-thread locales (uselocale()), OTOH that might not be portable. (Honestly not sure about this. Colin?)

(I haven’t reviewed the memory handling in detail

Revision history for this message
In , Bugzilla-tecnocode (bugzilla-tecnocode) wrote :

Comment on attachment 38166
Optionally use gettext for translations in .policy files

Review of attachment 38166:
-----------------------------------------------------------------

It might be useful to also allow gettext-domain to be specified on the <policyconfig> element, to avoid repeating it on every single <description> in the file.

::: src/polkitbackend/polkitbackendactionpool.c
@@ +1131,4 @@
> * _localize:
> * @translations: a mapping from xml:lang to the value, e.g. 'da' -> 'Smadre', 'en_CA' -> 'Punch, Aye!'
> * @untranslated: the untranslated value, e.g. 'Punch'
> + * @domain: the gettext domain for this string. Make be NULL.

s/Make/May/

@@ +1153,5 @@
> + {
> + gchar *old_locale;
> +
> + old_locale = g_strdup (setlocale (LC_ALL, NULL));
> + setlocale (LC_ALL, lang);

setlocale() is not thread safe. Since polkit could be being used from a thread, we *cannot* call this.

We could use uselocale() instead, which only operates on the current thread’s locale. http://pubs.opengroup.org/onlinepubs/9699919799/functions/uselocale.html

Unfortunately, as far as I know, there is no gettext function which allows the locale to be specified. The other approach I can think of would be to load up the gettext catalogues manually for the desired locale, but I don’t know if APIs exist for that.

Revision history for this message
In , Gitlab-migration (gitlab-migration) wrote :

-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/polkit/polkit/issues/34.

Changed in policykit-1:
status: Confirmed → Unknown
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.