📄 glib-i18n.html
字号:
<html xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Internationalization</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><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-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="next" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><meta name="generator" content="GTK-Doc V1.4 (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"></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 class="refnamediv"><table width="100%"><tr><td valign="top"><h2><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 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)const <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);const <a href="glib-Basic-Types.html#gchar">gchar</a>* const * <a href="glib-I18N.html#g-get-language-names">g_get_language_names</a> (void);</pre></div><div class="refsect1" lang="en"><a name="id2987082"></a><h2>Description</h2><p>GLib doesn't force any particular localization method upon its users.But since GLib itself is localized using the <ahref="../libbonobo/libbonobo-bonobo-i18n.html#gettext"><code class="function">gettext()</code></a> mechanism, it seemsnatural to offer the de-facto standard <ahref="../libbonobo/libbonobo-bonobo-i18n.html#gettext"><code class="function">gettext()</code></a> 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></p></div><div class="refsect1" lang="en"><a name="id2987147"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2987153"></a><h3><a name="gettext-macro"></a>_()</h3><a class="indexterm" name="id2987163"></a><pre class="programlisting">#define _(String)</pre><p>Marks a string for translation, gets replaced with the translated stringat runtime.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>String</code></em> :</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="id2987203"></a><h3><a name="Q-:CAPS"></a>Q_()</h3><a class="indexterm" name="id2987213"></a><pre class="programlisting">#define Q_(String)</pre><p>Like <a href="glib-I18N.html#gettext-macro"><code class="function">_()</code></a>, but applies <a href="glib-I18N.html#g-strip-context"><code class="function">g_strip_context()</code></a> to the translation. This has theadvantage 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><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>String</code></em> :</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="id2987285"></a><h3><a name="N-:CAPS"></a>N_()</h3><a class="indexterm" name="id2987295"></a><pre class="programlisting">#define N_(String)</pre><p>Marks a string for translation, gets replaced with the untranslated stringat runtime. This is useful in situations where the translated strings can'tbe 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"><em class="parameter"><code>String</code></em> :</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="id2987354"></a><h3><a name="g-strip-context"></a>g_strip_context ()</h3><a class="indexterm" name="id2987364"></a><pre class="programlisting">const <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 <ahref="../libbonobo/libbonobo-bonobo-i18n.html#gettext"><code class="function">gettext()</code></a> support (see <a href="glib-I18N.html#Q-:CAPS"><code class="function">Q_()</code></a>).</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>msgid</code></em> :</span></td><td> a string</td></tr><tr><td><span class="term"><em class="parameter"><code>msgval</code></em> :</span></td><td> another string</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <em class="parameter"><code>msgval</code></em>, unless <em class="parameter"><code>msgval</code></em> is identical to <em class="parameter"><code>msgid</code></em> 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><hr><div class="refsect2" lang="en"><a name="id2987492"></a><h3><a name="g-get-language-names"></a>g_get_language_names ()</h3><a class="indexterm" name="id2987504"></a><pre class="programlisting">const <a href="glib-Basic-Types.html#gchar">gchar</a>* const * g_get_language_names (void);</pre><p>Computes a list of applicable locale names, which can be used to e.g. construct locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale "C".</p><p>For example, if LANGUAGE=de:en_US, then the returned list is"de", "en_US", "en", "C".</p><p>This function consults the environment variables <code class="envar">LANGUAGE</code>, <code class="envar">LC_ALL</code>, <code class="envar">LC_MESSAGES</code> and <code class="envar">LANG</code> to find the list of locales specified by the user.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a <code class="literal">NULL</code>-terminated array of strings owned by GLib that must not be modified or freed.</td></tr></tbody></table></div><p>Since 2.6</p></div></div><div class="refsect1" lang="en"><a name="id2987585"></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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -