Bug 29639 - [patch] Use gettext for translating user messages
Summary: [patch] Use gettext for translating user messages
Status: RESOLVED MOVED
Alias: None
Product: PolicyKit
Classification: Unclassified
Component: daemon (show other bugs)
Version: unspecified
Hardware: All All
: medium enhancement
Assignee: David Zeuthen (not reading bugmail)
QA Contact: David Zeuthen (not reading bugmail)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-17 23:15 UTC by Robert Ancell
Modified: 2018-08-20 21:36 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Use gettext for translations in .policy files (18.32 KB, patch)
2010-08-17 23:27 UTC, Robert Ancell
Details | Splinter Review
Optionally use gettext for translations in .policy files (9.84 KB, patch)
2010-08-25 18:15 UTC, Robert Ancell
Details | Splinter Review
Optionally use gettext for translations in .policy files (9.13 KB, patch)
2010-08-25 18:17 UTC, Robert Ancell
Details | Splinter Review
Optionally use gettext for translations in .policy files (6.58 KB, patch)
2010-08-25 20:36 UTC, Robert Ancell
Details | Splinter Review

Description Robert Ancell 2010-08-17 23:15:41 UTC
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.
Comment 1 Robert Ancell 2010-08-17 23:27:17 UTC
Created attachment 37938 [details] [review]
Use gettext for translations in .policy files
Comment 2 Robert Ancell 2010-08-25 18:15:39 UTC
Created attachment 38163 [details] [review]
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.
Comment 3 Robert Ancell 2010-08-25 18:17:40 UTC
Created attachment 38164 [details] [review]
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.
Comment 4 Robert Ancell 2010-08-25 20:36:25 UTC
Created attachment 38166 [details] [review]
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.
Comment 5 Robert Ancell 2011-03-15 23:07:39 UTC
Hi, any feedback on this patch?
Comment 6 Robert Ancell 2017-04-04 05:05:38 UTC
Ping :)
Comment 7 Miloslav Trmac 2017-04-04 14:41:09 UTC
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
Comment 8 Philip Withnall 2017-07-06 14:44:03 UTC
Comment on attachment 38166 [details] [review]
Optionally use gettext for translations in .policy files

Review of attachment 38166 [details] [review]:
-----------------------------------------------------------------

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.
Comment 9 GitLab Migration User 2018-08-20 21:36:11 UTC
-- 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.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.