471,342 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

i18n questions

Hi,
A soon-to-be happy new year to everyone!

I'm 100% new to this i18n lark and my approach so far has been to create
a .mo file per module in my app.
My thinking was, why load one huge .mo file when a single module only needs
a few strings? Since then, it seems, I have made the wrong decision.

For example I have module A that imports module B. Each one does this:

gettext.install( domain, localedir, unicode = True )
lang = gettext.translation(domain, localedir, languages = [ loc ] )
lang.install(unicode = True )

(where doman is the name of the module, so "A" and "B")

The problem is that domain "A" loads and then import B happens and so
the "lang" reference (I think) gets replaced by domain "B" -- the result is
that module A can only translate strings that are in domain "B".

How does one 'merge' gettext.translations objects together? Or is that
insane?

What's the best way to handle a project with multiple domain.mo files?

I hope someone can give me some advice.

\d

Dec 28 '07 #1
4 1273
On Dec 28, 12:01 pm, Donn Ingle <donn.in...@gmail.comwrote:
Hi,
A soon-to-be happy new year to everyone!

I'm 100% new to this i18n lark and my approach so far has been to create
a .mo file per module in my app.
My thinking was, why load one huge .mo file when a single module only needs
a few strings? Since then, it seems, I have made the wrong decision.

For example I have module A that imports module B. Each one does this:

gettext.install( domain, localedir, unicode = True )
lang = gettext.translation(domain, localedir, languages = [ loc ] )
lang.install(unicode = True )

(where doman is the name of the module, so "A" and "B")

The problem is that domain "A" loads and then import B happens and so
the "lang" reference (I think) gets replaced by domain "B" -- the result is
that module A can only translate strings that are in domain "B".

How does one 'merge' gettext.translations objects together? Or is that
insane?

What's the best way to handle a project with multiple domain.mo files?

I hope someone can give me some advice.

\d
I've never messed with .mo files, but a little "googling" turned up
this interesting module on PyPI: http://cheeseshop.python.org/pypi?%3...rch&term=polib

If you're messing with unicode in general, I've heard this is a good
article to read:
http://kevino.theolliviers.com/python-unicode.html

This article looks related, although the author is using .po instead
of .mo files:
http://www.learningpython.com/2006/1...k-application/

Finally, I found a wxPython specific one that looks like it might be
general enough for you:
http://wiki.wxpython.org/Internationalization

I hope that gives you some ideas anyway.

Mike
Dec 28 '07 #2
Thanks for taking the time to post those links. I have read most of them
before. They don't seem to cover the basic issue in my OP, but i18n on
Python is a dark art and maybe there's something I missed.

\d

Dec 29 '07 #3
* Donn Ingle (Fri, 28 Dec 2007 20:01:48 +0200)
I'm 100% new to this i18n lark and my approach so far has been to create
a .mo file per module in my app.
My thinking was, why load one huge .mo file when a single module only needs
a few strings? Since then, it seems, I have made the wrong decision.

For example I have module A that imports module B. Each one does this:

gettext.install( domain, localedir, unicode = True )
lang = gettext.translation(domain, localedir, languages = [ loc ] )
lang.install(unicode = True )

(where doman is the name of the module, so "A" and "B")

The problem is that domain "A" loads and then import B happens and so
the "lang" reference (I think) gets replaced by domain "B" -- the result is
that module A can only translate strings that are in domain "B".

How does one 'merge' gettext.translations objects together? Or is that
insane?

What's the best way to handle a project with multiple domain.mo files?
I can give you just general advice how I dealt with
internationalization in my example app. "scipt" is the main app with
its own mo file and imports optparse which has again its own mo file

#
gettext.textdomain('optparse')
gettext.install('script', unicode = True)

from optparse import OptionParser, \
OptionGroup
# [...]
Thorsten
Dec 29 '07 #4
Thorsten Kampe wrote:
gettext.textdomain('optparse')
gettext.install('script', unicode = True)
They speak of a 'global' domain in the docs, but (as is my usual beef with
the Python docs -- see PHP docs for sterling help) there is no clarity.

It *sounds* like there can be a .mo file for *everything* and then one can
also install others on a per-script/module basis, as your code seems to
suggest.

All very confusing.

I have had an entire day to stew and I spent it combining all my po files
into one big file. Now I install that once, and efficiency be damned.

Still, I'm interested in what's possible and I'll give your approach a
whirl.

Don't let the thread die yet, c'mon you i18n boffins!

Thanks,
\d

Dec 29 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by ProgDario | last post: by
4 posts views Thread by Logan | last post: by
10 posts views Thread by Albretch | last post: by
13 posts views Thread by Guido Wesdorp | last post: by
reply views Thread by Laszlo Zsolt Nagy | last post: by
3 posts views Thread by Darren Davison | last post: by
8 posts views Thread by Alan J. Flavell | last post: by
reply views Thread by i18n-bounces | last post: by
2 posts views Thread by Norman Diamond | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.