I18NSupport


 * Launchpad Entry: NovaSpec:i18n-support
 * Created: 2010-10-22
 * Contributors: Koji Iida, Hisaharu Ishii

http://etherpad.openstack.org/I18N-Support

Summary

 * Internationalization support for logging messages
 * Support Japanese messages

Release Note

 * TBD

Rationale

 * Currently, log messages are written only in English.
 * I18N support is required for world-wide use of OpenStack.

User stories

 * TBD

Assumptions

 * Server side logging messages only
 * Use launchpad function https://help.launchpad.net/Translations to manage translations.

Design

 * Replace existing source code for log message output to I18N style by using gettext module.
 * Provide Japanese message catalog (.po) files.

Implementation
JayPipes has already begun the i18n process for the OpenStack-CI project. He will provide assistance on automating the upload of the message catalog to Launchpad translations unit.

UI Changes

 * No UI changes.

Code Changes
The followings are sample implementation step.

1. Install the function _ in Python’s builtin namespace.

Example: nova/nova-scheduler:

import os   import sys +  import gettext

# If ../nova/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir)

from nova import service from nova import twistd

+  gettext.install('nova', './locale', unicode=1) +   if __name__ == '__main__': twistd.serve(__file__)

if __name__ == '__builtin__': application = service.Service.create

2. Mark the strings which are used in logging function, by wrapping them in a call to the _ function.

Example: ./nova/service.py

if not periodic_interval: periodic_interval = FLAGS.periodic_interval -       logging.warn("Starting %s node", topic) +       logging.warn(_("Starting %s node"), topic) service_obj = cls(host, binary, topic, manager,                            report_interval, periodic_interval)

3. Generate .pot file.

$ pygettext -p locale -d nova nova/service.py

File locale/nova.pot generated.

4. Copy nova.pot to nova.po.

$ cp locale/nova.pot locale/ja/LC_MESSAGES/nova.po

5. Translate locale/ja/LC_MESSAGES/nova.po to your language.

Example translation of locale/ja/LC_MESSAGES/nova.po to Japanese:

msgid "" msgstr "" "Project-Id-Version: 0.1\n" "POT-Creation-Date: 2010-10-27 17:50+JST\n" "PO-Revision-Date: 2010-10-27 18:13+JST\n" "Last-Translator: Someone \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: pygettext.py 1.5\n"
 * 1) SOME DESCRIPTIVE TITLE.
 * 2) Copyright (C) YEAR ORGANIZATION
 * 3) FIRST AUTHOR , YEAR.

msgid "Starting %s node" msgstr "%s ノードを開始します"
 * nova/service.py:141

6. Generate .mo file.

$ msgfmt -o locale/ja/LC_MESSAGES/nova.mo locale/ja/LC_MESSAGES/nova.po

File ./locale/ja/LC_MESSAGES/nova.mo is generated.

7. Test nova-scheduler

$ LANGUAGE=ja_JP.UTF-8 ./bin/nova-scheduler --flagfile=./nova-manage.conf

Output messages:

... DEBUG:root:network_topic : network WARNING:root:scheduler ノードを開始します 2010-10-27 18:30:41+0900 [-] Log opened. 2010-10-27 18:30:41+0900 [-] twistd 10.0.0 (/usr/bin/python 2.6.5) starting up. 2010-10-27 18:30:41+0900 [-] reactor class: twisted.internet.selectreactor.SelectReactor. INFO:root:backend  2010-10-27 18:30:41+0900 [-] (root): INFO backend 

Migration

 * TBD

Test/Demo Plan

 * TBD

Unresolved issues

 * TBD

BoF agenda and discussion

 * TBD