From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alberto Garcia <berto@igalia.com>,
qemu-stable@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 6/6] gtk: use setlocale() for LC_MESSAGES only
Date: Tue, 15 Sep 2015 12:38:55 +0200 [thread overview]
Message-ID: <1442313535-4549-7-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1442313535-4549-1-git-send-email-kraxel@redhat.com>
From: Alberto Garcia <berto@igalia.com>
The QEMU code is not internationalized and assumes that it runs under
the C locale, but if we use the GTK+ UI we'll end up importing the
locale settings from the environment. This can break things, such as
the JSON generator and iotest 120 in locales that use a decimal comma.
We do however have translations for a few simple strings for the GTK+
menu items, so in order to run QEMU using the C locale, and yet have a
translated UI let's use setlocale() for LC_MESSAGES only.
Cc: qemu-stable@nongnu.org
Signed-off-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
ui/gtk.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/ui/gtk.c b/ui/gtk.c
index a17b1d1..187de74 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1950,7 +1950,8 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
s->free_scale = FALSE;
- setlocale(LC_ALL, "");
+ /* LC_MESSAGES only. See early_gtk_display_init() for details */
+ setlocale(LC_MESSAGES, "");
bindtextdomain("qemu", CONFIG_QEMU_LOCALEDIR);
textdomain("qemu");
@@ -2019,6 +2020,24 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
void early_gtk_display_init(int opengl)
{
+ /* The QEMU code relies on the assumption that it's always run in
+ * the C locale. Therefore it is not prepared to deal with
+ * operations that produce different results depending on the
+ * locale, such as printf's formatting of decimal numbers, and
+ * possibly others.
+ *
+ * Since GTK+ calls setlocale() by default -importing the locale
+ * settings from the environment- we must prevent it from doing so
+ * using gtk_disable_setlocale().
+ *
+ * QEMU's GTK+ UI, however, _does_ have translations for some of
+ * the menu items. As a trade-off between a functionally correct
+ * QEMU and a fully internationalized UI we support importing
+ * LC_MESSAGES from the environment (see the setlocale() call
+ * earlier in this file). This allows us to display translated
+ * messages leaving everything else untouched.
+ */
+ gtk_disable_setlocale();
gtkinit = gtk_init_check(NULL, NULL);
if (!gtkinit) {
/* don't exit yet, that'll break -help */
--
1.8.3.1
next prev parent reply other threads:[~2015-09-15 10:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-15 10:38 [Qemu-devel] [PULL 0/6] gtk: misc grab tweaks, locale fix Gerd Hoffmann
2015-09-15 10:38 ` [Qemu-devel] [PULL 1/6] gtk: check for existing grabs in gd_grab_{pointer, keyboard} Gerd Hoffmann
2015-09-15 10:38 ` [Qemu-devel] [PULL 2/6] gtk: move gd_update_caption calls to gd_{grab, ungrab}_{pointer, keyboard} Gerd Hoffmann
2015-09-15 10:38 ` [Qemu-devel] [PULL 3/6] gtk: trace input grab reason Gerd Hoffmann
2015-09-15 10:38 ` [Qemu-devel] [PULL 4/6] gtk: set free_scale when setting zoom_fit Gerd Hoffmann
2015-09-15 10:38 ` [Qemu-devel] [PULL 5/6] gtk: don't grab input when entering fullscreen Gerd Hoffmann
2015-09-15 10:38 ` Gerd Hoffmann [this message]
2015-09-15 14:27 ` [Qemu-devel] [PULL 0/6] gtk: misc grab tweaks, locale fix Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442313535-4549-7-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=berto@igalia.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).