6.5 Supporting Locale Options with gettext and intltool


6.5 Supporting Locale Options with gettext and intltool

GNOME uses GNU gettext to support locale. Here is how to use gettext in your program:

  1. Set the configure.ac macros for gettext as described in Section 6.2.2.

  2. Run gettextize and intltoolize in your source tree.

  3. In your source code, enclose all target strings with _() , and all target string constants with N_() :

     const gchar *str_array[] = {   N_("egg"),   N_("miracle"),   N_("drill"), }; g_print("%s\n", _(str_array[i])); 
  4. Change to your po directory and create POTFILES.in , a list of all of the source file names that you changed (relative to your source tree root):

     src/main.c src/aux.c 
  5. Run make prog.pot in your po directory to create a translation template that looks something like this:

     # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2003-07-03 16:51-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/main.c:7 msgid "egg" msgstr "" #: src/main.c:8 msgid "miracle" msgstr "" #: src/main.c:9 msgid "drill" msgstr "" #: src/main.c:15 msgid "strings:\n" msgstr "" 
  6. Edit prog.pot , changing the header lines. Do not change PO-Revision-Date and Last-Translator ; the translator should do this.

  7. Copy prog.pot to locale.po , where locale is the target locale, and fill in the blanks. Here is de.po for the preceding example:

     # Example package. # Copyright (C) 2003 J. Random Developer # This file is distributed under the same license as the example package. # J. Random Developer <jrd@example.com>, 2003. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Example 0.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2003-07-03 16:51-0700\n" "PO-Revision-Date: 2003-07-08 13:32+0100\n" "Last-Translator: J. Zufaelliger Uebersetzer <jzu@example.com>\n" "Language-Team: Example Translator Team <ett@example.com>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: src/main.c:7 msgid "egg" msgstr "Ei" #: src/main.c:8 msgid "miracle" msgstr "Wunder" #: src/main.c:9 msgid "drill" msgstr "Bohrmaschine" #: src/main.c:15 msgid "strings:\n" msgstr "Zeichenketten:\n" 
  8. Make sure that you define the character set as UTF-8.

  9. Rebuild your source tree; make install checks the available translations and puts them in their proper system directory, and the program is ready to use.

As a programmer, you only need to put _(...) and N_(...) into the strings in your code. If your package is popular enough, someone else will probably volunteer to maintain translations.

6.5.1 intltool

gettext supports only C source files, but you can use the same . po files for auxiliary data; for instance, you can use prog.desktop with intltool. Let's say that you want to create miracletext.desktop from Section 6.3:

  1. Rename your miracletext.desktop file to miracletext.desktop.in .

  2. Edit miracletext.desktop.in , adding an underscore to the beginning of each line that you want translated:

     [Desktop Entry] Name=Example _Comment=MiracleText Word Processor _Name=Edit documents with MiracleText TryExec=example << ... >> 
  3. Add miracletext.desktop .in to your po/POTFILES.in file.

  4. Add a set of intltool directives to your top-level Makefile.am . Section 7.3.6 contains an example for a schemas file, and a MIME keys example appears in Section 8.7.2.

  5. Add a rule to remove miracletext.desktop for clean-local in Makefile.am .

  6. Rebuild your source tree.




The Official GNOME 2 Developers Guide
The Official GNOME 2 Developers Guide
ISBN: 1593270305
EAN: 2147483647
Year: 2004
Pages: 108

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net