📄 glib-i18n.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Internationalization</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="prev" href="glib-Data-Checksums.html" title="Data Checksums"><link rel="next" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Data-Checksums.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><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3031121" class="shortcut">Top</a>  |  <a href="#id3031247" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-I18N"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3031121"></a><span class="refentrytitle">Internationalization</span></h2><p>Internationalization — gettext support macros</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h>#include <glib/gi18n.h>#define <a class="link" href="glib-I18N.html#Q-:CAPS">Q_</a> (String)#define <a class="link" href="glib-I18N.html#C-:CAPS">C_</a> (Context,String)#define <a class="link" href="glib-I18N.html#N-:CAPS">N_</a> (String)const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-I18N.html#g-strip-context">g_strip_context</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *msgid, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *msgval);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-I18N.html#g-dpgettext">g_dpgettext</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *domain, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *msgctxtid, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> msgidoffset);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* const * <a class="link" href="glib-I18N.html#g-get-language-names">g_get_language_names</a> (void);</pre></div><div class="refsect1" lang="en"><a name="id3031247"></a><h2>Description</h2><p>GLib doesn't force any particular localization method upon its users.But since GLib itself is localized using the <code class="function">gettext()</code> mechanism, it seemsnatural to offer the de-facto standard <code class="function">gettext()</code> support macros in an easy-to-use form.</p><p>In order to use these macros in an application, you must include <code class="filename">glib/gi18n.h</code>. For use in a library, must include<code class="filename">glib/gi18n-lib.h</code> <span class="emphasis"><em>after</em></span> definingthe 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>The gettext manual covers details of how to set up message extractionwith xgettext.</p></div><div class="refsect1" lang="en"><a name="id3031319"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3031329"></a><h3><a name="Q-:CAPS"></a>Q_()</h3><a class="indexterm" name="id3031343"></a><pre class="programlisting">#define Q_(String)</pre><p>Like <code class="function">_()</code>, but handles context in message ids. 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 translateddifferently 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><p>See the <a class="link" href="glib-I18N.html#C-:CAPS"><code class="function">C_()</code></a> macro for a different way to mark up translatable stringswith context.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you are using the <a class="link" href="glib-I18N.html#Q-:CAPS"><code class="function">Q_()</code></a> macro, you need to make sure that you pass <code class="option">--keyword=Q_</code> to xgettext when extracting messages.If you are using GNU gettext >= 0.15, you can also use<code class="option">--keyword=Q_:1g</code> to let xgettext split the contextstring off into a msgctxt line in the po file.</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>String</code></em> :</span></p></td><td>the string to be translated, with a '|'-separated prefix which must not be translated</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>the translated message</td></tr></tbody></table></div><p class="since">Since 2.4</p></div><hr><div class="refsect2" lang="en"><a name="id3031461"></a><h3><a name="C-:CAPS"></a>C_()</h3><a class="indexterm" name="id3031475"></a><pre class="programlisting">#define C_(Context,String)</pre><p>Uses gettext to get the translation for <em class="parameter"><code>msgid</code></em>. <em class="parameter"><code>msgctxt</code></em> is used as a context. This is mainly useful for short strings which may need different translations, depending on the context in which they are used.</p><div class="informalexample"><pre class="programlisting">label1 = C_("Navigation", "Back");label2 = C_("Body part", "Back");</pre></div><p> </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you are using the <a class="link" href="glib-I18N.html#C-:CAPS"><code class="function">C_()</code></a> macro, you need to make sure that you pass <code class="option">--keyword=C_:1c,2</code> to xgettext when extracting messages. Note that this only works with GNU gettext >= 0.15. </p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>Context</code></em> :</span></p></td><td>a message context, must be a string literal</td></tr><tr><td><p><span class="term"><em class="parameter"><code>String</code></em> :</span></p></td><td>a message id, must be a string literal</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -