Accepting request 503611 from Base:System

- Use gettext as fallback to get potential distro translations for
  polkit actions. Similar mechnism as used for desktop file
  translations. That way it's possible to use weblate to add
  additional translations that are not provided by upstream
  (polkit-gettext.patch). (forwarded request 503447 from lnussel)

OBS-URL: https://build.opensuse.org/request/show/503611
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/polkit?expand=0&rev=57
This commit is contained in:
Dominique Leuenberger 2017-06-18 11:49:34 +00:00 committed by Git OBS Bridge
commit 01433480c4
3 changed files with 70 additions and 1 deletions

57
polkit-gettext.patch Normal file
View File

@ -0,0 +1,57 @@
From fea7159b7cc50deb7298b2858e125fb623012549 Mon Sep 17 00:00:00 2001
From: Ludwig Nussel <ludwig.nussel@suse.de>
Date: Tue, 13 Jun 2017 18:28:28 +0200
Subject: [PATCH] Use gettext as fallback for translations
Upstream polkit action files do not necessarily contain translations for
all languages a distribution supports. And even if all translations are
contained in the head branch, distributions sometimes need to ship older
versions of packages. In order to allow retrofitting translations and
shipping language packs for polkit actions without having to patch and
rebuild packages gettext could be used as fallback. That way only
additional .mo files have to be installed.
So this patch makes polkit call into gettext with the domain
'polkit-action-distro-translations' if an xml doesn't contain
translations for the requested language.
---
src/polkitbackend/polkitbackendactionpool.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/polkitbackend/polkitbackendactionpool.c b/src/polkitbackend/polkitbackendactionpool.c
index 3894fe9..9252788 100644
--- a/src/polkitbackend/polkitbackendactionpool.c
+++ b/src/polkitbackend/polkitbackendactionpool.c
@@ -24,6 +24,7 @@
#include <pwd.h>
#include <string.h>
#include <expat.h>
+#include <locale.h>
#include <polkit/polkit.h>
#include <polkit/polkitprivate.h>
@@ -1132,8 +1133,20 @@ _localize (GHashTable *translations,
if (result != NULL)
goto out;
- /* fall back to untranslated */
- result = untranslated;
+ /* try distro provided language bundle via gettext */
+
+ /* Set LANG and locale so g_dgettext() + friends work below */
+ if (setlocale (LC_ALL, lang) == NULL)
+ {
+ g_printerr ("Invalid locale '%s'\n", lang);
+ }
+ g_setenv ("LANG", lang, TRUE);
+
+ result = g_dgettext ("polkit-action-distro-translations", untranslated);
+
+ /* Back to C! */
+ setlocale (LC_ALL, "C");
+ g_setenv ("LANG", "C", TRUE);
out:
return result;
--
2.12.2

View File

@ -1,3 +1,12 @@
-------------------------------------------------------------------
Tue Jun 13 15:25:58 UTC 2017 - lnussel@suse.de
- Use gettext as fallback to get potential distro translations for
polkit actions. Similar mechnism as used for desktop file
translations. That way it's possible to use weblate to add
additional translations that are not provided by upstream
(polkit-gettext.patch).
-------------------------------------------------------------------
Wed Jun 8 11:13:43 UTC 2016 - fbui@suse.com

View File

@ -1,7 +1,7 @@
#
# spec file for package polkit
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -36,6 +36,8 @@ Patch0: polkit-no-wheel-group.patch
Patch1: polkit-no-systemd.patch
# PATCH-REVERT-UPSTREAM polkit-revert-session-magic.patch various bugs meissner -- systemd session magic was not updating the user seats correctly
Patch2: polkit-revert-session-magic.patch
# PATCH-FIX-OPENSUSE polkit-gettext.patch lnussel@suse.de -- allow fallback to gettext for polkit action translations
Patch3: polkit-gettext.patch
# needed for patch1
BuildRequires: autoconf
# needed for patch1
@ -131,6 +133,7 @@ This package provides the GObject Introspection bindings for PolicyKit.
%patch1 -p1
%endif
%patch2 -p1 -R
%patch3 -p1
%build
export V=1