From 49836143784e56e369a91db73ac65ba8800ac686 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Wed, 18 Jan 2017 19:24:00 +0100 Subject: [PATCH] Use gettext to get potential distro translations The distribution may provide additional translations that are not contained in the xml file. Use this as fallback if no other translation in the xml file matches. --- 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..5983be2 100644 --- a/src/polkitbackend/polkitbackendactionpool.c +++ b/src/polkitbackend/polkitbackendactionpool.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -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-distro-action-translations", untranslated); + + /* Back to C! */ + setlocale (LC_ALL, "C"); + g_setenv ("LANG", "C", TRUE); out: return result; -- 2.10.2