[glib] Correct internal definition of C_()



commit 789b341eff1553232b61b2e3ce3c4c918bf661e3
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Mar 12 20:48:31 2011 -0500

    Correct internal definition of C_()
    
    * Since the GLib translations are lazily initialized, we need an
      internal wrapper for g_dpgettext() that does the initialization
      in the same way as glib_gettext()
    * We need to use the glib domain defined by GETTEXT_PACKAGE
      rather than than the application's domain.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644607

 glib/glibintl.h |    6 +++-
 glib/gutils.c   |   56 ++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 47 insertions(+), 15 deletions(-)
---
diff --git a/glib/glibintl.h b/glib/glibintl.h
index 6d79a26..3164a0a 100644
--- a/glib/glibintl.h
+++ b/glib/glibintl.h
@@ -5,7 +5,9 @@
 #error "config.h must be included prior to glibintl.h"
 #endif
 
-G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1);
+G_CONST_RETURN gchar *glib_gettext  (const gchar *str) G_GNUC_FORMAT(1);
+G_CONST_RETURN gchar *glib_pgettext (const gchar *msgctxtid,
+                                     gsize        msgidoffset) G_GNUC_FORMAT(1);
 
 #ifdef ENABLE_NLS
 
@@ -13,7 +15,7 @@ G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1);
 #define _(String) glib_gettext(String)
 /* Split out this in the code, but keep it in the same domain for now */
 #define P_(String) glib_gettext(String)
-#define C_(Context,String) g_dpgettext (NULL, Context "\004" String, strlen (Context) + 1)
+#define C_(Context,String) glib_pgettext (Context "\004" String, strlen (Context) + 1)
 
 #ifdef gettext_noop
 #define N_(String) gettext_noop(String)
diff --git a/glib/gutils.c b/glib/gutils.c
index 5bea93f..6d9dbe9 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -3611,18 +3611,8 @@ _glib_get_locale_dir (void)
 
 #endif /* G_OS_WIN32 */
 
-/**
- * glib_gettext:
- * @str: The string to be translated
- *
- * Returns the translated string from the glib translations.
- * This is an internal function and should only be used by
- * the internals of glib (such as libgio).
- *
- * Returns: the transation of @str to the current locale
- */
-G_CONST_RETURN gchar *
-glib_gettext (const gchar *str)
+static void
+ensure_gettext_initialized(void)
 {
   static gboolean _glib_gettext_initialized = FALSE;
 
@@ -3640,10 +3630,50 @@ glib_gettext (const gchar *str)
 #    endif
       _glib_gettext_initialized = TRUE;
     }
-  
+}
+
+/**
+ * glib_gettext:
+ * @str: The string to be translated
+ *
+ * Returns the translated string from the glib translations.
+ * This is an internal function and should only be used by
+ * the internals of glib (such as libgio).
+ *
+ * Returns: the transation of @str to the current locale
+ */
+G_CONST_RETURN gchar *
+glib_gettext (const gchar *str)
+{
+  ensure_gettext_initialized();
+
   return g_dgettext (GETTEXT_PACKAGE, str);
 }
 
+/**
+ * glib_pgettext:
+ * @msgctxtid: a combined message context and message id, separated
+ *   by a \004 character
+ * @msgidoffset: the offset of the message id in @msgctxid
+ *
+ * This function is a variant of glib_gettext() which supports
+ * a disambiguating message context. See g_dpgettext() for full
+ * details.
+ *
+ * This is an internal function and should only be used by
+ * the internals of glib (such as libgio).
+ *
+ * Returns: the transation of @str to the current locale
+ */
+G_CONST_RETURN gchar *
+glib_pgettext(const gchar *msgctxtid,
+              gsize        msgidoffset)
+{
+  ensure_gettext_initialized();
+
+  return g_dpgettext (GETTEXT_PACKAGE, msgctxtid, msgidoffset);
+}
+
 #if defined (G_OS_WIN32) && !defined (_WIN64)
 
 /* Binary compatibility versions. Not for newly compiled code. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]