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] | jpayne@68:[Contents] | jpayne@68:[Index] | 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: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:gettext jpayne@68:
jpayne@68:gettext jpayne@68:
jpayne@68:pot
, po
jpayne@68:
xgettext
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:fpk jpayne@68:
jpayne@68:fp-compiler jpayne@68:
jpayne@68:rst
, rsj
jpayne@68:
xgettext
, rstconv
jpayne@68:
glade, libglade, glade2, libglade2, intltool jpayne@68:
jpayne@68:glade, libglade2-dev, intltool jpayne@68:
jpayne@68:glade
, glade2
, ui
jpayne@68:
xgettext
, libglade-xgettext
, xml-i18n-extract
, intltool-extract
jpayne@68:
glib2 jpayne@68:
jpayne@68:libglib2.0-dev jpayne@68:
jpayne@68:gschema.xml
jpayne@68:
xgettext
, intltool-extract
jpayne@68:
This file format is specified in jpayne@68: https://www.freedesktop.org/software/appstream/docs/. jpayne@68:
jpayne@68:appdata-tools, appstream, libappstream-glib, libappstream-glib-builder jpayne@68:
jpayne@68:appdata-tools, appstream, libappstream-glib-dev jpayne@68:
jpayne@68:appdata.xml
, metainfo.xml
jpayne@68:
xgettext
, intltool-extract
, itstool
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:
This data category associates msgctxt
to the extracted text. In
jpayne@68: the global rule, the contextRule
element contains the following:
jpayne@68:
selector
attribute. It contains an absolute selector
jpayne@68: that selects the nodes to which this rule applies.
jpayne@68:
jpayne@68: contextPointer
attribute that contains a relative
jpayne@68: selector pointing to a node that holds the msgctxt
value.
jpayne@68:
jpayne@68: textPointer
attribute that contains a relative
jpayne@68: selector pointing to a node that holds the msgid
value.
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:
selector
attribute. It contains an absolute selector
jpayne@68: that selects the nodes to which this rule applies.
jpayne@68:
jpayne@68: escape
attribute with the value yes
or no
.
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:
selector
attribute. It contains an absolute selector
jpayne@68: that selects the nodes to which this rule applies.
jpayne@68:
jpayne@68: space
attribute with the value default
,
jpayne@68: preserve
, trim
, or paragraph
.
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:
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: |
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: |
‘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: |
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:
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:
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:
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:
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:
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:These file formats can be used with all of the msg*
tools and with
jpayne@68: the xgettext
program.
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:
po
jpayne@68:
properties
jpayne@68:
strings
jpayne@68:
These file formats can be created through msgfmt
and converted back
jpayne@68: to PO format through msgunfmt
.
jpayne@68:
mo
jpayne@68:
See section The Format of GNU MO Files for details. jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68:class
jpayne@68:
For more information, see the section Java and the examples
jpayne@68: hello-java
, hello-java-awt
, hello-java-swing
.
jpayne@68:
dll
jpayne@68:
For more information, see the section C#. jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68:resources
jpayne@68:
For more information, see the section C#. jpayne@68:
jpayne@68: jpayne@68: jpayne@68: jpayne@68:msg
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:
qm
jpayne@68:
For more information, see the examples hello-c++-qt
and
jpayne@68: hello-c++-kde
.
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:
For more information, see the example hello-c-gnome3
.
jpayne@68:
Icons are generally locale dependent, for the following reasons: jpayne@68:
jpayne@68:However, icons are not covered by GNU gettext localization, because 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:
Icon[locale]=icon_file_name jpayne@68: |
to the template file. jpayne@68:
This line remains in place when this template file is merged with the
jpayne@68: translators' PO files, through msgfmt
.
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: | [Top] | jpayne@68:[Contents] | jpayne@68:[Index] | jpayne@68:[ ? ] | 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: