<HTML> <HEAD> <!-- This HTML file has been created by texi2html 1.52a from gettext.texi on 6 August 2002 --> <TITLE>GNU gettext utilities - 13 Other Programming Languages</TITLE> </HEAD> <BODY> Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_12.html">previous</A>, <A HREF="gettext_14.html">next</A>, <A HREF="gettext_22.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>. <P><HR><P> <H1><A NAME="SEC199" HREF="gettext_toc.html#TOC199">13 Other Programming Languages</A></H1> <P> While the presentation of <CODE>gettext</CODE> focuses mostly on C and implicitly applies to C++ as well, its scope is far broader than that: Many programming languages, scripting languages and other textual data like GUI resources or package descriptions can make use of the gettext approach. </P> <H2><A NAME="SEC200" HREF="gettext_toc.html#TOC200">13.1 The Language Implementor's View</A></H2> <P> <A NAME="IDX909"></A> <A NAME="IDX910"></A> </P> <P> All programming and scripting languages that have the notion of strings are eligible to supporting <CODE>gettext</CODE>. Supporting <CODE>gettext</CODE> means the following: </P> <OL> <LI> You should add to the language a syntax for translatable strings. In principle, a function call of <CODE>gettext</CODE> would do, but a shorthand syntax helps keeping the legibility of internationalized programs. For example, in C we use the syntax <CODE>_("string")</CODE>, in bash we use the syntax <CODE>$"string"</CODE>, and in GNU awk we use the shorthand <CODE>_"string"</CODE>. <LI> You should arrange that evaluation of such a translatable string at runtime calls the <CODE>gettext</CODE> function, or performs equivalent processing. <LI> Similarly, you should make the functions <CODE>ngettext</CODE>, <CODE>dcgettext</CODE>, <CODE>dcngettext</CODE> available from within the language. These functions are less often used, but are nevertheless necessary for particular purposes: <CODE>ngettext</CODE> for correct plural handling, and <CODE>dcgettext</CODE> and <CODE>dcngettext</CODE> for obeying other locale environment variables than <CODE>LC_MESSAGES</CODE>, such as <CODE>LC_TIME</CODE> or <CODE>LC_MONETARY</CODE>. For these latter functions, you need to make the <CODE>LC_*</CODE> constants, available in the C header <CODE><locale.h></CODE>, referenceable from within the language, usually either as enumeration values or as strings. <LI> You should allow the programmer to designate a message domain, either by making the <CODE>textdomain</CODE> function available from within the language, or by introducing a magic variable called <CODE>TEXTDOMAIN</CODE>. Similarly, you should allow the programmer to designate where to search for message catalogs, by providing access to the <CODE>bindtextdomain</CODE> function. <LI> You should either perform a <CODE>setlocale (LC_ALL, "")</CODE> call during the startup of your language runtime, or allow the programmer to do so. Remember that gettext will act as a no-op if the <CODE>LC_MESSAGES</CODE> and <CODE>LC_CTYPE</CODE> locale facets are not both set. <LI> A programmer should have a way to extract translatable strings from a program into a PO file. The GNU <CODE>xgettext</CODE> program is being extended to support very different programming languages. Please contact the GNU <CODE>gettext</CODE> maintainers to help them doing this. If the string extractor is best integrated into your language's parser, GNU <CODE>xgettext</CODE> can function as a front end to your string extractor. <LI> The language's library should have a string formatting facility where the arguments of a format string are denoted by a positional number or a name. This is needed because for some languages and some messages with more than one substitutable argument, the translation will need to output the substituted arguments in different order. See section <A HREF="gettext_3.html#SEC18">3.5 Special Comments preceding Keywords</A>. <LI> If the language has more than one implementation, and not all of the implementations use <CODE>gettext</CODE>, but the programs should be portable across implementations, you should provide a no-i18n emulation, that makes the other implementations accept programs written for yours, without actually translating the strings. <LI> To help the programmer in the task of marking translatable strings, which is usually performed using the Emacs PO mode, you are welcome to contact the GNU <CODE>gettext</CODE> maintainers, so they can add support for your language to <TT>`po-mode.el´</TT>. </OL> <P> On the implementation side, three approaches are possible, with different effects on portability and copyright: </P> <UL> <LI> You may integrate the GNU <CODE>gettext</CODE>'s <TT>`intl/´</TT> directory in your package, as described in section <A HREF="gettext_12.html#SEC172">12 The Maintainer's View</A>. This allows you to have internationalization on all kinds of platforms. Note that when you then distribute your package, it legally falls under the GNU General Public License, and the GNU project will be glad about your contribution to the Free Software pool. <LI> You may link against GNU <CODE>gettext</CODE> functions if they are found in the C library. For example, an autoconf test for <CODE>gettext()</CODE> and <CODE>ngettext()</CODE> will detect this situation. For the moment, this test will succeed on GNU systems and not on other platforms. No severe copyright restrictions apply. <LI> You may emulate or reimplement the GNU <CODE>gettext</CODE> functionality. This has the advantage of full portability and no copyright restrictions, but also the drawback that you have to reimplement the GNU <CODE>gettext</CODE> features (such as the <CODE>LANGUAGE</CODE> environment variable, the locale aliases database, the automatic charset conversion, and plural handling). </UL> <H2><A NAME="SEC201" HREF="gettext_toc.html#TOC201">13.2 The Programmer's View</A></H2> <P> For the programmer, the general procedure is the same as for the C language. The Emacs PO mode supports other languages, and the GNU <CODE>xgettext</CODE> string extractor recognizes other languages based on the file extension or a command-line option. In some languages, <CODE>setlocale</CODE> is not needed because it is already performed by the underlying language runtime. </P> <H2><A NAME="SEC202" HREF="gettext_toc.html#TOC202">13.3 The Translator's View</A></H2> <P> The translator works exactly as in the C language case. The only difference is that when translating format strings, she has to be aware of the language's particular syntax for positional arguments in format strings. </P> <H3><A NAME="SEC203" HREF="gettext_toc.html#TOC203">13.3.1 C Format Strings</A></H3> <P> C format strings are described in POSIX (IEEE P1003.1 2001), section XSH 3 fprintf(), <A HREF="http://www.opengroup.org/onlinepubs/007904975/functions/fprintf.html">http://www.opengroup.org/onlinepubs/007904975/functions/fprintf.html</A>. See also the fprintf(3) manual page, <A HREF="http://www.linuxvalley.it/encyclopedia/ldp/manpage/man3/printf.3.php">http://www.linuxvalley.it/encyclopedia/ldp/manpage/man3/printf.3.php</A>, <A HREF="http://informatik.fh-wuerzburg.de/student/i510/man/printf.html">http://informatik.fh-wuerzburg.de/student/i510/man/printf.html</A>. </P> <H3><A NAME="SEC204" HREF="gettext_toc.html#TOC204">13.3.2 Python Format Strings</A></H3> <P> Python format strings are described in Python Library reference / 2. Built-in Types, Exceptions and Functions / 2.2. Built-in Types / 2.2.6. Sequence Types / 2.2.6.2. String Formatting Operations. <A HREF="http://www.python.org/doc/2.2.1/lib/typesseq-strings.html">http://www.python.org/doc/2.2.1/lib/typesseq-strings.html</A>. </P> <H3><A NAME="SEC205" HREF="gettext_toc.html#TOC205">13.3.3 Lisp Format Strings</A></H3> <P> Lisp format strings are described in the Common Lisp HyperSpec, chapter 22.3 Formatted Output, <A HREF="http://www.lisp.org/HyperSpec/Body/sec_22-3.html">http://www.lisp.org/HyperSpec/Body/sec_22-3.html</A>. </P> <H3><A NAME="SEC206" HREF="gettext_toc.html#TOC206">13.3.4 Emacs Lisp Format Strings</A></H3> <P> Emacs Lisp format strings are documented in the Emacs Lisp reference, section Formatting Strings, <A HREF="http://www.gnu.org/manual/elisp-manual-21-2.8/html_chapter/elisp_4.html#SEC75">http://www.gnu.org/manual/elisp-manual-21-2.8/html_chapter/elisp_4.html#SEC75</A>. Note that as of version 21, XEmacs supports numbered argument specifications in format strings while FSF Emacs doesn't. </P> <H3><A NAME="SEC207" HREF="gettext_toc.html#TOC207">13.3.5 librep Format Strings</A></H3> <P> librep format strings are documented in the librep manual, section Formatted Output, <A HREF="http://librep.sourceforge.net/librep-manual.html#Formatted%20Output">http://librep.sourceforge.net/librep-manual.html#Formatted%20Output</A>, <A HREF="http://www.gwinnup.org/research/docs/librep.html#SEC122">http://www.gwinnup.org/research/docs/librep.html#SEC122</A>. </P> <H3><A NAME="SEC208" HREF="gettext_toc.html#TOC208">13.3.6 Smalltalk Format Strings</A></H3> <P> Smalltalk format strings are described in the GNU Smalltalk documentation, class <CODE>CharArray</CODE>, methods <SAMP>`bindWith:´</SAMP> and <SAMP>`bindWithArguments:´</SAMP>. <A HREF="http://www.gnu.org/software/smalltalk/gst-manual/gst_68.html#SEC238">http://www.gnu.org/software/smalltalk/gst-manual/gst_68.html#SEC238</A>. In summary, a directive starts with <SAMP>`%´</SAMP> and is followed by <SAMP>`%´</SAMP> or a nonzero digit (<SAMP>`1´</SAMP> to <SAMP>`9´</SAMP>). </P> <H3><A NAME="SEC209" HREF="gettext_toc.html#TOC209">13.3.7 Java Format Strings</A></H3> <P> Java format strings are described in the JDK documentation for class <CODE>java.text.MessageFormat</CODE>, <A HREF="http://java.sun.com/j2se/1.4/docs/api/java/text/MessageFormat.html">http://java.sun.com/j2se/1.4/docs/api/java/text/MessageFormat.html</A>. See also the ICU documentation <A HREF="http://oss.software.ibm.com/icu/apiref/classMessageFormat.html">http://oss.software.ibm.com/icu/apiref/classMessageFormat.html</A>. </P> <H3><A NAME="SEC210" HREF="gettext_toc.html#TOC210">13.3.8 awk Format Strings</A></H3> <P> awk format strings are described in the gawk documentation, section Printf, <A HREF="http://www.gnu.org/manual/gawk/html_node/Printf.html#Printf">http://www.gnu.org/manual/gawk/html_node/Printf.html#Printf</A>. </P> <H3><A NAME="SEC211" HREF="gettext_toc.html#TOC211">13.3.9 Object Pascal Format Strings</A></H3> <P> Where is this documented? </P> <H3><A NAME="SEC212" HREF="gettext_toc.html#TOC212">13.3.10 YCP Format Strings</A></H3> <P> YCP sformat strings are described in the libycp documentation <A HREF="file:/usr/share/doc/packages/libycp/YCP-builtins.html">file:/usr/share/doc/packages/libycp/YCP-builtins.html</A>. In summary, a directive starts with <SAMP>`%´</SAMP> and is followed by <SAMP>`%´</SAMP> or a nonzero digit (<SAMP>`1´</SAMP> to <SAMP>`9´</SAMP>). </P> <H3><A NAME="SEC213" HREF="gettext_toc.html#TOC213">13.3.11 Tcl Format Strings</A></H3> <P> Tcl format strings are described in the <TT>`format.n´</TT> manual page, <A HREF="http://www.scriptics.com/man/tcl8.3/TclCmd/format.htm">http://www.scriptics.com/man/tcl8.3/TclCmd/format.htm</A>. </P> <H2><A NAME="SEC214" HREF="gettext_toc.html#TOC214">13.4 The Maintainer's View</A></H2> <P> For the maintainer, the general procedure differs from the C language case in two ways. </P> <UL> <LI> For those languages that don't use GNU gettext, the <TT>`intl/´</TT> directory is not needed and can be omitted. This means that the maintainer calls the <CODE>gettextize</CODE> program without the <SAMP>`--intl´</SAMP> option, and that he invokes the <CODE>AM_GNU_GETTEXT</CODE> autoconf macro via <SAMP>`AM_GNU_GETTEXT([external])´</SAMP>. <LI> If only a single programming language is used, the <CODE>XGETTEXT_OPTIONS</CODE> variable in <TT>`po/Makevars´</TT> (see section <A HREF="gettext_12.html#SEC179">12.4.3 <TT>`Makefile´</TT> pieces in <TT>`po/´</TT></A>) should be adjusted to match the <CODE>xgettext</CODE> options for that particular programming language. If the package uses more than one programming language with <CODE>gettext</CODE> support, it becomes necessary to change the POT file construction rule in <TT>`po/Makefile.in.in´</TT>. It is recommended to make one <CODE>xgettext</CODE> invocation per programming language, each with the options appropriate for that language, and to combine the resulting files using <CODE>msgcat</CODE>. </UL> <H2><A NAME="SEC215" HREF="gettext_toc.html#TOC215">13.5 Individual Programming Languages</A></H2> <H3><A NAME="SEC216" HREF="gettext_toc.html#TOC216">13.5.1 C, C++, Objective C</A></H3> <P> <A NAME="IDX911"></A> </P> <DL COMPACT> <DT>RPMs <DD> gcc, gpp, gobjc, glibc, gettext <DT>File extension <DD> For C: <CODE>c</CODE>, <CODE>h</CODE>. <BR>For C++: <CODE>C</CODE>, <CODE>c++</CODE>, <CODE>cc</CODE>, <CODE>cxx</CODE>, <CODE>cpp</CODE>, <CODE>hpp</CODE>. <BR>For Objective C: <CODE>m</CODE>. <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>_("abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE>, <CODE>ngettext</CODE>, <CODE>dngettext</CODE>, <CODE>dcngettext</CODE> <DT>textdomain <DD> <CODE>textdomain</CODE> function <DT>bindtextdomain <DD> <CODE>bindtextdomain</CODE> function <DT>setlocale <DD> Programmer must call <CODE>setlocale (LC_ALL, "")</CODE> <DT>Prerequisite <DD> <CODE>#include <libintl.h></CODE> <BR><CODE>#include <locale.h></CODE> <BR><CODE>#define _(string) gettext (string)</CODE> <DT>Use or emulate GNU gettext <DD> Use <DT>Extractor <DD> <CODE>xgettext -k_</CODE> <DT>Formatting with positions <DD> <CODE>fprintf "%2$d %1$d"</CODE> (POSIX but not C 99) <DT>Portability <DD> autoconf (gettext.m4) and #if ENABLE_NLS <DT>po-mode marking <DD> yes </DL> <H3><A NAME="SEC217" HREF="gettext_toc.html#TOC217">13.5.2 sh - Shell Script</A></H3> <P> <A NAME="IDX912"></A> </P> <DL COMPACT> <DT>RPMs <DD> bash, gettext <DT>File extension <DD> <CODE>sh</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE>, <CODE>'abc'</CODE>, <CODE>abc</CODE> <DT>gettext shorthand <DD> <CODE>"`gettext "abc"`"</CODE> <DT>gettext/ngettext functions <DD> <A NAME="IDX913"></A> <A NAME="IDX914"></A> <CODE>gettext</CODE>, <CODE>ngettext</CODE> programs <DT>textdomain <DD> <A NAME="IDX915"></A> environment variable <CODE>TEXTDOMAIN</CODE> <DT>bindtextdomain <DD> <A NAME="IDX916"></A> environment variable <CODE>TEXTDOMAINDIR</CODE> <DT>setlocale <DD> automatic <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> --- <DT>Formatting with positions <DD> --- <DT>Portability <DD> --- <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC218" HREF="gettext_toc.html#TOC218">13.5.3 bash - Bourne-Again Shell Script</A></H3> <P> <A NAME="IDX917"></A> </P> <DL COMPACT> <DT>RPMs <DD> bash 2.0 or newer, gettext <DT>File extension <DD> <CODE>sh</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE>, <CODE>'abc'</CODE>, <CODE>abc</CODE> <DT>gettext shorthand <DD> <CODE>$"abc"</CODE> <DT>gettext/ngettext functions <DD> <A NAME="IDX918"></A> <A NAME="IDX919"></A> <CODE>gettext</CODE>, <CODE>ngettext</CODE> programs <DT>textdomain <DD> <A NAME="IDX920"></A> environment variable <CODE>TEXTDOMAIN</CODE> <DT>bindtextdomain <DD> <A NAME="IDX921"></A> environment variable <CODE>TEXTDOMAINDIR</CODE> <DT>setlocale <DD> automatic <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> <CODE>bash --dump-po-strings</CODE> <DT>Formatting with positions <DD> --- <DT>Portability <DD> --- <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC219" HREF="gettext_toc.html#TOC219">13.5.4 Python</A></H3> <P> <A NAME="IDX922"></A> </P> <DL COMPACT> <DT>RPMs <DD> python <DT>File extension <DD> <CODE>py</CODE> <DT>String syntax <DD> <CODE>'abc'</CODE>, <CODE>u'abc'</CODE>, <CODE>r'abc'</CODE>, <CODE>ur'abc'</CODE>, <BR><CODE>"abc"</CODE>, <CODE>u"abc"</CODE>, <CODE>r"abc"</CODE>, <CODE>ur"abc"</CODE>, <BR><CODE>"'abc"'</CODE>, <CODE>u"'abc"'</CODE>, <CODE>r"'abc"'</CODE>, <CODE>ur"'abc"'</CODE>, <BR><CODE>"""abc"""</CODE>, <CODE>u"""abc"""</CODE>, <CODE>r"""abc"""</CODE>, <CODE>ur"""abc"""</CODE> <DT>gettext shorthand <DD> <CODE>_('abc')</CODE> etc. <DT>gettext/ngettext functions <DD> <CODE>gettext.gettext</CODE>, <CODE>gettext.dgettext</CODE>, also <CODE>ugettext</CODE> <DT>textdomain <DD> <CODE>gettext.textdomain</CODE> function, or <CODE>gettext.install(<VAR>domain</VAR>)</CODE> function <DT>bindtextdomain <DD> <CODE>gettext.bindtextdomain</CODE> function, or <CODE>gettext.install(<VAR>domain</VAR>,<VAR>localedir</VAR>)</CODE> function <DT>setlocale <DD> not used by the gettext emulation <DT>Prerequisite <DD> <CODE>import gettext</CODE> <DT>Use or emulate GNU gettext <DD> emulate. Bug: uses only the first found .mo file, not all of them <DT>Extractor <DD> <CODE>xgettext</CODE> <DT>Formatting with positions <DD> <CODE>'...%(ident)d...' % { 'ident': value }</CODE> <DT>Portability <DD> fully portable <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC220" HREF="gettext_toc.html#TOC220">13.5.5 GNU clisp - Common Lisp</A></H3> <P> <A NAME="IDX923"></A> <A NAME="IDX924"></A> <A NAME="IDX925"></A> </P> <DL COMPACT> <DT>RPMs <DD> clisp 2.28 or newer <DT>File extension <DD> <CODE>lisp</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>(_ "abc")</CODE>, <CODE>(ENGLISH "abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>i18n:gettext</CODE>, <CODE>i18n:ngettext</CODE> <DT>textdomain <DD> <CODE>i18n:textdomain</CODE> <DT>bindtextdomain <DD> <CODE>i18n:textdomaindir</CODE> <DT>setlocale <DD> automatic <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> <CODE>xgettext -k_ -kENGLISH</CODE> <DT>Formatting with positions <DD> <CODE>format "~1@*~D ~0@*~D"</CODE> <DT>Portability <DD> On platforms without gettext, no translation. <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC221" HREF="gettext_toc.html#TOC221">13.5.6 GNU clisp C sources</A></H3> <P> <A NAME="IDX926"></A> </P> <DL COMPACT> <DT>RPMs <DD> clisp <DT>File extension <DD> <CODE>d</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>ENGLISH ? "abc" : ""</CODE> <BR><CODE>GETTEXT("abc")</CODE> <BR><CODE>GETTEXTL("abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>clgettext</CODE>, <CODE>clgettextl</CODE> <DT>textdomain <DD> --- <DT>bindtextdomain <DD> --- <DT>setlocale <DD> automatic <DT>Prerequisite <DD> <CODE>#include "lispbibl.c"</CODE> <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> <CODE>clisp-xgettext</CODE> <DT>Formatting with positions <DD> <CODE>fprintf "%2$d %1$d"</CODE> (POSIX but not C 99) <DT>Portability <DD> On platforms without gettext, no translation. <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC222" HREF="gettext_toc.html#TOC222">13.5.7 Emacs Lisp</A></H3> <P> <A NAME="IDX927"></A> </P> <DL COMPACT> <DT>RPMs <DD> emacs, xemacs <DT>File extension <DD> <CODE>el</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>(_"abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>gettext</CODE>, <CODE>dgettext</CODE> (xemacs only) <DT>textdomain <DD> <CODE>domain</CODE> special form (xemacs only) <DT>bindtextdomain <DD> <CODE>bind-text-domain</CODE> function (xemacs only) <DT>setlocale <DD> automatic <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> <CODE>xgettext</CODE> <DT>Formatting with positions <DD> <CODE>format "%2$d %1$d"</CODE> <DT>Portability <DD> Only XEmacs. Without <CODE>I18N3</CODE> defined at build time, no translation. <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC223" HREF="gettext_toc.html#TOC223">13.5.8 librep</A></H3> <P> <A NAME="IDX928"></A> </P> <DL COMPACT> <DT>RPMs <DD> librep 0.15.3 or newer <DT>File extension <DD> <CODE>jl</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>(_"abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>gettext</CODE> <DT>textdomain <DD> <CODE>textdomain</CODE> function <DT>bindtextdomain <DD> <CODE>bindtextdomain</CODE> function <DT>setlocale <DD> --- <DT>Prerequisite <DD> <CODE>(require 'rep.i18n.gettext)</CODE> <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> <CODE>xgettext</CODE> <DT>Formatting with positions <DD> <CODE>format "%2$d %1$d"</CODE> <DT>Portability <DD> On platforms without gettext, no translation. <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC224" HREF="gettext_toc.html#TOC224">13.5.9 GNU Smalltalk</A></H3> <P> <A NAME="IDX929"></A> </P> <DL COMPACT> <DT>RPMs <DD> smalltalk <DT>File extension <DD> <CODE>st</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>NLS? "abc"</CODE> <BR><CODE>self? "abc"</CODE> <DT>gettext/ngettext functions <DD> <CODE>LcMessagesDomain>>#at:</CODE>, <CODE>LcMessagesDomain>>#at:plural:with:</CODE> <DT>textdomain <DD> <CODE>LcMessages>>#?</CODE> (returns a <CODE>LcMessagesDomain</CODE> object).<BR> Example: <CODE>Locale default messages ? 'gettext'</CODE> <DT>bindtextdomain <DD> <CODE>LcMessages>>#domain:directory:</CODE> (returns a <CODE>LcMessagesDomain</CODE> object) <DT>setlocale <DD> You can obtain any <CODE>Locale</CODE> object from <CODE>Locale</CODE> class methods such as <CODE>#fromString:</CODE> or <CODE>#default</CODE>.<BR> Example: <CODE>Locale default messages</CODE> gives the <CODE>LcMessages</CODE> object for the default locale. <DT>Prerequisite <DD> The gettext code is contained in the <TT>`I18N´</TT> package. <DT>Use or emulate GNU gettext <DD> emulate <DT>Extractor <DD> --- <DT>Formatting with positions <DD> <CODE>'%1 %2' bindWith: 'Hello' with: 'world'</CODE> <DT>Portability <DD> fully portable <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC225" HREF="gettext_toc.html#TOC225">13.5.10 Java</A></H3> <P> <A NAME="IDX930"></A> </P> <DL COMPACT> <DT>RPMs <DD> java, java2 <DT>File extension <DD> <CODE>java</CODE> <DT>String syntax <DD> "abc" <DT>gettext shorthand <DD> _("abc") <DT>gettext/ngettext functions <DD> <CODE>GettextResource.gettext</CODE>, <CODE>GettextResource.ngettext</CODE> <DT>textdomain <DD> ---, use <CODE>ResourceBundle.getResource</CODE> instead <DT>bindtextdomain <DD> ---, use CLASSPATH instead <DT>setlocale <DD> automatic <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> ---, uses a Java specific message catalog format <DT>Extractor <DD> <CODE>xgettext -k_</CODE> <DT>Formatting with positions <DD> <CODE>MessageFormat.format "{1,number} {0,number}"</CODE> <DT>Portability <DD> fully portable <DT>po-mode marking <DD> --- </DL> <P> Before marking strings as internationalizable, uses of the string concatenation operator need to be converted to <CODE>MessageFormat</CODE> applications. For example, <CODE>"file "+filename+" not found"</CODE> becomes <CODE>MessageFormat.format("file {0} not found", new Object[] { filename })</CODE>. Only after this is done, can the strings be marked and extracted. </P> <P> GNU gettext uses the native Java internationalization mechanism, namely <CODE>ResourceBundle</CODE>s. To convert a PO file to a ResourceBundle, the <CODE>msgfmt</CODE> program can be used with the option <CODE>--java</CODE> or <CODE>--java2</CODE>. To convert a ResourceBundle back to a PO file, the <CODE>msgunfmt</CODE> program can be used with the option <CODE>--java</CODE>. </P> <P> Two different programmatic APIs can be used to access ResourceBundles. Note that both APIs work with all kinds of ResourceBundles, whether GNU gettext generated classes, or other <CODE>.class</CODE> or <CODE>.properties</CODE> files. </P> <OL> <LI> The <CODE>java.util.ResourceBundle</CODE> API. In particular, its <CODE>getString</CODE> function returns a string translation. Note that a missing translation yields a <CODE>MissingResourceException</CODE>. This has the advantage of being the standard API. And it does not require any additional libraries, only the <CODE>msgfmt</CODE> generated <CODE>.class</CODE> files. But it cannot do plural handling, even if the resource was generated from a PO file with plural handling. <LI> The <CODE>gnu.gettext.GettextResource</CODE> API. Reference documentation in Javadoc 1.1 style format is in the <A HREF="javadoc1/tree.html">javadoc1 directory</A> and in Javadoc 2 style format in the <A HREF="javadoc2/index.html">javadoc2 directory</A>. Its <CODE>gettext</CODE> function returns a string translation. Note that when a translation is missing, the <VAR>msgid</VAR> argument is returned unchanged. This has the advantage of having the <CODE>ngettext</CODE> function for plural handling. <A NAME="IDX931"></A> To use this API, one needs the <CODE>libintl.jar</CODE> file which is part of the GNU gettext package and distributed under the LGPL. </OL> <H3><A NAME="SEC226" HREF="gettext_toc.html#TOC226">13.5.11 GNU awk</A></H3> <P> <A NAME="IDX932"></A> <A NAME="IDX933"></A> </P> <DL COMPACT> <DT>RPMs <DD> gawk 3.1 or newer <DT>File extension <DD> <CODE>awk</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>_"abc"</CODE> <DT>gettext/ngettext functions <DD> <CODE>dcgettext</CODE>, missing <CODE>dcngettext</CODE> in gawk-3.1.0 <DT>textdomain <DD> <CODE>TEXTDOMAIN</CODE> variable <DT>bindtextdomain <DD> <CODE>bindtextdomain</CODE> function <DT>setlocale <DD> automatic, but missing <CODE>setlocale (LC_MESSAGES, "")</CODE> in gawk-3.1.0 <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> <CODE>xgettext</CODE> <DT>Formatting with positions <DD> <CODE>printf "%2$d %1$d"</CODE> (GNU awk only) <DT>Portability <DD> On platforms without gettext, no translation. On non-GNU awks, you must define <CODE>dcgettext</CODE>, <CODE>dcngettext</CODE> and <CODE>bindtextdomain</CODE> yourself. <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC227" HREF="gettext_toc.html#TOC227">13.5.12 Pascal - Free Pascal Compiler</A></H3> <P> <A NAME="IDX934"></A> <A NAME="IDX935"></A> <A NAME="IDX936"></A> </P> <DL COMPACT> <DT>RPMs <DD> fpk <DT>File extension <DD> <CODE>pp</CODE>, <CODE>pas</CODE> <DT>String syntax <DD> <CODE>'abc'</CODE> <DT>gettext shorthand <DD> automatic <DT>gettext/ngettext functions <DD> ---, use <CODE>ResourceString</CODE> data type instead <DT>textdomain <DD> ---, use <CODE>TranslateResourceStrings</CODE> function instead <DT>bindtextdomain <DD> ---, use <CODE>TranslateResourceStrings</CODE> function instead <DT>setlocale <DD> automatic, but uses only LANG, not LC_MESSAGES or LC_ALL <DT>Prerequisite <DD> <CODE>{$mode delphi}</CODE> or <CODE>{$mode objfpc}</CODE><BR><CODE>uses gettext;</CODE> <DT>Use or emulate GNU gettext <DD> emulate partially <DT>Extractor <DD> <CODE>ppc386</CODE> followed by <CODE>xgettext</CODE> or <CODE>rstconv</CODE> <DT>Formatting with positions <DD> <CODE>uses sysutils;</CODE><BR><CODE>format "%1:d %0:d"</CODE> <DT>Portability <DD> ? <DT>po-mode marking <DD> --- </DL> <P> The Pascal compiler has special support for the <CODE>ResourceString</CODE> data type. It generates a <CODE>.rst</CODE> file. This is then converted to a <CODE>.pot</CODE> file by use of <CODE>xgettext</CODE> or <CODE>rstconv</CODE>. At runtime, a <CODE>.mo</CODE> file corresponding to translations of this <CODE>.pot</CODE> file can be loaded using the <CODE>TranslateResourceStrings</CODE> function in the <CODE>gettext</CODE> unit. </P> <H3><A NAME="SEC228" HREF="gettext_toc.html#TOC228">13.5.13 wxWindows library</A></H3> <P> <A NAME="IDX937"></A> </P> <DL COMPACT> <DT>RPMs <DD> wxGTK, gettext <DT>File extension <DD> <CODE>cpp</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>_("abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>wxLocale::GetString</CODE>, <CODE>wxGetTranslation</CODE> <DT>textdomain <DD> <CODE>wxLocale::AddCatalog</CODE> <DT>bindtextdomain <DD> <CODE>wxLocale::AddCatalogLookupPathPrefix</CODE> <DT>setlocale <DD> <CODE>wxLocale::Init</CODE>, <CODE>wxSetLocale</CODE> <DT>Prerequisite <DD> <CODE>#include <wx/intl.h></CODE> <DT>Use or emulate GNU gettext <DD> emulate, see <CODE>include/wx/intl.h</CODE> and <CODE>src/common/intl.cpp</CODE> <DT>Extractor <DD> <CODE>xgettext</CODE> <DT>Formatting with positions <DD> --- <DT>Portability <DD> fully portable <DT>po-mode marking <DD> yes </DL> <H3><A NAME="SEC229" HREF="gettext_toc.html#TOC229">13.5.14 YCP - YaST2 scripting language</A></H3> <P> <A NAME="IDX938"></A> <A NAME="IDX939"></A> </P> <DL COMPACT> <DT>RPMs <DD> libycp, libycp-devel, yast2-core-translator <DT>File extension <DD> <CODE>ycp</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>_("abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>_()</CODE> with 1 or 3 arguments <DT>textdomain <DD> <CODE>textdomain</CODE> statement <DT>bindtextdomain <DD> --- <DT>setlocale <DD> --- <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use maps instead <DT>Extractor <DD> <CODE>xgettext</CODE> <DT>Formatting with positions <DD> <CODE>sformat "%2 %1"</CODE> <DT>Portability <DD> fully portable <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC230" HREF="gettext_toc.html#TOC230">13.5.15 Tcl - Tk's scripting language</A></H3> <P> <A NAME="IDX940"></A> <A NAME="IDX941"></A> </P> <DL COMPACT> <DT>RPMs <DD> tcl <DT>File extension <DD> <CODE>tcl</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>[_ "abc"]</CODE> <DT>gettext/ngettext functions <DD> <CODE>::msgcat::mc</CODE> <DT>textdomain <DD> --- <DT>bindtextdomain <DD> ---, use <CODE>::msgcat::mcload</CODE> instead <DT>setlocale <DD> automatic, uses LANG, but ignores LC_MESSAGES and LC_ALL <DT>Prerequisite <DD> <CODE>package require msgcat</CODE> <BR><CODE>proc _ {s} {return [::msgcat::mc $s]}</CODE> <DT>Use or emulate GNU gettext <DD> ---, uses a Tcl specific message catalog format <DT>Extractor <DD> <CODE>xgettext -k_</CODE> <DT>Formatting with positions <DD> <CODE>format "%2\$d %1\$d"</CODE> <DT>Portability <DD> fully portable <DT>po-mode marking <DD> --- </DL> <P> Before marking strings as internationalizable, substitutions of variables into the string need to be converted to <CODE>format</CODE> applications. For example, <CODE>"file $filename not found"</CODE> becomes <CODE>[format "file %s not found" $filename]</CODE>. Only after this is done, can the strings be marked and extracted. After marking, this example becomes <CODE>[format [_ "file %s not found"] $filename]</CODE> or <CODE>[msgcat::mc "file %s not found" $filename]</CODE>. Note that the <CODE>msgcat::mc</CODE> function implicitly calls <CODE>format</CODE> when more than one argument is given. </P> <H3><A NAME="SEC231" HREF="gettext_toc.html#TOC231">13.5.16 Perl</A></H3> <P> <A NAME="IDX942"></A> </P> <DL COMPACT> <DT>RPMs <DD> perl, perl-gettext <DT>File extension <DD> <CODE>pl</CODE>, <CODE>PL</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> --- <DT>gettext/ngettext functions <DD> <CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE> <DT>textdomain <DD> <CODE>textdomain</CODE> function <DT>bindtextdomain <DD> <CODE>bindtextdomain</CODE> function <DT>setlocale <DD> Use <CODE>setlocale (LC_ALL, "");</CODE> <DT>Prerequisite <DD> <CODE>use POSIX;</CODE> <BR><CODE>use Locale::gettext;</CODE> <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> ? <DT>Formatting with positions <DD> --- <DT>Portability <DD> ? <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC232" HREF="gettext_toc.html#TOC232">13.5.17 PHP Hypertext Preprocessor</A></H3> <P> <A NAME="IDX943"></A> </P> <DL COMPACT> <DT>RPMs <DD> mod_php4, phplib, phpdoc <DT>File extension <DD> <CODE>php</CODE>, <CODE>php3</CODE>, <CODE>php4</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> <CODE>_("abc")</CODE> <DT>gettext/ngettext functions <DD> <CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE> <DT>textdomain <DD> <CODE>textdomain</CODE> function <DT>bindtextdomain <DD> <CODE>bindtextdomain</CODE> function <DT>setlocale <DD> <CODE>setlocale</CODE> function <DT>Prerequisite <DD> --- <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> --- <DT>Formatting with positions <DD> --- <DT>Portability <DD> On platforms without gettext, the functions are not available. <DT>po-mode marking <DD> --- </DL> <H3><A NAME="SEC233" HREF="gettext_toc.html#TOC233">13.5.18 Pike</A></H3> <P> <A NAME="IDX944"></A> </P> <DL COMPACT> <DT>RPMs <DD> roxen <DT>File extension <DD> <CODE>pike</CODE> <DT>String syntax <DD> <CODE>"abc"</CODE> <DT>gettext shorthand <DD> --- <DT>gettext/ngettext functions <DD> <CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE> <DT>textdomain <DD> <CODE>textdomain</CODE> function <DT>bindtextdomain <DD> <CODE>bindtextdomain</CODE> function <DT>setlocale <DD> <CODE>setlocale</CODE> function <DT>Prerequisite <DD> <CODE>import Locale.Gettext;</CODE> <DT>Use or emulate GNU gettext <DD> use <DT>Extractor <DD> --- <DT>Formatting with positions <DD> --- <DT>Portability <DD> On platforms without gettext, the functions are not available. <DT>po-mode marking <DD> --- </DL> <H2><A NAME="SEC234" HREF="gettext_toc.html#TOC234">13.6 Internationalizable Data</A></H2> <P> Here is a list of other data formats which can be internationalized using GNU gettext. </P> <H3><A NAME="SEC235" HREF="gettext_toc.html#TOC235">13.6.1 POT - Portable Object Template</A></H3> <DL COMPACT> <DT>RPMs <DD> gettext <DT>File extension <DD> <CODE>pot</CODE>, <CODE>po</CODE> <DT>Extractor <DD> <CODE>xgettext</CODE> </DL> <H3><A NAME="SEC236" HREF="gettext_toc.html#TOC236">13.6.2 Resource String Table</A></H3> <P> <A NAME="IDX945"></A> </P> <DL COMPACT> <DT>RPMs <DD> fpk <DT>File extension <DD> <CODE>rst</CODE> <DT>Extractor <DD> <CODE>xgettext</CODE>, <CODE>rstconv</CODE> </DL> <H3><A NAME="SEC237" HREF="gettext_toc.html#TOC237">13.6.3 Glade - GNOME user interface description</A></H3> <DL COMPACT> <DT>RPMs <DD> glade, libglade, xml-i18n-tools <DT>File extension <DD> <CODE>glade</CODE> <DT>Extractor <DD> <CODE>xgettext</CODE>, <CODE>libglade-xgettext</CODE> </DL> <P><HR><P> Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_12.html">previous</A>, <A HREF="gettext_14.html">next</A>, <A HREF="gettext_22.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>. </BODY> </HTML>