Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/app/static/doc/myosa/ch013_going-international-with-pootle.xhtml
blob: 46c8b4709512dc1cde520e2ba107b1d7f9f159ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><body><h1>Going International With Pootle
</h1>
<h2>Introduction
  <br/></h2>
<p>The goal of Sugar Labs and One Laptop Per Child is to educate all the children of the world, and we can't do that with Activities that are only available in one language.&#160; It is equally true that making separate versions of each Activity for every language is not going to work, and expecting Activity developers to be fluent in many languages is not realistic either.&#160; We need a way for Activity developers to be able to concentrate on creating Activities and for those who can translate to just do that.&#160; Fortunately, this is possible and the way it's done is by using <em>gettext</em>.
</p>
<h2>Getting Text With gettext
</h2>
<p>You should remember that our latest code example made use of an odd import:
</p>
<pre>from gettext import gettext as _
</pre>
<p> The "_()" function was used in statements like this:
</p>
<pre>        self.back.set_tooltip(_('Back'))
</pre>
<p> At the time I explained that this odd looking function was used to translate the word "Back" into other languages, so that when someone looks at the Back button's tool tip he'll see the text in his own language.&#160; I also said that if it was not possible to translate this text the user would see the word "Back" untranslated.&#160; In this chapter we'll learn more about how this works and what we have to do to support the volunteers who translate these text strings into other languages.
</p>
<p>The first thing you need to learn is how to properly format the text strings to be translated.&#160; This is an issue when the text strings are actual sentences containing information.&#160; For example, you might write such a message this way:
</p>
<pre>    message = _("User ") + username + \
        _(" has joined the chat room.")
</pre>
<p>This would work, but you've made things difficult for the translator. &#160; He has two separate strings to translate and no clue that they belong together.&#160; It is much better to do this:
</p>
<pre>    message = _("User %s has joined the chat room.") % \
        username
</pre>
<p>If you know both statements give the same resulting string then you can easily see why a translator would prefer the second one.&#160; Use this technique whenever you need a message that has some information inserted into it.&#160; When you use it, try and limit yourself to only one format code (the %s) per string.&#160; If you use more than one it can cause problems for the translator.
  <br/></p>
<h2>Going To Pot
</h2>
<p>Assuming that every string of text a user might be shown by our Activity is passed through "_()" the next step is to generate a pot file.&#160; You can do this by running setup.py with a special option:
</p>
<pre>./setup.py genpot</pre>
<p>This creates a directory called <strong>po</strong> and puts a file <strong><em>ActivityName</em>.pot</strong> in that directory.&#160; In the case of our example project <em>ActivityName</em> is <strong>ReadEtextsII</strong>.&#160; This is the contents of that file:
</p>
<pre># SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the
# PACKAGE package.
# FIRST AUTHOR &lt;EMAIL@ADDRESS&gt;, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-01-06 18:31-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME &lt;EMAIL@ADDRESS&gt;\n"
"Language-Team: LANGUAGE &lt;LL@li.org&gt;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: activity/activity.info:2
msgid "Read ETexts II"
msgstr ""

#: toolbar.py:34
msgid "Back"
msgstr ""

#: toolbar.py:40
msgid "Forward"
msgstr ""

#: toolbar.py:115
msgid "Zoom out"
msgstr ""

#: toolbar.py:120
msgid "Zoom in"
msgstr ""

#: toolbar.py:130
msgid "Fullscreen"
msgstr ""

#: ReadEtextsActivity2.py:34
msgid "Edit"
msgstr ""

#: ReadEtextsActivity2.py:38
msgid "Read"
msgstr ""

#: ReadEtextsActivity2.py:46
msgid "View"
msgstr ""
</pre>
<p> This file contains an entry for every text string in our Activity (as msgid) and a place to put a translation of that string (msgstr).&#160;&#160; Copies of this file will be made by the Pootle server for every language desired, and the msgstr entries will be filled in by volunteer translators.
</p>
<h2>Going To Pootle
  <br/></h2>
<p>Before any of that can happen we need to get our POT file into Pootle.&#160; The first thing we need to do is get the new directory into our Git repository and push it out to Gitorious.&#160; You should be familiar with the needed commands by now:
</p>
<pre>git add po
git commit -a -m "Add POT file"
git push
</pre>
<p>Next we need to give the user "pootle" commit authority to our Git project.&#160; Go to <a href="http://git.sugarlabs.org">git.sugarlabs.org,</a>&#160; sign in, and find your Project page and click on the mainline link.&#160; You should see this on the page that takes you to:
</p>
<p>&#160;<img alt="Add pootle as a committer" src="static/ActivitiesGuideSugar-pootle1-en.jpg" height="456" width="376"/></p>
<p>Click on the <strong>Add committer</strong> link and type in the name <strong>pootle </strong>in the form that takes you to.&#160; When you come back to this page <strong>pootle</strong> will be listed under Committers.
  <br/></p>
<p> Your next step is to go to web site <a href="http://bugs.sugarlabs.org">http://bugs.sugarlabs.org</a>&#160; and register for a user id.&#160; When you get that open up a ticket something like this:
</p>
<p><img alt="pootle2.jpg" src="static/ActivitiesGuideSugar-pootle2-en.jpg" height="527" width="640"/></p>
<p>The <strong>Component</strong> entry <em>localization</em> should be used, along with <strong>Type</strong> <em>task</em>.
</p>
<p>Believe it or not, this is all you need to do to get your Activity set up to be translated.
</p>
<h2>Pay No Attention To That Man Behind The Curtain
</h2>
<p>After this you'll need to do a few things to get translations from Pootle into your Activity.
</p>
<ul><li>When you add text strings (labels, error messages, etc.) to your Activity always use the <strong>_()</strong> function with them so they can be translated.</li>
  <li>After adding new strings always run <strong>./setup.py genpot</strong> to recreate the POT file.</li>
  <li>After that commit and push your changes to Gitorious.</li>
  <li>Every so often, and especially before releasing a new version, do a <strong>git pull</strong>.&#160; If there are any localization files added to Gitorious this will bring them to you.</li>
  <li>After getting a bunch of new files run <strong>./setup.py fix_manifest</strong> to get the new files included in your <strong>MANIFEST</strong> file.&#160; Afterwards edit the <strong>MANIFEST</strong> with gedit to remove any unwanted entries (which will be Eric project files, etc.).
  <br/></li>
</ul><p>Localization with Pootle will create a large number of files in your project, some in the <strong>po</strong> directory and others in a new directory called <strong>locale</strong>.&#160; As long as these are listed in the MANIFEST they will be included in the .xo file that you will use to distribute your Activity.
</p>
<h2>C'est Magnifique!
</h2>
<p>Here is a screen shot of the French language version of <strong>Read Etexts</strong> reading Jules Verne's novel <em>Le tour du monde en quatre-vingts jours</em>:
</p>
<p><img alt="Jules Verne in French" src="static/ActivitiesGuideSugar-pootle3-en.jpg" height="480" width="640"/>&#160;
</p>
<p>There is reason to believe that the book is in French too.
  <br/></p></body></html>