Kuku/Localization: Difference between revisions
< Kuku
Jump to navigation
Jump to search
(added i18n instructions) |
|||
(10 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
= |
== How to == |
||
: For a guide on how to localize an activity see: '''[[Python i18n|Python Localization Instructions]]''' |
|||
== Strings == |
|||
* activity name: Kuku Anakula |
* activity name: Kuku Anakula |
||
Line 5: | Line 9: | ||
** english: Begin! |
** english: Begin! |
||
** swahili: Kuanza! |
** swahili: Kuanza! |
||
** portuguese: Começar! |
|||
== Code Comments == |
=== Code Comments === |
||
When we start to comment the code with comments and docstrings, |
When we start to comment the code with comments and docstrings, |
||
we will ask for translations and add in i18n. |
we will ask for translations and add in i18n. |
||
== kuku.pot == |
|||
= Intstructions for i18n in a pygame app = |
|||
Following the wxpython tutorial below, I added the following code at the top of my application: |
|||
<pre> |
<pre> |
||
# SOME DESCRIPTIVE TITLE. |
|||
import gettext |
|||
# Copyright (C) YEAR ORGANIZATION |
|||
gettext.install('kuku', './locale', unicode=False) |
|||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: PACKAGE VERSION\n" |
|||
"POT-Creation-Date: 2007-06-19 17:15+EDT\n" |
|||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
|||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
|||
"Language-Team: LANGUAGE <LL@li.org>\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=utf-8\n" |
|||
"Content-Transfer-Encoding: utf-8\n" |
|||
"Generated-By: pygettext.py 1.5\n" |
|||
#one line for each language |
|||
presLan_en = gettext.translation("kuku", "./locale", languages=['en']) |
|||
presLan_sw = gettext.translation("kuku", "./locale", languages=['sw']) |
|||
#: kuku.py:500 |
|||
#only install one language - add program logic later |
|||
msgid "Begin!" |
|||
presLan_en.install() |
|||
msgstr "" |
|||
# presLan_sw.install() |
|||
</pre> |
</pre> |
||
=== en - kuku.po === |
|||
Here my application is called kuku.py, and I am using 'kuku' to be the domain of my i18n. Now I choose which strings I needed to localize within my application file kuku.py - these strings I surrounded with |
|||
_(). For example |
|||
<pre> |
<pre> |
||
#./locale/en/LC_MESSAGES/kuku.po |
|||
message = _('Begin!') |
|||
# SOME DESCRIPTIVE TITLE. |
|||
</pre> |
|||
# Copyright (C) YEAR ORGANIZATION |
|||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: PACKAGE VERSION\n" |
|||
"POT-Creation-Date: 2007-06-19 17:15+EDT\n" |
|||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
|||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
|||
"Language-Team: LANGUAGE <LL@li.org>\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=utf-8\n" |
|||
"Content-Transfer-Encoding: utf-8\n" |
|||
"Generated-By: pygettext.py 1.5\n" |
|||
Next I need to create the i18n files. First I create a directory called 'locale' within my activity directory (this is referred to in the above lines (presLan_en ...). The first step is to make a pot file, which I use pygettext.py to process kuku.py |
|||
#: kuku.py:500 |
|||
<pre> |
|||
msgid "Begin!" |
|||
python <path to your python distribution>/Tools/i18n/pygettext.py -o kuku.pot kuku.py |
|||
msgstr "Begin!" |
|||
</pre> |
</pre> |
||
=== es - kuku.po === |
|||
which creates kuku.pot. When first created it looks like |
|||
<pre> |
<pre> |
||
#./locale/es/LC_MESSAGES/kuku.po |
|||
# SOME DESCRIPTIVE TITLE. |
# SOME DESCRIPTIVE TITLE. |
||
# Copyright (C) YEAR ORGANIZATION |
# Copyright (C) YEAR ORGANIZATION |
||
Line 51: | Line 77: | ||
msgstr "" |
msgstr "" |
||
"Project-Id-Version: PACKAGE VERSION\n" |
"Project-Id-Version: PACKAGE VERSION\n" |
||
"POT-Creation-Date: 2007-06-19 17: |
"POT-Creation-Date: 2007-06-19 17:15+EDT\n" |
||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
||
"Language-Team: LANGUAGE <LL@li.org>\n" |
"Language-Team: LANGUAGE <LL@li.org>\n" |
||
"MIME-Version: 1.0\n" |
"MIME-Version: 1.0\n" |
||
"Content-Type: text/plain; charset= |
"Content-Type: text/plain; charset=utf-8\n" |
||
"Content-Transfer-Encoding: |
"Content-Transfer-Encoding: utf-8\n" |
||
"Generated-By: pygettext.py 1.5\n" |
"Generated-By: pygettext.py 1.5\n" |
||
#: kuku.py: |
#: kuku.py:500 |
||
msgid "Begin!" |
msgid "Begin!" |
||
msgstr "" |
msgstr "Comenzar!" |
||
</pre> |
</pre> |
||
=== fr - kuku.po === |
|||
The last little bit is the stuff we have to translate. I had to modify the stuff at the top to change the ENCODING and CHARSET. I changed both of these to utf-8, so my file now reads: |
|||
<pre> |
<pre> |
||
#./locale/fr/LC_MESSAGES/kuku.po |
|||
# SOME DESCRIPTIVE TITLE. |
# SOME DESCRIPTIVE TITLE. |
||
# Copyright (C) YEAR ORGANIZATION |
# Copyright (C) YEAR ORGANIZATION |
||
Line 88: | Line 115: | ||
#: kuku.py:500 |
#: kuku.py:500 |
||
msgid "Begin!" |
msgid "Begin!" |
||
msgstr "" |
msgstr "Commencer!" |
||
</pre> |
</pre> |
||
=== jp - kuku.po === |
|||
Now I moved kuku.pot to ./locale . Then for each language I want to localize to, I create subdirectories within ./locale according to their [http://www.w3.org/WAI/ER/IG/ert/iso639.htm language codes]. Within each of these subdirectories, I create subdirectories called LC_MESSAGES. For know I am using english and swahili, so my directory structure looks like |
|||
<pre> |
<pre> |
||
locale/ |
#./locale/jp/LC_MESSAGES/kuku.po |
||
kuku.pot |
|||
en/ |
|||
LC_MESSAGES/ |
|||
sw/ |
|||
LC_MESSAGES/ |
|||
</pre> |
|||
Now we do translations. I copied kuku.pot into ./locale/en/LC_MESSAGES/kuku.po and ./locale/sw/LC_MESSAGES/kuku.po, and performed the translations: |
|||
<pre> |
|||
#./locale/en/LC_MESSAGES/kuku.po |
|||
# SOME DESCRIPTIVE TITLE. |
# SOME DESCRIPTIVE TITLE. |
||
# Copyright (C) YEAR ORGANIZATION |
# Copyright (C) YEAR ORGANIZATION |
||
Line 125: | Line 141: | ||
#: kuku.py:500 |
#: kuku.py:500 |
||
msgid "Begin!" |
msgid "Begin!" |
||
msgstr " |
msgstr "開始する!" |
||
</pre> |
</pre> |
||
=== sw - kuku.po === |
|||
<pre> |
<pre> |
||
Line 152: | Line 170: | ||
</pre> |
</pre> |
||
=== ar - kuku.po === |
|||
Now my directory structure looks like |
|||
<pre> |
<pre> |
||
# SOME DESCRIPTIVE TITLE. |
|||
locale/ |
|||
# Copyright (C) YEAR ORGANIZATION |
|||
kuku.pot |
|||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
|||
en/ |
|||
# |
|||
LC_MESSAGES/ |
|||
msgid "" |
|||
kuku.po |
|||
msgstr "" |
|||
sw/ |
|||
"Project-Id-Version: PACKAGE VERSION\n" |
|||
LC_MESSAGES/ |
|||
"POT-Creation-Date: 2007-06-19 17:15+EDT\n" |
|||
kuku.po |
|||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
|||
</pre> |
|||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
|||
"Language-Team: LANGUAGE <LL@li.org>\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=utf-8\n" |
|||
"Content-Transfer-Encoding: utf-8\n" |
|||
"Generated-By: pygettext.py 1.5\n" |
|||
One last step before we are ready to go. We need to make the binary files used by gettext. We do that with msgfmt.py: |
|||
#: kuku.py:500 |
|||
<pre> |
|||
msgid "Begin!" |
|||
cd <project path>/locale/en/LC_MESSAGES/ |
|||
msgstr "ابدأ" |
|||
python <path to your python distribution>/Tools/i18n/msgfmt.py kuku.po |
|||
cd <project path>/locale/en/LC_MESSAGES/ |
|||
python <path to your python distribution>/Tools/i18n/msgfmt.py kuku.po |
|||
</pre> |
</pre> |
||
=== pt_BR - kuku.po === |
|||
This creates binary .mo files, and now my directory structure looks like: |
|||
<pre> |
<pre> |
||
# SOME DESCRIPTIVE TITLE. |
|||
locale/ |
|||
# Copyright (C) YEAR ORGANIZATION |
|||
kuku.pot |
|||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
|||
en/ |
|||
# |
|||
LC_MESSAGES/ |
|||
msgid "" |
|||
kuku.po |
|||
msgstr "" |
|||
kuku.mo |
|||
"Project-Id-Version: PACKAGE VERSION\n" |
|||
sw/ |
|||
"POT-Creation-Date: 2007-06-19 17:15+EDT\n" |
|||
LC_MESSAGES/ |
|||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
|||
kuku.po |
|||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
|||
kuku.mo |
|||
"Language-Team: LANGUAGE <LL@li.org>\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=utf-8\n" |
|||
"Content-Transfer-Encoding: utf-8\n" |
|||
"Generated-By: pygettext.py 1.5\n" |
|||
#: kuku.py:500 |
|||
msgid "Begin!" |
|||
msgstr "Começar!" |
|||
</pre> |
</pre> |
||
=== th - kuku.po === |
|||
To add new languages, we need to add a subdirectory for each language, perform the translations, create the .mo files, and add the relevant code in the application to select the language. |
|||
<pre> |
|||
== Resources == |
|||
# SOME DESCRIPTIVE TITLE. |
|||
These are the two docs that I used to learn about i18n (with no prior knowledge). Read the WxPython reference first, and instead of using the mki18n.py file mentioned on the WkPython page, use the tools in the python standard distribution: pygettext.py and msgfmt.py. |
|||
# Copyright (C) YEAR ORGANIZATION |
|||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: PACKAGE VERSION\n" |
|||
"POT-Creation-Date: 2007-06-19 17:15+EDT\n" |
|||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
|||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
|||
"Language-Team: LANGUAGE <LL@li.org>\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=utf-8\n" |
|||
"Content-Transfer-Encoding: utf-8\n" |
|||
"Generated-By: pygettext.py 1.5\n" |
|||
[http://docs.python.org/lib/node738.html Python Reference] |
|||
#: kuku.py:500 |
|||
[http://wiki.wxpython.org/Internationalization WxPython i18n] |
|||
msgid "Begin!" |
|||
msgstr "เริ่ม!" |
|||
</pre> |
Latest revision as of 22:48, 10 February 2009
How to
- For a guide on how to localize an activity see: Python Localization Instructions
Strings
- activity name: Kuku Anakula
- start screen: Begin!
- english: Begin!
- swahili: Kuanza!
- portuguese: Começar!
Code Comments
When we start to comment the code with comments and docstrings, we will ask for translations and add in i18n.
kuku.pot
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr ""
en - kuku.po
#./locale/en/LC_MESSAGES/kuku.po # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "Begin!"
es - kuku.po
#./locale/es/LC_MESSAGES/kuku.po # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "Comenzar!"
fr - kuku.po
#./locale/fr/LC_MESSAGES/kuku.po # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "Commencer!"
jp - kuku.po
#./locale/jp/LC_MESSAGES/kuku.po # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "開始する!"
sw - kuku.po
#./locale/sw/LC_MESSAGES/kuku.po # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "Kuanza!"
ar - kuku.po
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "ابدأ"
pt_BR - kuku.po
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "Começar!"
th - kuku.po
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2007-06-19 17:15+EDT\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: utf-8\n" "Generated-By: pygettext.py 1.5\n" #: kuku.py:500 msgid "Begin!" msgstr "เริ่ม!"