[spambayes-dev] State of I18N

Hernan Martínez Foffani hernan at orgmf.com.ar
Thu Oct 21 00:06:40 CEST 2004


[Kenny Pitt]
> Hernán Martínez Foffani wrote:
>> I mentioned before that I would like to make rcparser.py gettext
>> aware so a translator could work out a solution without having to
>> edit the resource dialogs.
>>
>> The problem I found is that the output of the parser is a dict that
>> includes string literals subject to be translated (like caption or
>> labels) and literals that do not (like font names.) Once in the dict
>> there's no way to differentiate between them.
>> As I expect that changes in the dict would imply changes all over SB,
>> I thought of a partial solution (call it a hack) that may work.
>>
>> AFAICT, SB does not use the output of rcparse directly but through a
>> rc2py previous process.  So how about a subclass of str that override
>> __repr__ ?  Then, rcparse only needs to create instances of this
>> class for labels, captions, etc., not for font names (or every
>> literal can be of this new type and an attribute flag can drive
>> __repr__ accordingly.)
>
> I'm not that familiar with gettext, so I may be way off base here.

Sorry, I should have explained it a bit first.  But you're not
off base here.  To make it short: gettext let you initiliaze a
specific language environment so later, in your program, every
call to _("A message") will be translated on the fly through to the
corresponding table mapping "A message" -> "Un mensaje".
gettext is specially suited if you have a program full of literal
strings and you want to i18n it.  All you'd have to do is set the
environment (a couple of lines of code) and surround every literal
string of your code with _().  The "_" is just a binding to a gettext
function name.  The task that rest is for translators to build
the table mapping (a text file that could be released separated
from the program.)

> However, if you can make the parser smart enough to use different
> classes for translatable vs. non-translatable strings, wouldn't it be
> possible to just put the _() around the translatable strings and
> leave it off for non-translatable ones?

Actually, that's what I'm proposing but with a little twist.
The type of the non-translatable string will be the same as it is
now and the type of the translatable strings will be a subclass of
str (unicode?).  These are the ones that I need to have __repr__
overriden.

I could implement a standard root class for the translatable strings,
something like:

     class translatable_str:
         def __init__(self, s):
             self.s = s
         def __repr__(self):
             return "_(" + repr(self.s) + ")"

but doing so the dict that rcparse produces wouldn't have instances
of str for the translatable items.  It would may impossible to use
that dict directly for win32all dialogs without dumping it first to
a .py file but I don't know if that is a problem.

BTW, I wanted to override (or implement __repr__) because rc2py
just call repr() on the dict to dump it and create the dialogs.py
file.

> Once the strings are written
> out to dialogs.py with the correct markers, you could run the
> pygettext utility against it to extract the appropriate strings for
> translation.

Yes.  That's the idea.

-H.



More information about the spambayes-dev mailing list