+2008-05-17 Yair Hershkovitz <yairhr@gmail.com>
+
+ * glib/glib.symbols:
+ * glib/gi18n.h: Added g_disable_setlocale().
+
+ * glib/gi18n.c: Added g_disable_setlocale() API to disable setting
+ the locale in g_i18n_init(). Dont disable translations if textdomain
+ was not set before calling g_i18n_init(). Dont disable translations if
+ the locale is "C".
+
2008-05-16 Tor Lillqvist <tml@novell.com>
* config.h.win32.in: Update to match the configure-produced one.
#include <string.h>
#include <locale.h>
-static gboolean g_should_translate = TRUE;
+static gboolean should_translate = TRUE;
+static gboolean do_setlocale = TRUE;
+static gboolean initialized = FALSE;
void
g_i18n_init (void)
{
- gchar *domain, *default_domain;
+ gchar *domain, *default_domain, *locale;
- setlocale (LC_ALL, "");
+ initialized = TRUE;
+
+ locale = setlocale (LC_ALL, do_setlocale ? "" : NULL);
domain = g_strdup (textdomain (NULL));
default_domain = g_strdup (textdomain (""));
textdomain (domain);
if (!strcmp (domain, default_domain))
- g_warning ("textdomain() must be called before glib i18n initialization");
-
- g_free (domain);
- g_free (default_domain);
+ {
+ g_warning ("textdomain() must be called before glib i18n initialization");
+ goto out;
+ }
- if (!*gettext (""))
+ if (!*gettext ("") && (!locale || strcmp (locale, "C")))
{
- g_should_translate = FALSE;
+ should_translate = FALSE;
g_warning ("No translation is available for the requested locale.");
}
+
+out:
+ g_free (domain);
+ g_free (default_domain);
+}
+
+/**
+ * g_disable_setlocale:
+ *
+ * Prevents g_i18n_init() from automatically
+ * calling <literal>setlocale (LC_ALL, "")</literal>. You would
+ * want to use this function if you wanted to set the locale for
+ * your program to something other than the user's locale, or if
+ * you wanted to set different values for different locale categories.
+ *
+ * Most programs should not need to call this function.
+ **/
+void
+g_disable_setlocale (void)
+{
+ if (initialized)
+ g_warning ("g_disable_setlocale() must be called before g_i18n_init()");
+
+ do_setlocale = FALSE;
}
/**
const gchar *
g_gettext (const gchar *msgid)
{
- if (g_should_translate)
- return gettext (msgid);
- else
+ if (!initialized)
+ goto out;
+
+ if (!should_translate)
return msgid;
+
+out:
+ return gettext (msgid);
}
/**
g_dgettext (const gchar *domain,
const gchar *msgid)
{
- if (g_should_translate)
- return dgettext (domain, msgid);
- else
+ if (!initialized)
+ goto out;
+
+ if (!should_translate)
return msgid;
+
+out:
+ return dgettext (domain, msgid);
}
/**