1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Internationalization</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
<link rel="prev" href="glib-Data-HMACs.html" title="Secure HMAC Digests">
<link rel="next" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions">
<meta name="generator" content="GTK-Doc V1.19 (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" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Data-HMACs.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">
<a href="#glib-I18N.synopsis" class="shortcut">Top</a>
|
<a href="#glib-I18N.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry">
<a name="glib-I18N"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="glib-I18N.top_of_page"></a>Internationalization</span></h2>
<p>Internationalization — gettext support macros</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="glib-I18N.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include <glib.h>
#include <glib/gi18n.h>
#define <a class="link" href="glib-I18N.html#gettext-macro" title="_()">_</a> (String)
#define <a class="link" href="glib-I18N.html#Q-:CAPS" title="Q_()">Q_</a> (String)
#define <a class="link" href="glib-I18N.html#C-:CAPS" title="C_()">C_</a> (Context,
String)
#define <a class="link" href="glib-I18N.html#N-:CAPS" title="N_()">N_</a> (String)
#define <a class="link" href="glib-I18N.html#NC-:CAPS" title="NC_()">NC_</a> (Context,
String)
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()">g_dgettext</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>);
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-I18N.html#g-dcgettext" title="g_dcgettext ()">g_dcgettext</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> category</code></em>);
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-I18N.html#g-dngettext" title="g_dngettext ()">g_dngettext</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid_plural</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gulong" title="gulong"><span class="type">gulong</span></a> n</code></em>);
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-I18N.html#g-dpgettext" title="g_dpgettext ()">g_dpgettext</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgctxtid</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gsize" title="gsize"><span class="type">gsize</span></a> msgidoffset</code></em>);
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-I18N.html#g-dpgettext2" title="g_dpgettext2 ()">g_dpgettext2</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *context</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>);
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-I18N.html#g-strip-context" title="g_strip_context ()">g_strip_context</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgval</code></em>);
const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * const * <a class="link" href="glib-I18N.html#g-get-language-names" title="g_get_language_names ()">g_get_language_names</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
<a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> ** <a class="link" href="glib-I18N.html#g-get-locale-variants" title="g_get_locale_variants ()">g_get_locale_variants</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *locale</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="glib-I18N.description"></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 seems
natural 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, you must include
<code class="filename">glib/gi18n-lib.h</code> <span class="emphasis"><em>after</em></span> defining
the GETTEXT_PACKAGE macro suitably for your library:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="preproc">#define</span><span class="normal"> GETTEXT_PACKAGE </span><span class="string">"gtk20"</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string"><glib/gi18n-lib.h></span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
For an application, note that you also have to call <code class="function">bindtextdomain()</code>,
<code class="function">bind_textdomain_codeset()</code>, <code class="function">textdomain()</code> and <a class="link" href="glib-running.html#setlocale" title="Locale"><code class="function">setlocale()</code></a> early on in your
<code class="function">main()</code> to make <code class="function">gettext()</code> work.
</p>
<p>
For a library, you only have to call <code class="function">bindtextdomain()</code> and
<code class="function">bind_textdomain_codeset()</code> in your initialization function. If your library
doesn't have an initialization function, you can call the functions before
the first translated message.
</p>
<p>
The gettext manual covers details of how to set up message extraction
with xgettext.
</p>
</div>
<div class="refsect1">
<a name="glib-I18N.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="gettext-macro"></a><h3>_()</h3>
<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" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>String</code></em> :</span></p></td>
<td>the string to be translated</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.4</p>
</div>
<hr>
<div class="refsect2">
<a name="Q-:CAPS"></a><h3>Q_()</h3>
<pre class="programlisting">#define Q_(String)</pre>
<p>
Like <a class="link" href="glib-I18N.html#gettext-macro" title="_()"><code class="function">_()</code></a>, 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 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>
<p>
See the <a class="link" href="glib-I18N.html#C-:CAPS" title="C_()"><code class="function">C_()</code></a> macro for a different way to mark up translatable strings
with context.
</p>
<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#Q-:CAPS" title="Q_()"><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 context
string off into a msgctxt line in the po file.</p>
</div>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<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">
<a name="C-:CAPS"></a><h3>C_()</h3>
<pre class="programlisting">#define C_(Context,String)</pre>
<p>
Uses gettext to get the translation for <em class="parameter"><code>String</code></em>. <em class="parameter"><code>Context</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">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="normal">label1 </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-I18N.html#C-:CAPS">C_</a></span><span class="symbol">(</span><span class="string">"Navigation"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Back"</span><span class="symbol">);</span>
<span class="normal">label2 </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-I18N.html#C-:CAPS">C_</a></span><span class="symbol">(</span><span class="string">"Body part"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Back"</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<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" title="C_()"><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>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<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>
<td>the translated message</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.16</p>
</div>
<hr>
<div class="refsect2">
<a name="N-:CAPS"></a><h3>N_()</h3>
<pre class="programlisting">#define N_(String)</pre>
<p>
Only marks a string for translation. 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, call <code class="function">gettext()</code>
at runtime.
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="cbracket">{</span>
<span class="normal"> </span><span class="keyword">static</span><span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="type">char</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">messages</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="function"><a href="glib-I18N.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"some very meaningful message"</span><span class="symbol">),</span>
<span class="normal"> </span><span class="function"><a href="glib-I18N.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"and another one"</span><span class="symbol">)</span>
<span class="normal"> </span><span class="cbracket">}</span><span class="symbol">;</span>
<span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="type">char</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">string</span><span class="symbol">;</span>
<span class="normal"> </span><span class="symbol">...</span>
<span class="normal"> string</span>
<span class="normal"> </span><span class="symbol">=</span><span class="normal"> index </span><span class="symbol">></span><span class="normal"> </span><span class="number">1</span><span class="normal"> </span><span class="symbol">?</span><span class="normal"> </span><span class="function"><a href="glib-I18N.html#gettext-macro">_</a></span><span class="symbol">(</span><span class="string">"a default message"</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">:</span><span class="normal"> </span><span class="function">gettext</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">messages</span><span class="symbol">[</span><span class="normal">index</span><span class="symbol">]);</span>
<span class="normal"> </span><span class="function">fputs</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">string</span><span class="symbol">);</span>
<span class="normal"> </span><span class="symbol">...</span>
<span class="cbracket">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>String</code></em> :</span></p></td>
<td>the string to be translated</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.4</p>
</div>
<hr>
<div class="refsect2">
<a name="NC-:CAPS"></a><h3>NC_()</h3>
<pre class="programlisting">#define NC_(Context, String)</pre>
<p>
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 <a class="link" href="glib-I18N.html#g-dpgettext2" title="g_dpgettext2 ()"><code class="function">g_dpgettext2()</code></a> at runtime.
</p>
<p>
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="cbracket">{</span>
<span class="normal"> </span><span class="keyword">static</span><span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="type">char</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">messages</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="function"><a href="glib-I18N.html#NC-:CAPS">NC_</a></span><span class="symbol">(</span><span class="string">"some context"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"some very meaningful message"</span><span class="symbol">),</span>
<span class="normal"> </span><span class="function"><a href="glib-I18N.html#NC-:CAPS">NC_</a></span><span class="symbol">(</span><span class="string">"some context"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"and another one"</span><span class="symbol">)</span>
<span class="normal"> </span><span class="cbracket">}</span><span class="symbol">;</span>
<span class="normal"> </span><span class="keyword">const</span><span class="normal"> </span><span class="type">char</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">string</span><span class="symbol">;</span>
<span class="normal"> </span><span class="symbol">...</span>
<span class="normal"> string</span>
<span class="normal"> </span><span class="symbol">=</span><span class="normal"> index </span><span class="symbol">></span><span class="normal"> </span><span class="number">1</span><span class="normal"> </span><span class="symbol">?</span><span class="normal"> </span><span class="function"><a href="glib-I18N.html#g-dpgettext2">g_dpgettext2</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="string">"some context"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"a default message"</span><span class="symbol">)</span>
<span class="normal"> </span><span class="symbol">:</span><span class="normal"> </span><span class="function"><a href="glib-I18N.html#g-dpgettext2">g_dpgettext2</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="string">"some context"</span><span class="symbol">,</span><span class="normal"> messages</span><span class="symbol">[</span><span class="normal">index</span><span class="symbol">]);</span>
<span class="normal"> </span><span class="function">fputs</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">string</span><span class="symbol">);</span>
<span class="normal"> </span><span class="symbol">...</span>
<span class="cbracket">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<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#NC-:CAPS" title="NC_()"><code class="function">NC_()</code></a> macro, you need to make sure
that you pass <code class="option">--keyword=NC_:1c,2</code> to xgettext when
extracting messages. Note that this only works with GNU gettext >= 0.15.
Intltool has support for the <a class="link" href="glib-I18N.html#NC-:CAPS" title="NC_()"><code class="function">NC_()</code></a> macro since version 0.40.1.
</p>
</div>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<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>
</tbody>
</table></div>
<p class="since">Since 2.18</p>
</div>
<hr>
<div class="refsect2">
<a name="g-dgettext"></a><h3>g_dgettext ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_dgettext (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>);</pre>
<p>
This function is a wrapper of <code class="function">dgettext()</code> which does not translate
the message if the default domain as set with <code class="function">textdomain()</code> has no
translations for the current locale.
</p>
<p>
The advantage of using this function over <code class="function">dgettext()</code> proper is that
libraries using this function (like GTK+) will not use translations
if the application using the library does not have translations for
the current locale. This results in a consistent English-only
interface instead of one having partial translations. For this
feature to work, the call to <code class="function">textdomain()</code> and <a class="link" href="glib-running.html#setlocale" title="Locale"><code class="function">setlocale()</code></a> should
precede any <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> invocations. For GTK+, it means calling
<code class="function">textdomain()</code> before gtk_init or its variants.
</p>
<p>
This function disables translations if and only if upon its first
call all the following conditions hold:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<em class="parameter"><code>domain</code></em> is not <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
</li>
<li class="listitem">
<code class="function">textdomain()</code> has been called to set a default text domain</li>
<li class="listitem">there is no translations available for the default text domain
and the current locale</li>
<li class="listitem">current locale is not "C" or any English locales (those
starting with "en_")</li>
</ul></div>
<p>
</p>
<p>
Note that this behavior may not be desired for example if an application
has its untranslated messages in a language other than English. In those
cases the application should call <code class="function">textdomain()</code> after initializing GTK+.
</p>
<p>
Applications should normally not use this function directly,
but use the <a class="link" href="glib-I18N.html#gettext-macro" title="_()"><code class="function">_()</code></a> macro for translations.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>the translation domain to use, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to use
the domain set with <code class="function">textdomain()</code>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgid</code></em> :</span></p></td>
<td>message to translate</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The translated string</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.18</p>
</div>
<hr>
<div class="refsect2">
<a name="g-dcgettext"></a><h3>g_dcgettext ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_dcgettext (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> category</code></em>);</pre>
<p>
This is a variant of <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> that allows specifying a locale
category instead of always using <code class="envar">LC_MESSAGES</code>. See <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> for
more information about how this functions differs from calling
<code class="function">dcgettext()</code> directly.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>the translation domain to use, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to use
the domain set with <code class="function">textdomain()</code>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgid</code></em> :</span></p></td>
<td>message to translate</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>category</code></em> :</span></p></td>
<td>a locale category</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the translated string for the given locale category</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.26</p>
</div>
<hr>
<div class="refsect2">
<a name="g-dngettext"></a><h3>g_dngettext ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_dngettext (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid_plural</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gulong" title="gulong"><span class="type">gulong</span></a> n</code></em>);</pre>
<p>
This function is a wrapper of <code class="function">dngettext()</code> which does not translate
the message if the default domain as set with <code class="function">textdomain()</code> has no
translations for the current locale.
</p>
<p>
See <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> for details of how this differs from <code class="function">dngettext()</code>
proper.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>the translation domain to use, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to use
the domain set with <code class="function">textdomain()</code>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgid</code></em> :</span></p></td>
<td>message to translate</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgid_plural</code></em> :</span></p></td>
<td>plural form of the message</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n</code></em> :</span></p></td>
<td>the quantity for which translation is needed</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The translated string</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.18</p>
</div>
<hr>
<div class="refsect2">
<a name="g-dpgettext"></a><h3>g_dpgettext ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_dpgettext (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgctxtid</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gsize" title="gsize"><span class="type">gsize</span></a> msgidoffset</code></em>);</pre>
<p>
This function is a variant of <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> which supports
a disambiguating message context. GNU gettext uses the
'\004' character to separate the message context and
message id in <em class="parameter"><code>msgctxtid</code></em>.
If 0 is passed as <em class="parameter"><code>msgidoffset</code></em>, this function will fall back to
trying to use the deprecated convention of using "|" as a separation
character.
</p>
<p>
This uses <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> internally. See that functions for differences
with <code class="function">dgettext()</code> proper.
</p>
<p>
Applications should normally not use this function directly,
but use the <a class="link" href="glib-I18N.html#C-:CAPS" title="C_()"><code class="function">C_()</code></a> macro for translations with context.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>the translation domain to use, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to use
the domain set with <code class="function">textdomain()</code>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgctxtid</code></em> :</span></p></td>
<td>a combined message context and message id, separated
by a \004 character</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgidoffset</code></em> :</span></p></td>
<td>the offset of the message id in <em class="parameter"><code>msgctxid</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The translated string</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.16</p>
</div>
<hr>
<div class="refsect2">
<a name="g-dpgettext2"></a><h3>g_dpgettext2 ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_dpgettext2 (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *domain</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *context</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>);</pre>
<p>
This function is a variant of <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> which supports
a disambiguating message context. GNU gettext uses the
'\004' character to separate the message context and
message id in <em class="parameter"><code>msgctxtid</code></em>.
</p>
<p>
This uses <a class="link" href="glib-I18N.html#g-dgettext" title="g_dgettext ()"><code class="function">g_dgettext()</code></a> internally. See that functions for differences
with <code class="function">dgettext()</code> proper.
</p>
<p>
This function differs from <a class="link" href="glib-I18N.html#C-:CAPS" title="C_()"><code class="function">C_()</code></a> in that it is not a macro and
thus you may use non-string-literals as context and msgid arguments.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>the translation domain to use, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to use
the domain set with <code class="function">textdomain()</code>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
<td>the message context</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgid</code></em> :</span></p></td>
<td>the message</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The translated string</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.18</p>
</div>
<hr>
<div class="refsect2">
<a name="g-strip-context"></a><h3>g_strip_context ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_strip_context (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgid</code></em>,
<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *msgval</code></em>);</pre>
<p>
An auxiliary function for <code class="function">gettext()</code> support (see <a class="link" href="glib-I18N.html#Q-:CAPS" title="Q_()"><code class="function">Q_()</code></a>).
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgid</code></em> :</span></p></td>
<td>a string</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msgval</code></em> :</span></p></td>
<td>another string</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></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 class="since">Since 2.4</p>
</div>
<hr>
<div class="refsect2">
<a name="g-get-language-names"></a><h3>g_get_language_names ()</h3>
<pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * const * g_get_language_names (<em class="parameter"><code><span class="type">void</span></code></em>);</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>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>-terminated array of strings owned by GLib
that must not be modified or freed. <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> zero-terminated=1][<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span>
</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.6</p>
</div>
<hr>
<div class="refsect2">
<a name="g-get-locale-variants"></a><h3>g_get_locale_variants ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> ** g_get_locale_variants (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *locale</code></em>);</pre>
<p>
Returns a list of derived variants of <em class="parameter"><code>locale</code></em>, 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.
This function handles territory, charset and extra locale modifiers.
</p>
<p>
For example, if <em class="parameter"><code>locale</code></em> is "fr_BE", then the returned list
is "fr_BE", "fr".
</p>
<p>
If you need the list of variants for the <span class="emphasis"><em>current locale</em></span>,
use <a class="link" href="glib-I18N.html#g-get-language-names" title="g_get_language_names ()"><code class="function">g_get_language_names()</code></a>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>locale</code></em> :</span></p></td>
<td>a locale identifier</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a newly
allocated array of newly allocated strings with the locale variants. Free with
<a class="link" href="glib-String-Utility-Functions.html#g-strfreev" title="g_strfreev ()"><code class="function">g_strfreev()</code></a>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>][<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> zero-terminated=1][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> utf8]</span>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
</div>
<div class="refsect1">
<a name="glib-I18N.see-also"></a><h2>See Also</h2>
the gettext manual
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.19</div>
</body>
</html>
|