[silva-dev] how to i18n python code ?

Godefroid Chapelle gotcha at bubblenet.be
Tue Nov 25 09:29:07 CET 2003


Hi all,

This is the current state of my thoughts and experiments for i18n of Silva
python code (and more generally for Zope Python code).

First, if I am correctly aware, there has been the decision that 2.7
will be demanded for i18n support in Silva.

Still we must ensure that users that do not need i18n will be able to
run Silva on pre-2.7 Zope.

There has been quite nice work for i18n of Python code in Zope3.

One part of this work is the MessageID class. A MessageID is actually a
unicode
string that brings with it its domain and its default translation.

How is this helpful in i18n work ? The TALInterpreter and the
TranslationService collaborate with MessageIDs.

- When TALInterpreter meets a MessageID (instantiated in Python code),
it translates it.
    This avoids the need for the template developer to know exactly which
    dynamic parts need to be included in i18n:translate tags.

- As the domain is packed with the message id, the template writer work
is also
    eased : he doesn't have to check the domains to include the correct one
    around each string coming from Python code that must be translated !

- This leads us to the most important point : message ids can be kept in
    different .pot files with their own domain. This allows nicer
translation work as
    the messages can be kept together in small coherent sets.

Another part is the extract.py script found in Zope3 that can be run on a
directory and will extract strings packed in a _() call in Python code.
Btw,
_() function is the convention coming from GNU code and also used in z3 to
avoid to clutter the code too much just because of i18n.

Please find enclosed three files :

First one is z3i18n product which monkeypatches 2.7 TALInterpreter and
TranslationService to add the same collaboration as in Z3.

Second is test_z3i18n which shows how to use the MessageID infrastructure in
Python code, by creating the _() function as a MessageIDFactory
parameterized
with the domain.

Both must be installed as zope products in a 2.7 cvs check out
(Zope-2_7-branch, not a beta release).
You must also install Localizer (1.0.1) and TranslationService
(0.4.0-1). Don't
worry, it works also with PlacelessTranslationService.

Last is the i18n.zexp which you should import. This contains i18n.pt  that
exercises i18ned python code from test_z3i18n product. You can test
i18n.pt with both
french or english as default language.




All comments are welcome.
-- 
Godefroid Chapelle (aka __gotcha)                http://bubblenet.be





-------------- next part --------------
A non-text attachment was scrubbed...
Name: z3i18n.tgz
Type: application/x-gzip
Size: 4495 bytes
Desc: not available
Url : http://lists.infrae.com/pipermail/silva-dev/attachments/20031125/d6208eff/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_z3i18n.tgz
Type: application/x-gzip
Size: 896 bytes
Desc: not available
Url : http://lists.infrae.com/pipermail/silva-dev/attachments/20031125/d6208eff/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: i18n.zexp
Type: application/octet-stream
Size: 7627 bytes
Desc: not available
Url : http://lists.infrae.com/pipermail/silva-dev/attachments/20031125/d6208eff/attachment.obj 


More information about the silva-dev mailing list