jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: GNU gettext utilities: 16. Other Data Formats jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:
[ << ][ >> ]           [Top][Contents][Index][ ? ]
jpayne@68: jpayne@68:
jpayne@68: jpayne@68: jpayne@68:

16. Other Data Formats

jpayne@68: jpayne@68:

While the GNU gettext tools deal mainly with POT and PO files, they can jpayne@68: also manipulate a couple of other data formats. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1 Internationalizable Data Formats

jpayne@68: jpayne@68:

Here is a list of other data formats which can be internationalized jpayne@68: using GNU gettext. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1.1 POT - Portable Object Template

jpayne@68: jpayne@68:
jpayne@68:
RPMs
jpayne@68:

gettext jpayne@68:

jpayne@68:
jpayne@68:
Ubuntu packages
jpayne@68:

gettext jpayne@68:

jpayne@68:
jpayne@68:
File extension
jpayne@68:

pot, po jpayne@68:

jpayne@68:
jpayne@68:
Extractor
jpayne@68:

xgettext jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1.2 Resource String Table

jpayne@68: jpayne@68:

RST is the format of resource string table files of the Free Pascal compiler jpayne@68: versions older than 3.0.0. RSJ is the new format of resource string table jpayne@68: files, created by the Free Pascal compiler version 3.0.0 or newer. jpayne@68:

jpayne@68:
jpayne@68:
RPMs
jpayne@68:

fpk jpayne@68:

jpayne@68:
jpayne@68:
Ubuntu packages
jpayne@68:

fp-compiler jpayne@68:

jpayne@68:
jpayne@68:
File extension
jpayne@68:

rst, rsj jpayne@68:

jpayne@68:
jpayne@68:
Extractor
jpayne@68:

xgettext, rstconv jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1.3 Glade - GNOME user interface description

jpayne@68: jpayne@68:
jpayne@68:
RPMs
jpayne@68:

glade, libglade, glade2, libglade2, intltool jpayne@68:

jpayne@68:
jpayne@68:
Ubuntu packages
jpayne@68:

glade, libglade2-dev, intltool jpayne@68:

jpayne@68:
jpayne@68:
File extension
jpayne@68:

glade, glade2, ui jpayne@68:

jpayne@68:
jpayne@68:
Extractor
jpayne@68:

xgettext, libglade-xgettext, xml-i18n-extract, intltool-extract jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1.4 GSettings - GNOME user configuration schema

jpayne@68: jpayne@68:
jpayne@68:
RPMs
jpayne@68:

glib2 jpayne@68:

jpayne@68:
jpayne@68:
Ubuntu packages
jpayne@68:

libglib2.0-dev jpayne@68:

jpayne@68:
jpayne@68:
File extension
jpayne@68:

gschema.xml jpayne@68:

jpayne@68:
jpayne@68:
Extractor
jpayne@68:

xgettext, intltool-extract jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1.5 AppData - freedesktop.org application description

jpayne@68: jpayne@68:

This file format is specified in jpayne@68: https://www.freedesktop.org/software/appstream/docs/. jpayne@68:

jpayne@68:
jpayne@68:
RPMs
jpayne@68:

appdata-tools, appstream, libappstream-glib, libappstream-glib-builder jpayne@68:

jpayne@68:
jpayne@68:
Ubuntu packages
jpayne@68:

appdata-tools, appstream, libappstream-glib-dev jpayne@68:

jpayne@68:
jpayne@68:
File extension
jpayne@68:

appdata.xml, metainfo.xml jpayne@68:

jpayne@68:
jpayne@68:
Extractor
jpayne@68:

xgettext, intltool-extract, itstool jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.1.6 Preparing Rules for XML Internationalization

jpayne@68: jpayne@68:

