<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Internationalization</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="previous" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="next" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="refentry" href="glib-building.html" title="Compiling the GLib package"><link rel="refentry" href="glib-cross-compiling.html" title="Cross-compiling the GLib package"><link rel="refentry" href="glib-compiling.html" title="Compiling GLib Applications"><link rel="refentry" href="glib-running.html" title="Running GLib Applications"><link rel="refentry" href="glib-changes.html" title="Changes to GLib"><link rel="refentry" href="glib-resources.html" title="Mailing lists and bug reports"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="refentry" href="glib-Basic-Types.html" title="Basic Types"><link rel="refentry" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types"><link rel="refentry" href="glib-Standard-Macros.html" title="Standard Macros"><link rel="refentry" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros"><link rel="refentry" href="glib-Byte-Order-Macros.html" title="Byte Order Macros"><link rel="refentry" href="glib-Numerical-Definitions.html" title="Numerical Definitions"><link rel="refentry" href="glib-Miscellaneous-Macros.html" title="Miscellaneous Macros"><link rel="refentry" href="glib-Atomic-Operations.html" title="Atomic Operations"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="refentry" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop"><link rel="refentry" href="glib-Threads.html" title=" Threads"><link rel="refentry" href="glib-Thread-Pools.html" title="Thread Pools"><link rel="refentry" href="glib-Asynchronous-Queues.html" title="Asynchronous Queues"><link rel="refentry" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules"><link rel="refentry" href="glib-Memory-Allocation.html" title="Memory Allocation"><link rel="refentry" href="glib-IO-Channels.html" title="IO Channels"><link rel="refentry" href="glib-Error-Reporting.html" title="Error Reporting"><link rel="refentry" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions"><link rel="refentry" href="glib-Message-Logging.html" title="Message Logging"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="refentry" href="glib-String-Utility-Functions.html" title="String Utility Functions"><link rel="refentry" href="glib-Character-Set-Conversion.html" title="Character Set Conversion"><link rel="refentry" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="refentry" href="glib-I18N.html" title="Internationalization"><link rel="refentry" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="refentry" href="glib-Random-Numbers.html" title="Random Numbers"><link rel="refentry" href="glib-Hook-Functions.html" title="Hook Functions"><link rel="refentry" href="glib-Miscellaneous-Utility-Functions.html" title="Miscellaneous Utility Functions"><link rel="refentry" href="glib-Lexical-Scanner.html" title="Lexical Scanner"><link rel="refentry" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><link rel="refentry" href="glib-Timers.html" title="Timers"><link rel="refentry" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="refentry" href="glib-File-Utilities.html" title="File Utilities"><link rel="refentry" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities"><link rel="refentry" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching"><link rel="refentry" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser"><link rel="refentry" href="glib-Windows-Compatability-Functions.html" title="Windows Compatibility Functions"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="refentry" href="glib-Memory-Chunks.html" title="Memory Chunks"><link rel="refentry" href="glib-Doubly-Linked-Lists.html" title="Doubly-Linked Lists"><link rel="refentry" href="glib-Singly-Linked-Lists.html" title="Singly-Linked Lists"><link rel="refentry" href="glib-Double-ended-Queues.html" title="Double-ended Queues"><link rel="refentry" href="glib-Trash-Stacks.html" title="Trash Stacks"><link rel="refentry" href="glib-Hash-Tables.html" title="Hash Tables"><link rel="refentry" href="glib-Strings.html" title="Strings"><link rel="refentry" href="glib-String-Chunks.html" title="String Chunks"><link rel="refentry" href="glib-Arrays.html" title="Arrays"><link rel="refentry" href="glib-Pointer-Arrays.html" title="Pointer Arrays"><link rel="refentry" href="glib-Byte-Arrays.html" title="Byte Arrays"><link rel="refentry" href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees"><link rel="refentry" href="glib-N-ary-Trees.html" title="N-ary Trees"><link rel="refentry" href="glib-Quarks.html" title="Quarks"><link rel="refentry" href="glib-Keyed-Data-Lists.html" title="Keyed Data Lists"><link rel="refentry" href="glib-Datasets.html" title="Datasets"><link rel="refentry" href="glib-Relations-and-Tuples.html" title="Relations and Tuples"><link rel="refentry" href="glib-Caches.html" title="Caches"><link rel="refentry" href="glib-Memory-Allocators.html" title="Memory Allocators"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="refentry" href="glib-gettextize.html" title="glib-gettextize"><link rel="index" href="ix01.html" title="Index"><link rel="section" href="glib-I18N.html#id3147253" title="Description"><link rel="section" href="glib-I18N.html#id3147319" title="Details"><link rel="section" href="glib-I18N.html#id3147666" title="See Also"><meta name="generator" content="GTK-Doc V1.2 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Unicode-Manipulation.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Date-and-Time-Functions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-I18N"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2><span class="refentrytitle">Internationalization</span></h2><p>Internationalization — gettext support macros.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis"> #include <glib.h> #include <glib/gi18n.h> #define <a href="glib-I18N.html#gettext-macro">_</a> (String) #define <a href="glib-I18N.html#Q--CAPS">Q_</a> (String) #define <a href="glib-I18N.html#N--CAPS">N_</a> (String) G_CONST_RETURN <a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-I18N.html#g-strip-context">g_strip_context</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *msgid, const <a href="glib-Basic-Types.html#gchar">gchar</a> *msgval); </pre></div><div class="refsect1" lang="en"><a name="id3147253"></a><h2>Description</h2><p> GLib doesn't force any particular localization method upon its users. But since GLib itself is localized using the <tt class="function">gettext()</tt> mechanism, it seems natural to offer the de-facto standard <tt class="function">gettext()</tt> support macros in an easy-to-use form. </p><p> In order to use these macros in an application, you must include <tt class="filename">glib/gi18n.h</tt>. For use in a library, must include <tt class="filename">glib/gi18n-lib.h</tt> <span class="emphasis"><em>after</em></span> defining the GETTEXT_PACKAGE macro suitably for your library: </p><div class="informalexample"><pre class="programlisting"> #define GETTEXT_PACKAGE "gtk20" #include <glib/gi18n-lib.h> </pre></div><p> </p></div><div class="refsect1" lang="en"><a name="id3147319"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3147324"></a><h3><a name="gettext-macro"></a>_()</h3><a class="indexterm" name="id3147335"></a><pre class="programlisting">#define _(String)</pre><p> Marks a string for translation, gets replaced with the translated string at runtime. </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>String</tt></i> :</span></td><td>the string to be translated </td></tr></tbody></table></div><p>Since 2.4 </p></div><hr><div class="refsect2" lang="en"><a name="id3147374"></a><h3><a name="Q--CAPS"></a>Q_()</h3><a class="indexterm" name="id3147385"></a><pre class="programlisting">#define Q_(String)</pre><p> Like <a href="glib-I18N.html#gettext-macro"><tt class="function">_()</tt></a>, but applies <a href="glib-I18N.html#g-strip-context"><tt class="function">g_strip_context()</tt></a> to the translation. This has the advantage that the string can be adorned with a prefix to guarantee uniqueness and provide context to the translator. </p><p> One use case given in the gettext manual is GUI translation, where one could e.g. disambiguate two "Open" menu entries as "File|Open" and "Printer|Open". Another use case is the string "Russian" which may have to be translated differently depending on whether it's the name of a character set or a language. This could be solved by using "charset|Russian" and "language|Russian". </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>String</tt></i> :</span></td><td>the string to be translated, with a '|'-separated prefix which must not be translated </td></tr></tbody></table></div><p>Since 2.4 </p></div><hr><div class="refsect2" lang="en"><a name="id3147457"></a><h3><a name="N--CAPS"></a>N_()</h3><a class="indexterm" name="id3147468"></a><pre class="programlisting">#define N_(String)</pre><p> Marks a string for translation, gets replaced with the untranslated string at runtime. This is useful in situations where the translated strings can't be directly used, e.g. in string array initializers. </p><div class="informalexample"><pre class="programlisting"> { static const char *messages[] = { N_("some very meaningful message"), N_("and another one") }; const char *string; ... string = index > 1 ? _("a default message") : gettext (messages[index]); fputs (string); ... } </pre></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>String</tt></i> :</span></td><td>the string to be translated </td></tr></tbody></table></div><p>Since 2.4 </p></div><hr><div class="refsect2" lang="en"><a name="id3147526"></a><h3><a name="g-strip-context"></a>g_strip_context ()</h3><a class="indexterm" name="id3147537"></a><pre class="programlisting">G_CONST_RETURN <a href="glib-Basic-Types.html#gchar">gchar</a>* g_strip_context (const <a href="glib-Basic-Types.html#gchar">gchar</a> *msgid, const <a href="glib-Basic-Types.html#gchar">gchar</a> *msgval);</pre><p> An auxiliary function for <tt class="function">gettext()</tt> support (see <a href="glib-I18N.html#Q--CAPS"><tt class="function">Q_()</tt></a>).</p><p> </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>msgid</tt></i> :</span></td><td> a string </td></tr><tr><td><span class="term"><i class="parameter"><tt>msgval</tt></i> :</span></td><td> another string </td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <i class="parameter"><tt>msgval</tt></i>, unless <i class="parameter"><tt>msgval</tt></i> is identical to <i class="parameter"><tt>msgid</tt></i> and contains a '|' character, in which case a pointer to the substring of msgid after the first '|' character is returned. </td></tr></tbody></table></div><p>Since 2.4 </p></div></div><div class="refsect1" lang="en"><a name="id3147666"></a><h2>See Also</h2><p> The gettext manual. </p></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Unicode-Manipulation.html"><b><< Unicode Manipulation</b></a></td><td align="right"><a accesskey="n" href="glib-Date-and-Time-Functions.html"><b>Date and Time Functions >></b></a></td></tr></table></body></html>