Translating Metadata | AppStream | AppStream 1.0
Description: 5.4.1 Introduction # Most AppStream metadata can be translated, This page contains some practical instructions how to translate the metadata. 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 …

Jump to content Jump to page navigation: previous page [access key p]/next page [access key n]
AppStream
AppStream › Metadata Quickstart › Translating Metadata
AppStream › Metadata Quickstart › Translating Metadata
Top
←→

## 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: 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 Itstool #

One good way to translate MetaInfo files besides using plain Gettext is using Itstool for translation. In order to translate an XML file with it, you need an `.its` file with translation definitions. This file is installed with Gettext, but a more recent version is also shipped by AppStream, so make sure `appstream` itself is installed to get more complete translations.

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

    itstool -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 -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

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

#### 5.4.2.1 Integrating with Meson #

First add your MetaInfo file to your `POTFILES.in` file and use Gettext for extraction of translatable elements:

    i18n = import('i18n')

    i18n_result = i18n.gettext(gettext_domain,
        preset : 'glib',
    )

To then apply the translated data to the MetaInfo XML file, you can use the built-in `itstool_join` function:

    metainfo_dir = join_paths(get_option ('datadir'), 'metainfo')

    metainfo_i18n = i18n.itstool_join(
        input:  'org.example.myapp.metainfo.xml',
        output: 'org.example.myapp.metainfo.xml',
        mo_targets: i18n_result[0],
        install: true,
        install_dir: metainfo_dir,
    )