Sophie

Sophie

distrib > Mageia > 6 > armv7hl > by-pkgid > 302473efd5d8804d45197576e257a9ed > files > 218

libappstream-devel-0.11.8-1.mga6.armv7hl.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title xmlns:d="http://docbook.org/ns/docbook">4.4. Translating Metadata</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta xmlns:d="http://docbook.org/ns/docbook" name="generator" content="publican v4.3.2" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="AppStream-AppStream-0.11-en-US-0.0-0" /><link rel="home" href="index.html" title="AppStream" /><link rel="up" href="chap-Quickstart.html" title="Chapter 4. Metadata Quickstart" /><link rel="prev" href="sect-Quickstart-Distros.html" title="4.3. For distributors packaging Appstream metadata" /><link rel="next" href="chap-AppStream-Services.html" title="Chapter 5. Services" /></head><body><p id="title"><a class="left" href="http://www.freedesktop.org/wiki/Distributions/AppStream/"><img alt="Product Site" src="Common_Content/images//image_left.png" /></a><a class="right" href="http://www.freedesktop.org/software/appstream/docs/"><img alt="Documentation Site" src="Common_Content/images//image_right.png" /></a></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="sect-Quickstart-Distros.html"><strong>Prev</strong></a></li><li class="home">AppStream</li><li class="next"><a accesskey="n" href="chap-AppStream-Services.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" lang="en-US"><div class="titlepage"><div><div><h2 class="title"><a id="sect-Quickstart-Translation">
      ⁠</a>4.4. Translating Metadata</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="qsr-l10n-introduction">
      ⁠</a>4.4.1. Introduction</h3></div></div></div><div class="para">
			Most AppStream metadata can be translated, This page contains some practical instructions how to translate the metadata.
		</div><div xmlns:d="http://docbook.org/ns/docbook" class="note"><div class="admonition_header"><p><strong>For KDE developers</strong></p></div><div class="admonition"><div class="para">
				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 <code class="filename">*.appdata.xml*</code> or <code class="filename">*.metainfo.xml*</code> file at a sane place, and the l10n-script will translate the file in-place automatically.
			</div></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="qsr-l10n-intltool">
      ⁠</a>4.4.2. Translating using Intltool</h3></div></div></div><div class="para">
			If you ship an <code class="filename">.xml.in</code> file rather than an <code class="filename">.xml</code> file, you can use Intltool to translate the data.
		</div><div class="para">
			Each translatable element in the <code class="filename">.xml.in</code> file needs to be prefixed with an underscore (<code class="code">_</code>) to be marked as translatable. This should include the <code class="code">name</code>, <code class="code">summary</code>, and <code class="code">caption</code> tags, as well as each paragraph in the <code class="code">description</code>. Apart from that, the same specifications apply to this file as for any other AppStream metadata.
		</div><div class="para">
			To translate the appstream data, first add the <code class="filename">.xml.in</code> file to <code class="filename">po/POTFILES.in</code>, along with any other translatable files. Then create the translation template file <code class="filename">&lt;package name&gt;.pot</code>.
		</div><pre class="programlisting"><span xmlns="" class="line">​</span><span xmlns="" class="perl_Reserved">cd</span> po; intltool-update --pot --gettext-package=<span xmlns="" class="perl_Operator">&lt;</span>package name<span xmlns="" class="perl_Operator">&gt;</span></pre><div class="para">
			For each supported language, copy the template file to <code class="filename">po/&lt;language&gt;-[&lt;COUNTRY&gt;].po</code>, where <code class="filename">po/&lt;language&gt;</code> and the optional <code class="filename">po/&lt;COUNTRY&gt;</code> are standard two-letter codes. Edit the file to add translated strings.
		</div><div class="para">
			As the translatable content is updated, recreate the template file, and update the <code class="filename">.po</code> files.
		</div><pre class="programlisting"><span xmlns="" class="line">​</span><span xmlns="" class="perl_Reserved">cd</span> po; intltool-update --dist --gettext-package=<span xmlns="" class="perl_Operator">&lt;</span>package name<span xmlns="" class="perl_Operator">&gt;</span> <span xmlns="" class="perl_Operator">&lt;</span>language<span xmlns="" class="perl_Operator">&gt;</span></pre><div class="para">
			Create the translated <code class="filename">.xml</code> with the following command.
		</div><pre class="programlisting"><span xmlns="" class="line">​</span>intltool-merge -u -c ./po/.intltool-merge-cache ./po -x <span xmlns="" class="perl_Operator">&lt;</span><span xmlns="" class="perl_BString">file</span><span xmlns="" class="perl_Operator">&gt;</span>.xml.<span xmlns="" class="perl_Keyword">in</span> <span xmlns="" class="perl_Operator">&lt;</span><span xmlns="" class="perl_BString">file</span><span xmlns="" class="perl_Operator">&gt;</span>.xml</pre><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="qsr-l10n-intltool-autotools">
      ⁠</a>4.4.2.1. Integrating with Autotools (the AppStream way)</h4></div></div></div><div class="para">
				The generic way to add translation to your AppStream metadata in case you use Autotools is by using the following code snippet:
			</div><pre class="programlisting"><span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">appstreamdir </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">datadir</span><span xmlns="" class="perl_Char">)</span><span xmlns="" class="perl_String">/appdata/</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">appstream_in_files </span><span xmlns="" class="perl_String">= gedit.appdata.xml.in</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">appstream_DATA </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">appstream_in_files:.xml.in=.xml</span><span xmlns="" class="perl_Char">)</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Char">@</span><span xmlns="" class="perl_BaseN">INTLTOOL_XML_RULE</span>@
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">EXTRA_DIST </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">appdata_in_files</span><span xmlns="" class="perl_Char">)</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">CLEANFILES </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">appstream_DATA</span><span xmlns="" class="perl_Char">)</span></pre><div class="para">
				The code assumes you are using the Intltool Automake code.
			</div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="qsr-l10n-intltool-autotools-asglib">
      ⁠</a>4.4.2.2. Integrating with Autotools (the AppStream-GLib way)</h4></div></div></div><div class="para">
				In case you want to use the macro provided by the AppStream-GLib library, you can use this code snippet:
			</div><pre class="programlisting"><span xmlns="" class="line">​</span><span xmlns="" class="perl_Char">@</span><span xmlns="" class="perl_BaseN">APPSTREAM_XML_RULES</span>@
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">appstream_in_files </span><span xmlns="" class="perl_String">= gedit.appdata.xml.in</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">appstream_XML </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">appstream_in_files:.xml.in=.xml</span><span xmlns="" class="perl_Char">)</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Char">@</span><span xmlns="" class="perl_BaseN">INTLTOOL_XML_RULE</span>@
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">EXTRA_DIST </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">appdata_in_files</span><span xmlns="" class="perl_Char">)</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_DataType">CLEANFILES </span><span xmlns="" class="perl_String">= </span><span xmlns="" class="perl_Char">$(</span><span xmlns="" class="perl_DataType">appstream_XML</span><span xmlns="" class="perl_Char">)</span></pre><div class="para">
				Make sure you have the additional AppStream macro installed.
			</div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="qsr-l10n-itstool">
      ⁠</a>4.4.3. Translating using Itstool</h3></div></div></div><div class="para">
			You can also use Itstool for translation. In order to translate an XML file with it, you need an <code class="filename">.its</code> file with translation definitions. An appropriate file for AppStream upstream metadata of any kind can be found here:
		</div><pre class="programlisting"><span xmlns="" class="line">​</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Keyword">&lt;its:rules</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Others">  xmlns:its=</span><span xmlns="" class="perl_String">"http://www.w3.org/2005/11/its"</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Others">  version=</span><span xmlns="" class="perl_String">"1.0"</span><span xmlns="" class="perl_Keyword">&gt;</span>
