glib r6894 - in trunk: . glib
- From: yairhr svn gnome org
- To: svn-commits-list gnome org
- Subject: glib r6894 - in trunk: . glib
- Date: Fri, 16 May 2008 23:52:42 +0100 (BST)
Author: yairhr
Date: Fri May 16 22:52:42 2008
New Revision: 6894
URL: http://svn.gnome.org/viewvc/glib?rev=6894&view=rev
Log:
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".
Modified:
trunk/ChangeLog
trunk/glib/gi18n.c
trunk/glib/gi18n.h
trunk/glib/glib.symbols
Modified: trunk/glib/gi18n.c
==============================================================================
--- trunk/glib/gi18n.c (original)
+++ trunk/glib/gi18n.c Fri May 16 22:52:42 2008
@@ -31,29 +31,57 @@
#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;
}
/**
@@ -73,10 +101,14 @@
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);
}
/**
@@ -99,10 +131,14 @@
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);
}
/**
Modified: trunk/glib/gi18n.h
==============================================================================
--- trunk/glib/gi18n.h (original)
+++ trunk/glib/gi18n.h Fri May 16 22:52:42 2008
@@ -42,7 +42,8 @@
const gchar *msgctxtid,
gsize msgidoffset);
-void g_i18n_init (void);
+void g_i18n_init (void);
+void g_disable_setlocale (void);
G_END_DECLS
Modified: trunk/glib/glib.symbols
==============================================================================
--- trunk/glib/glib.symbols (original)
+++ trunk/glib/glib.symbols Fri May 16 22:52:42 2008
@@ -1585,6 +1585,7 @@
#if IN_HEADER(__G_I18N_H__)
#if IN_FILE(__G_I18N_C__)
g_i18n_init
+g_disable_setlocale
g_gettext
g_dgettext
g_dpgettext
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]