[PATCH 2/3] Set client locale to LC_MESSAGES rather than LC_ALL

Colin Watson cjwatson at canonical.com
Mon Jan 24 06:27:13 PST 2011


If some locale categories are set to different values (e.g.
LANG=en_GB.UTF-8 LC_COLLATE=C), then glibc's setlocale (LC_ALL, NULL)
will return a composite name, which looks something like this:

  LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=en_GB.UTF-8;LC_TIME=en_GB.UTF-8;LC_COLLATE=C;LC_MONETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=en_GB.UTF-8;LC_ADDRESS=en_GB.UTF-8;LC_TELEPHONE=en_GB.UTF-8;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=en_GB.UTF-8

Setting LANG to this, as some backends do, will produce invalid results;
the only thing that can validly be done with this string is to set the
LC_ALL locale category to it.

However, in some cases (e.g. the aptcc backend), we need to set the
locale in the environment rather than via setlocale.  Since some
programs have been known to look at locale environment variables
directly, passing a composite name through the environment is probably
not the most reliable approach.  Instead, fetch the LC_MESSAGES
category, since our uses of the client locale are generally for message
localization.
---
 lib/packagekit-glib2/pk-client.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/packagekit-glib2/pk-client.c b/lib/packagekit-glib2/pk-client.c
index 5e13780..fa2f18b 100644
--- a/lib/packagekit-glib2/pk-client.c
+++ b/lib/packagekit-glib2/pk-client.c
@@ -4883,7 +4883,7 @@ pk_client_init (PkClient *client)
 					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
 
 	/* cache locale */
-	client->priv->locale = 	g_strdup (setlocale (LC_ALL, NULL));
+	client->priv->locale = 	g_strdup (setlocale (LC_MESSAGES, NULL));
 }
 
 /**
-- 
1.7.2.3


--svZFHVx8/dhPCe52
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0003-aptcc-Use-a-pty-rather-than-a-pipe-for-writing-to-ap.patch"



More information about the PackageKit mailing list