All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] gtk: use setlocale() for LC_MESSAGES only
@ 2015-09-10 15:19 Alberto Garcia
  2015-09-11  9:12 ` Gerd Hoffmann
  2015-12-18 11:38 ` Kevin Wolf
  0 siblings, 2 replies; 8+ messages in thread
From: Alberto Garcia @ 2015-09-10 15:19 UTC (permalink / raw)
  To: qemu-devel; +Cc: Markus Armbruster, Alberto Garcia, Gerd Hoffmann

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.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 ui/gtk.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index df2a79e..11ea2cf 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1941,7 +1941,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");
 
@@ -2010,6 +2011,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 */
-- 
2.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-12-21 17:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-10 15:19 [Qemu-devel] [PATCH] gtk: use setlocale() for LC_MESSAGES only Alberto Garcia
2015-09-11  9:12 ` Gerd Hoffmann
2015-12-18 11:38 ` Kevin Wolf
2015-12-18 13:23   ` Gerd Hoffmann
2015-12-18 15:38     ` Kevin Wolf
2015-12-18 18:04     ` Alberto Garcia
2015-12-18 19:55       ` Markus Armbruster
2015-12-21 17:49         ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.