Jump to contentJump to page navigation: previous page [access key p]/next page [access key n]

5.4 Translating Metadata

5.4.1 Introduction

Most AppStream metadata can be translated, This page contains some practical instructions how to translate the metadata.

Note
Note: For KDE developers

If you are a KDE developer and using the KDE infrastructure with it's localization support, you need to do nothing to get translated metadata. Just place your *.metainfo.xml* (or *.appdata.xml* file) at a sane place, and the l10n-script will translate the file in-place automatically.

5.4.2 Translating using Intltool

If you ship an .xml.in file rather than an .xml file, you can use Intltool to translate the data.

Each translatable element in the .xml.in file needs to be prefixed with an underscore (_) to be marked as translatable. This should include the name, summary, and caption tags, as well as each paragraph in the description. Apart from that, the same specifications apply to this file as for any other AppStream metadata.

To translate the appstream data, first add the .xml.in file to po/POTFILES.in, along with any other translatable files. Then create the translation template file <package name>.pot.

cd po; intltool-update --pot --gettext-package=<package name>

For each supported language, copy the template file to po/<language>-[<COUNTRY>].po, where po/<language> and the optional po/<COUNTRY> are standard two-letter codes. Edit the file to add translated strings.

As the translatable content is updated, recreate the template file, and update the .po files.

cd po; intltool-update --dist --gettext-package=<package name> <language>

Create the translated .xml with the following command.

intltool-merge -u -c ./po/.intltool-merge-cache ./po -x <file>.xml.in <file>.xml

5.4.2.1 Integrating with Autotools (the AppStream way)

The generic way to add translation to your AppStream metadata in case you use Autotools is by using the following code snippet:

appstreamdir = $(datadir)/metainfo/
appstream_in_files = gedit.metainfo.xml.in
appstream_DATA = $(appstream_in_files:.xml.in=.xml)
@INTLTOOL_XML_RULE@
EXTRA_DIST = $(metainfo_in_files)
CLEANFILES = $(appstream_DATA)

The code assumes you are using the Intltool Automake code.

5.4.2.2 Integrating with Autotools (the AppStream-GLib way)

In case you want to use the macro provided by the AppStream-GLib library, you can use this code snippet:

@APPSTREAM_XML_RULES@
appstream_in_files = gedit.metainfo.xml.in
appstream_XML = $(appstream_in_files:.xml.in=.xml)
@INTLTOOL_XML_RULE@
EXTRA_DIST = $(metainfo_in_files)
CLEANFILES = $(appstream_XML)

Make sure you have the additional AppStream macro installed.

5.4.3 Translating using Itstool

You can also use Itstool for translation. In order to translate an XML file with it, you need an .its file with translation definitions. An appropriate file for AppStream upstream metadata of any kind can be found here:

<its:rules
  xmlns:its="http://www.w3.org/2005/11/its"
  version="1.0">
  <its:translateRule translate="no" selector="/component"/>
  <its:translateRule translate="yes"
    selector="/component/name | /component/summary |
    /component/description | /component/screenshots/screenshot/caption | /component/developer_name"/>
</its:rules>

Save this file as as-metainfo.its for example.

To extract a GNU Gettext .pot file from your XML file, run itstool with the follwing arguments (replacing "foo" with your project name):

itstool -i as-metainfo.its -o $podir/foo_metadata.pot data/foo.metainfo.xml

You can then translate the .pot file using the standard methods for translating files like these. You obtain .po files, which you can convert into .mo files (using msgfmt) like you would do with any other localization. Then, you need to call itstool again, to create a translated version of the original XML file:

itstool -i as-metainfo.its -j data/foo.metainfo.xml -o output/foo.metainfo.xml $modir/*.mo

Please ensure that the .mo files in $modir are named with their language codes.

Note
Note

You can find more information about Itstool on their homepage (http://itstool.org/).