nuxeo-localizer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nuxeo-localizer] ZWiki internationalization


From: Juan David Ibáñez Palomar
Subject: Re: [Nuxeo-localizer] ZWiki internationalization
Date: Mon, 25 Feb 2002 10:54:28 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020214

This weekend I worked a bit in the internationalizatio of Python
products, now it would be:


from Products.Localizer import Gettext

_ = Gettext.translation(globals()) # or "gettext = Gettext.translation(globals()) "
N_ = Gettext.dummy

....

_('Edit conflict!')


So now it looks more like a normal multilingual Python application.
The "N_" is used for defered translations, that is, to markup a string
for translation but without actually translating it.

The previous way still works, and will work for a looong time.

That's all,



Juan David Ibáñez Palomar wrote:


Hi all, and specially to Simon, who is considering to use Localizer
to internationalize ZWiki.

Note: this message is *long*.

I'm going to explain, step by step, how to output a multilingual
message from ZWiki. The selected message appears in line 1655
of ZWikiPage.py (ZWiki version 0.9.8):

return MessageDialog(
title='Edit conflict!',

The explanation also will be useful for anybody that wants to
internationalize a Python product. Let's start:

0 - Download and install Localizer

1 - Edit the file ZWikiPage.py:

1.1 - Import the needed stuff:

from Globals import package_home
from Products.Localizer.LocalObjects import gettext

1.2 - Add the following lines to the class "ZWikiPage":

locale = package_home(globals()) + '/locale/'
_gettext = gettext

The "locale" attribute tells where the translations are stored,
the "_gettext" method will be used to translate the messages.

The reason the method is "_gettext" and not just "gettext" is
to prevent collisions with acquisition.

1.3 - Modify the message to translate:

return MessageDialog(
title=self._gettext('Edit conflict!'),

2 - Generate the "locale" directory and the POT and PO files.
For example, from the ZWiki product type:

../Localizer/zgettext.py ZWikiPage.py -l es fr

This will create the files "locale/locale.pot", "locale/es.po"
and "locale/fr.po".

3 - Translate the files "es.po" and "fr.po", using for example: vi,
the PO mode of emacs, poedit, gtranslator, KBabel, etc..

4 - Generate the "mo" files typing:

../Localizer/zgettext.py -m

In our example this would generate the files "locale/es.mo"
and "locale/fr.mo".

5 - Restart the Zope server and enjoy.

Explanation...

The step 1 is known as internationalization, the step 3 is localization.

The PO files are text files that would be stored in the CVS. The MO
files are the binary files used in run time.

The solution Localizer proposes to internationalize Python products is
to use the GNU Gettext utilities. Most free software (KDE, GNOME,
etc..) uses them.

Differences between this and the normal use of Gettext:

1. Usually in a multilingual Python application the "gettext" function
is installed in the builtins namespace, then programmers type:

gettext(message)

but in Localizer you've to type:

self._gettext(message)

I can give a number of arguments for this. But I'm not completely
sure this is the simplest possible way.

2. The standard place to store the MO files is:

<locale_dir>/<language>/LC_MESSAGES/<domain>.mo

However, with Localizer the MO files are stored in:

<zope_dir>/Products/<domain>/locale/<language>.mo

This way it's easier to install the product from a tarball, as the MO files
live within the product the user only has to unpack it in the "Products"
directory.

But I thing the best would be to follow the standard, then we would have:

<locale_dir>/<language>/LC_MESSAGES/zope.mo
<locale_dir>/<language>/LC_MESSAGES/zope-zwiki.mo
<locale_dir>/<language>/LC_MESSAGES/zope-localizer.mo
...

As you see from this two notes, there's still some work to do in this area. But I think it's already quite easy to internationalize a product with Localizer.


And now the comparison with ZBabel. There're 2 key differences that make
Localizer a better solution to internationalize Python products, they're:

1. With Localizer the message catalog lives in the file system. With ZBabel
you need a ZBabelTower instance in the ZODB.

This is important specially for the user, with ZBabel the user has to:

1. Install the product (ZWiki for example)

2. Create a ZBabelTower (ZBT for short) instance in the ZODB

With Localizer the second step doesn't exists. Of course, you could do things to automate it, for example the ZBT instance could be automatically created when a new ZWiki instance is created. But you still can't internationalize the management screen that lets to create a new ZWiki object. Unless you create automatically a ZBT instance in the root of the Zope site every time the server
restarts (if it don't exists already, of course).

Anyway, these are workarounds. The fact is that the message catalog from
ZBabel was designed to translate templates that live in the ZODB, no to
translate Python products.

2. Localizer uses Gettext, this is specially important for translators. Try for
example the KBabel tool from the KDE project. Translators will be happy
to use tools like this one.

Instead with ZBabel you have two options: edit the message catalog through the web with a pretty bad interface (just try it); or export the message catalog to a file, then you could translate it with a text editor (the format of the exported file is specific to ZBabel) and then import the file to the message catalog again.

I'm sure translators prefer to use graphical tools like KBabel.


That's all, cheers,



--
J. David Ib??ez, Nuxeo.com
Libre Software zealot (http://www.fsf.org)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]