Marking translatable strings in an XML file is done through a separate jpayne@68: "rule" file, making use of the Internationalization Tag Set standard jpayne@68: (ITS, https://www.w3.org/TR/its20/). The currently supported ITS jpayne@68: data categories are: ‘Translate’, ‘Localization Note’, jpayne@68: ‘Elements Within Text’, and ‘Preserve Space’. In addition to jpayne@68: them, xgettext also recognizes the following extended data jpayne@68: categories: jpayne@68:

jpayne@68:
jpayne@68:
Context
jpayne@68:
jpayne@68:

This data category associates msgctxt to the extracted text. In jpayne@68: the global rule, the contextRule element contains the following: jpayne@68:

jpayne@68: jpayne@68: jpayne@68:
jpayne@68:
Escape Special Characters
jpayne@68:
jpayne@68:

This data category indicates whether the special XML characters jpayne@68: (<, >, &, ") are escaped with entity jpayne@68: reference. In the global rule, the escapeRule element contains jpayne@68: the following: jpayne@68:

jpayne@68: jpayne@68: jpayne@68:
jpayne@68:
Extended Preserve Space
jpayne@68:
jpayne@68:

This data category extends the standard ‘Preserve Space’ data jpayne@68: category with the additional values ‘trim’ and ‘paragraph’. jpayne@68: ‘trim’ means to remove the leading and trailing whitespaces of the jpayne@68: content, but not to normalize whitespaces in the middle. jpayne@68: ‘paragraph’ means to normalize the content but keep the paragraph jpayne@68: boundaries. In the global jpayne@68: rule, the preserveSpaceRule element contains the following: jpayne@68:

jpayne@68: jpayne@68: jpayne@68:
jpayne@68:
jpayne@68: jpayne@68:

All those extended data categories can only be expressed with global jpayne@68: rules, and the rule elements have to have the jpayne@68: https://www.gnu.org/s/gettext/ns/its/extensions/1.0 namespace. jpayne@68:

jpayne@68:

Given the following XML document in a file ‘messages.xml’: jpayne@68:

jpayne@68:
 
<?xml version="1.0"?>
jpayne@68: <messages>
jpayne@68:   <message>
jpayne@68:     <p>A translatable string</p>
jpayne@68:   </message>
jpayne@68:   <message>
jpayne@68:     <p translatable="no">A non-translatable string</p>
jpayne@68:   </message>
jpayne@68: </messages>
jpayne@68: 
jpayne@68: jpayne@68:

To extract the first text content ("A translatable string"), but not the jpayne@68: second ("A non-translatable string"), the following ITS rules can be used: jpayne@68:

jpayne@68:
 
<?xml version="1.0"?>
jpayne@68: <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
jpayne@68:   <its:translateRule selector="/messages" translate="no"/>
jpayne@68:   <its:translateRule selector="//message/p" translate="yes"/>
jpayne@68: 
jpayne@68:   <!-- If 'p' has an attribute 'translatable' with the value 'no', then
jpayne@68:        the content is not translatable.  -->
jpayne@68:   <its:translateRule selector="//message/p[@translatable = 'no']"
jpayne@68:     translate="no"/>
jpayne@68: </its:rules>
jpayne@68: 
jpayne@68: jpayne@68:

xgettext’ needs another file called "locating rule" to associate jpayne@68: an ITS rule with an XML file. If the above ITS file is saved as jpayne@68: ‘messages.its’, the locating rule would look like: jpayne@68:

jpayne@68:
 
<?xml version="1.0"?>
jpayne@68: <locatingRules>
jpayne@68:   <locatingRule name="Messages" pattern="*.xml">
jpayne@68:     <documentRule localName="messages" target="messages.its"/>
jpayne@68:   </locatingRule>
jpayne@68:   <locatingRule name="Messages" pattern="*.msg" target="messages.its"/>
jpayne@68: </locatingRules>
jpayne@68: 
jpayne@68: jpayne@68:

The locatingRule element must have a pattern attribute, jpayne@68: which denotes either a literal file name or a wildcard pattern of the jpayne@68: XML file(7). The locatingRule element can have child jpayne@68: documentRule element, which adds checks on the content of the XML jpayne@68: file. jpayne@68:

jpayne@68:

The first rule matches any file with the ‘.xml’ file extension, but jpayne@68: it only applies to XML files whose root element is ‘<messages>’. jpayne@68:

jpayne@68:

The second rule indicates that the same ITS rule file are also jpayne@68: applicable to any file with the ‘.msg’ file extension. The jpayne@68: optional name attribute of locatingRule allows to choose jpayne@68: rules by name, typically with xgettext's -L option. jpayne@68:

jpayne@68:

The associated ITS rule file is indicated by the target attribute jpayne@68: of locatingRule or documentRule. If it is specified in a jpayne@68: documentRule element, the parent locatingRule shouldn't jpayne@68: have the target attribute. jpayne@68:

jpayne@68:

Locating rule files must have the ‘.loc’ file extension. Both ITS jpayne@68: rule files and locating rule files must be installed in the jpayne@68: ‘$prefix/share/gettext/its’ directory. Once those files are jpayne@68: properly installed, xgettext can extract translatable strings jpayne@68: from the matching XML files. jpayne@68:

jpayne@68: jpayne@68: jpayne@68:

16.1.6.1 Two Use-cases of Translated Strings in XML

jpayne@68: jpayne@68:

For XML, there are two use-cases of translated strings. One is the case jpayne@68: where the translated strings are directly consumed by programs, and the jpayne@68: other is the case where the translated strings are merged back to the jpayne@68: original XML document. In the former case, special characters in the jpayne@68: extracted strings shouldn't be escaped, while they should in the latter jpayne@68: case. To control wheter to escape special characters, the ‘Escape jpayne@68: Special Characters’ data category can be used. jpayne@68:

jpayne@68:

To merge the translations, the ‘msgfmt’ program can be used with jpayne@68: the option --xml. See section Invoking the msgfmt Program, for more details jpayne@68: about how one calls the ‘msgfmt’ program. ‘msgfmt’'s jpayne@68: --xml option doesn't perform character escaping, so translated jpayne@68: strings can have arbitrary XML constructs, such as elements for markup. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2 Localized Data Formats

jpayne@68: jpayne@68:

Here is a list of file formats that contain localized data and that the jpayne@68: GNU gettext tools can manipulate. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.1 Editable Message Catalogs

jpayne@68: jpayne@68:

These file formats can be used with all of the msg* tools and with jpayne@68: the xgettext program. jpayne@68:

jpayne@68:

If you just want to convert among these formats, you can use the jpayne@68: msgcat program (with the appropriate option) or the xgettext jpayne@68: program. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.1.1 PO - Portable Object

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

po jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.1.2 Java .properties

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

properties jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.1.3 NeXTstep/GNUstep .strings

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

strings jpayne@68:

jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2 Compiled Message Catalogs

jpayne@68: jpayne@68:

These file formats can be created through msgfmt and converted back jpayne@68: to PO format through msgunfmt. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2.1 MO - Machine Object

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

mo jpayne@68:

jpayne@68:
jpayne@68: jpayne@68:

See section The Format of GNU MO Files for details. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2.2 Java ResourceBundle

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

class jpayne@68:

jpayne@68:
jpayne@68: jpayne@68:

For more information, see the section Java and the examples jpayne@68: hello-java, hello-java-awt, hello-java-swing. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2.3 C# Satellite Assembly

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

dll jpayne@68:

jpayne@68:
jpayne@68: jpayne@68:

For more information, see the section C#. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2.4 C# Resource

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

resources jpayne@68:

jpayne@68:
jpayne@68: jpayne@68:

For more information, see the section C#. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2.5 Tcl message catalog

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

msg jpayne@68:

jpayne@68:
jpayne@68: jpayne@68:

For more information, see the section Tcl - Tk's scripting language and the examples jpayne@68: hello-tcl, hello-tcl-tk. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.2.6 Qt message catalog

jpayne@68: jpayne@68:
jpayne@68:
File extension
jpayne@68:

qm jpayne@68:

jpayne@68:
jpayne@68: jpayne@68:

For more information, see the examples hello-c++-qt and jpayne@68: hello-c++-kde. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.3 Desktop Entry files

jpayne@68: jpayne@68:

The programmer produces a desktop entry file template with only the jpayne@68: English strings. These strings get included in the POT file, by way of jpayne@68: xgettext (usually by listing the template in po/POTFILES.in). jpayne@68: The translators produce PO files, one for each language. Finally, an jpayne@68: msgfmt --desktop invocation collects all the translations in the jpayne@68: desktop entry file. jpayne@68:

jpayne@68:

For more information, see the example hello-c-gnome3. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.3.1 How to handle icons in Desktop Entry files

jpayne@68: jpayne@68:

Icons are generally locale dependent, for the following reasons: jpayne@68:

jpayne@68: jpayne@68: jpayne@68:

However, icons are not covered by GNU gettext localization, because jpayne@68:

jpayne@68: jpayne@68:

Desktop Entry files may contain an ‘Icon’ property, and this jpayne@68: property is localizable. If a translator wishes to localize an icon, jpayne@68: she should do so by bypassing the normal workflow with PO files: jpayne@68:

    jpayne@68:
  1. jpayne@68: The translator contacts the package developers directly, sending them jpayne@68: the icon appropriate for her locale, with a request to change the jpayne@68: template file. jpayne@68:
  2. jpayne@68: The package developers add the icon file to their repository, and a jpayne@68: line jpayne@68:
     
    Icon[locale]=icon_file_name
    jpayne@68: 
    jpayne@68:

    to the template file. jpayne@68:

jpayne@68:

This line remains in place when this template file is merged with the jpayne@68: translators' PO files, through msgfmt. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68:

16.2.4 XML files

jpayne@68: jpayne@68:

See the section Preparing Rules for XML Internationalization and jpayne@68: Invoking the msgfmt Program, subsection “XML mode operations”. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:
[ << ][ >> ]           [Top][Contents][Index][ ? ]
jpayne@68:

jpayne@68: jpayne@68: This document was generated by Bruno Haible on February, 21 2024 using texi2html 1.78a. jpayne@68: jpayne@68:
jpayne@68: jpayne@68:

jpayne@68: jpayne@68: