1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5 >For the Programmer</TITLE
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
15 TITLE="Native Language Support"
18 TITLE="Native Language Support"
21 TITLE="Writing A Procedural Language Handler"
22 HREF="plhandler.html"><LINK
25 HREF="stylesheet.css"><META
27 CONTENT="2003-12-22T03:48:47"></HEAD
33 SUMMARY="Header navigation table"
43 >PostgreSQL 7.4.1 Documentation</TH
67 >Chapter 46. Native Language Support</TD
96 >46.2. For the Programmer</A
104 >46.2.1. Mechanics</A
107 > This section describes how to implement native language support in a
108 program or library that is part of the
113 Currently, it only applies to C programs.
119 >Adding NLS support to a program</B
125 > Insert this code into the start-up sequence of the program:
127 CLASS="PROGRAMLISTING"
129 #include <locale.h>
135 setlocale(LC_ALL, "");
149 > can actually be chosen
155 > Wherever a message that is a candidate for translation is found,
159 > needs to be inserted. E.g.,
161 CLASS="PROGRAMLISTING"
162 >fprintf(stderr, "panic level %d\n", lvl);</PRE
166 CLASS="PROGRAMLISTING"
167 >fprintf(stderr, gettext("panic level %d\n"), lvl);</PRE
172 > is defined as a no-op if no NLS is
176 > This may tend to add a lot of clutter. One common shortcut is to use
178 CLASS="PROGRAMLISTING"
179 >#define _(x) gettext(x)</PRE
181 Another solution is feasible if the program does much of its
182 communication through one or a few functions, such as
186 > in the backend. Then you make this
199 > in the directory with the
200 program sources. This file will be read as a makefile. The
201 following variable assignments need to be made here:
215 > The program name, as provided in the
225 >AVAIL_LANGUAGES</VAR
229 > List of provided translations -- empty in the beginning.
239 > List of files that contain translatable strings, i.e., those
244 solution. Eventually, this will include nearly all source
245 files of the program. If this list gets too long you can
253 and the second word be a file that contains one file name per
260 >GETTEXT_TRIGGERS</VAR
264 > The tools that generate message catalogs for the translators
265 to work on need to know what function calls contain
266 translatable strings. By default, only
270 > calls are known. If you used
274 > or other identifiers you need to list
275 them here. If the translatable string is not the first
276 argument, the item needs to be of the form
280 > (for the second argument).
291 > The build system will automatically take care of building and
292 installing the message catalogs.
300 NAME="NLS-GUIDELINES"
301 >46.2.2. Message-writing guidelines</A
304 > Here are some guidelines for writing messages that are easily
312 > Do not construct sentences at run-time, like
314 CLASS="PROGRAMLISTING"
315 >printf("Files were %s.\n", flag ? "copied" : "removed");</PRE
317 The word order within the sentence may be different in other
318 languages. Also, even if you remember to call gettext() on each
319 fragment, the fragments may not translate well separately. It's
320 better to duplicate a little code so that each message to be
321 translated is a coherent whole. Only numbers, file names, and
322 such-like run-time variables should be inserted at runtime into
328 > For similar reasons, this won't work:
330 CLASS="PROGRAMLISTING"
331 >printf("copied %d file%s", n, n!=1 ? "s" : "");</PRE
333 because it assumes how the plural is formed. If you figured you
334 could solve it like this
336 CLASS="PROGRAMLISTING"
338 printf("copied 1 file");
340 printf("copied %d files", n):</PRE
342 then be disappointed. Some languages have more than two forms,
343 with some peculiar rules. We may have a solution for this in
344 the future, but for now the matter is best avoided altogether.
347 CLASS="PROGRAMLISTING"
348 >printf("number of copied files: %d", n);</PRE
354 > If you want to communicate something to the translator, such as
355 about how a message is intended to line up with other output,
356 precede the occurrence of the string with a comment that starts
362 CLASS="PROGRAMLISTING"
363 >/* translator: This message is not what it seems to be. */</PRE
365 These comments are copied to the message catalog files so that
366 the translators can see them.
379 SUMMARY="Footer navigation table"
408 HREF="plhandler.html"
418 >Native Language Support</TD
432 >Writing A Procedural Language Handler</TD