glib r7202 - in trunk: . docs/reference docs/reference/glib docs/reference/glib/tmpl glib
- From: matthiasc svn gnome org
- To: svn-commits-list gnome org
- Subject: glib r7202 - in trunk: . docs/reference docs/reference/glib docs/reference/glib/tmpl glib
- Date: Fri, 18 Jul 2008 18:14:05 +0000 (UTC)
Author: matthiasc
Date: Fri Jul 18 18:14:04 2008
New Revision: 7202
URL: http://svn.gnome.org/viewvc/glib?rev=7202&view=rev
Log:
Bug 536996 â Missing noop i18n macro equivalent to C_
* glib/glib.symbols:
* glib/gstrfuncs.[hc]: Add g_dpgettext2() which is a
variant of g_dpgettext() taking context and id as separate
arguments.
* glib/gi18n-lib.h:
* glib/gi18n.h: Add an NC_() macro that is to C_() as N_()
is to _().
Modified:
trunk/ChangeLog
trunk/docs/reference/ChangeLog
trunk/docs/reference/glib/glib-sections.txt
trunk/docs/reference/glib/tmpl/i18n.sgml
trunk/glib/gi18n-lib.h
trunk/glib/gi18n.h
trunk/glib/glib.symbols
trunk/glib/gstrfuncs.c
trunk/glib/gstrfuncs.h
Modified: trunk/docs/reference/glib/glib-sections.txt
==============================================================================
--- trunk/docs/reference/glib/glib-sections.txt (original)
+++ trunk/docs/reference/glib/glib-sections.txt Fri Jul 18 18:14:04 2008
@@ -2503,9 +2503,11 @@
Q_
C_
N_
+NC_
g_dgettext
g_dngettext
g_dpgettext
+g_dpgettext2
g_strip_context
<SUBSECTION>
g_get_language_names
Modified: trunk/docs/reference/glib/tmpl/i18n.sgml
==============================================================================
--- trunk/docs/reference/glib/tmpl/i18n.sgml (original)
+++ trunk/docs/reference/glib/tmpl/i18n.sgml Fri Jul 18 18:14:04 2008
@@ -148,6 +148,41 @@
@Returns:
+<!-- ##### MACRO NC_ ##### -->
+<para>
+Only marks a string for translation, with context.
+This is useful in situations where the translated strings can't
+be directly used, e.g. in string array initializers.
+To get the translated string, you should call g_dpgettext2() at runtime.
+</para>
+|[
+ {
+ static const char *messages[] = {
+ NC_("some context", "some very meaningful message"),
+ NC_("some context", "and another one")
+ };
+ const char *string;
+ ...
+ string
+ = index > 1 ? g_dpgettext2 (NULL, "some context", "a default message") : g_dpgettext2 (NULL, "some context", messages[index]);
+<!-- -->
+ fputs (string);
+ ...
+ }
+]|
+
+<note><para>
+If you are using the NC_() macro, you need to make sure that you
+pass <option>--keyword=NC_:1c,2</option> to xgettext when extracting
+messages. Note that this only works with GNU gettext >= 0.15.
+</para></note>
+
+
+ Context: a message context, must be a string literal
+ String: a message id, must be a string literal
+ Since: 2.18
+
+
<!-- ##### FUNCTION g_strip_context ##### -->
<para>
Modified: trunk/glib/gi18n-lib.h
==============================================================================
--- trunk/glib/gi18n-lib.h (original)
+++ trunk/glib/gi18n-lib.h Fri Jul 18 18:14:04 2008
@@ -32,5 +32,6 @@
#define Q_(String) g_dpgettext (GETTEXT_PACKAGE, String, 0)
#define N_(String) (String)
#define C_(Context,String) g_dpgettext (GETTEXT_PACKAGE, Context "\004" String, strlen (Context) + 1)
+#define NC_(Context, String) (String)
#endif /* __G_I18N_LIB_H__ */
Modified: trunk/glib/gi18n.h
==============================================================================
--- trunk/glib/gi18n.h (original)
+++ trunk/glib/gi18n.h Fri Jul 18 18:14:04 2008
@@ -28,5 +28,6 @@
#define Q_(String) g_dpgettext (NULL, String, 0)
#define N_(String) (String)
#define C_(Context,String) g_dpgettext (NULL, Context "\004" String, strlen (Context) + 1)
+#define NC_(Context, String) (String)
#endif /* __G_I18N_H__ */
Modified: trunk/glib/glib.symbols
==============================================================================
--- trunk/glib/glib.symbols (original)
+++ trunk/glib/glib.symbols Fri Jul 18 18:14:04 2008
@@ -1154,6 +1154,7 @@
g_dgettext G_GNUC_FORMAT(2)
g_dngettext G_GNUC_FORMAT(3)
g_dpgettext G_GNUC_FORMAT(2)
+g_dpgettext2 G_GNUC_FORMAT(3)
#endif
#endif
Modified: trunk/glib/gstrfuncs.c
==============================================================================
--- trunk/glib/gstrfuncs.c (original)
+++ trunk/glib/gstrfuncs.c Fri Jul 18 18:14:04 2008
@@ -2909,6 +2909,62 @@
return translation;
}
+/* This function is taken from gettext.h
+ * GNU gettext uses '\004' to separate context and msgid in .mo files.
+ */
+/**
+ * g_dpgettext2:
+ * @domain: the translation domain to use, or %NULL to use
+ * the domain set with textdomain()
+ * @context: the message context
+ * @msgid: the message
+ *
+ * This function is a variant of g_dgettext() which supports
+ * a disambiguating message context. GNU gettext uses the
+ * '\004' character to separate the message context and
+ * message id in @msgctxtid.
+ *
+ * This uses g_dgettext() internally. See that functions for differences
+ * with dgettext() proper.
+ *
+ * This function differs from C_() in that it is not a macro and
+ * thus you may use non-string-literals as context and msgid arguments.
+ *
+ * Returns: The translated string
+ *
+ * Since: 2.18
+ */
+G_CONST_RETURN char *
+g_dpgettext2 (const char *domain,
+ const char *msgctxt,
+ const char *msgid)
+{
+ size_t msgctxt_len = strlen (msgctxt) + 1;
+ size_t msgid_len = strlen (msgid) + 1;
+ const char *translation;
+ char* msg_ctxt_id;
+
+ msg_ctxt_id = g_alloca (msgctxt_len + msgid_len);
+
+ memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+ msg_ctxt_id[msgctxt_len - 1] = '\004';
+ memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+
+ translation = g_dgettext (domain, msg_ctxt_id);
+
+ if (translation == msg_ctxt_id)
+ {
+ /* try the old way of doing message contexts, too */
+ msg_ctxt_id[msgctxt_len - 1] = '|';
+ translation = g_dgettext (domain, msg_ctxt_id);
+
+ if (translation == msg_ctxt_id)
+ return msgid;
+ }
+
+ return translation;
+}
+
static gboolean
_g_dgettext_should_translate (void)
{
Modified: trunk/glib/gstrfuncs.h
==============================================================================
--- trunk/glib/gstrfuncs.h (original)
+++ trunk/glib/gstrfuncs.h Fri Jul 18 18:14:04 2008
@@ -257,6 +257,9 @@
G_CONST_RETURN gchar *g_dpgettext (const gchar *domain,
const gchar *msgctxtid,
gsize msgidoffset) G_GNUC_FORMAT(2);
+G_CONST_RETURN gchar *g_dpgettext2 (const gchar *domain,
+ const gchar *context,
+ const gchar *msgid) G_GNUC_FORMAT(3);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]