<span xmlns="" class="line">​</span>  <span xmlns="" class="perl_Keyword">&lt;its:translateRule</span><span xmlns="" class="perl_Others"> translate=</span><span xmlns="" class="perl_String">"no"</span><span xmlns="" class="perl_Others"> selector=</span><span xmlns="" class="perl_String">"/component"</span><span xmlns="" class="perl_Keyword">/&gt;</span>
<span xmlns="" class="line">​</span>  <span xmlns="" class="perl_Keyword">&lt;its:translateRule</span><span xmlns="" class="perl_Others"> translate=</span><span xmlns="" class="perl_String">"yes"</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Others">    selector=</span><span xmlns="" class="perl_String">"/component/name | /component/summary |</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_String">    /component/description | /component/screenshots/screenshot/caption | /component/developer_name"</span><span xmlns="" class="perl_Keyword">/&gt;</span>
<span xmlns="" class="line">​</span><span xmlns="" class="perl_Keyword">&lt;/its:rules&gt;</span></pre><div class="para">
			Save this file as <code class="filename">as-metainfo.its</code> for example.
		</div><div class="para">
			To extract a GNU Gettext <code class="filename">.pot</code> file from your XML file, run itstool with the follwing arguments (replacing "foo" with your project name):
		</div><pre class="programlisting"><span xmlns="" class="line">​</span>itstool -i <span xmlns="" class="perl_BString">as</span>-metainfo.its -o <span xmlns="" class="perl_Others">$podir</span>/foo_metadata.pot data/foo.appdata.xml</pre><div class="para">
			You can then translate the <code class="filename">.pot</code> file using the standard methods for translating files like these. You obtain <code class="filename">.po</code> files, which you can convert into <code class="filename">.mo</code> files (using msgfmt) like you would do with any other localization. Then, you need to call <code class="command">itstool</code> again, to create a translated version of the original XML file:
		</div><pre class="programlisting"><span xmlns="" class="line">​</span>itstool -i <span xmlns="" class="perl_BString">as</span>-metainfo.its -j data/foo.appdata.xml -o output/foo.appdata.xml <span xmlns="" class="perl_Others">$modir</span>/*.mo</pre><div class="para">
			Please ensure that the <code class="filename">.mo</code> files in <code class="filename">$modir</code> are named with their language codes.
		</div><div xmlns:d="http://docbook.org/ns/docbook" class="note"><div class="admonition_header"><p><strong>Note</strong></p></div><div class="admonition"><div class="para">
				You can find more information about Itstool <a href="http://itstool.org/">on their homepage</a>.
			</div></div></div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="sect-Quickstart-Distros.html"><strong>Prev</strong>4.3. For distributors packaging Appstream metadata</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="chap-AppStream-Services.html"><strong>Next</strong>Chapter 5. Services</a></li></ul></body></html>