Posted by: kezhong | March 20, 2009

V0.7 Release – Migrate aNd Manage

<!– @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } –>

My current job of this project is to implement i18n. After talking with Chris, communities and studying by myself, I finally have a basic concept of i18n. I tried to implement i18n in my program, it works. The following are the steps:

1.Create a test program named test1.py. I marked the messages which want to display with “_()” in the program. For example, if there is a string “Hello World!” want to display, I marked it to “_(“Hello World!”)”. I did these, because I want to automatically fetch the messages which want to be i18n.

#!/usr/bin/python

##############################################################################

# Author: Kezhong Liang

# Purpose: Test I18N

# Date: Mar 19, 2009

##############################################################################

####################### Part of Import ###########################

import gettext

####################### Part of Test ############################

domain_name = “myfile”


cat = gettext.translation(domain_name,”/usr/share/locale”)

_ = cat.gettext

print _(“Hello World!”)

print _(“How are you!”)

2. Produce a myfile.po file using pygettext.py program which I find in the Python Tools directory.

# ./pygettext.py -k _ -d myfile -o myfile.po test1.py

3. Edit myfile.po file and change some items as below.

# SOME DESCRIPTIVE TITLE.

# Copyright (C) YEAR ORGANIZATION

# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.

#

msgid “”

msgstr “”

“Project-Id-Version: PACKAGE VERSION\n”

“POT-Creation-Date: 2009-03-19 15:47+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=CHARSET\n”          ==>        charset=UTF-8

“Content-Transfer-Encoding: ENCODING\n”

“Generated-By: pygettext.py 1.5\n”

#: test1.py:18

msgid “Hello World!”

msgstr “”                                                  ==>      msgstr “世界您好!”

#: test1.py:19

msgid “How are you!”

msgstr””                                                 ==>    msgstr “您好吗!”

4. Produce a myfile.mo file using msgfmt.py program

#./msgfmt.py myfile.po

5. Copy myfile.mo into /usr/share/locale/zh_ZH/LC_MESSAGES

#cp myfile.mo /usr/share/locale/zh_CN/LC_MESSAGES/

6. Set current Locale

#export LC_ALL=zh_CN

7. Test

# ./test1.py

世界您好!

您好吗!

The next step, the first thing I should do is to continue to communicate with communities(i18n, l10n) for understanding more deeply. The second thing is installing various languages Fedora system and test my program on them. The third thing is enhancing the function of my program and make it flexible and strong.


Responses

  1. hao

  2. good job, thx a lot!!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: