[TransWarp] internationalization

Radek Kanovsky rk at dat.cz
Tue Jun 24 04:59:08 EDT 2003


we have touched internationalization theme on IRC channel yesterday.
I have a some remarks for discussion.

There is notorious problem with sentence to sentence translations.
Application code often looks like this:

    if num == 1 :
        print _('1 record found')
    else :
        print _('%d records found') % num

This is what gettext allows for example. But correct translation
into czech language must looks like this:

    if num == 1 :
        print _('Nalezen 1 zaznam')
    elif num in [2,3,4] :
        print _('Nalezeny %d zaznamy') % num
    else :
        print _('Nalezeno %d zaznamu') % num

Strange language :) IIRC, german language has similar problems.

I think that above branching belongs to i18n subsystem work. This
work should be delegated onto translator that better knows how to
make such branching.

Positional arguments are another problem. One has not chance
to translate 'foo %d bar %s' into 'baz %s foo %d' because arguments
are often positional. In python it is possible to write %(num)d
but anyway this doesn't solve the first problem.

I have searched through the web for some smart solution but haven't found
anything. My idea is that i18n subsystem should be adaptable (at least)
to following interface:

    class IMessageCatalog (Interface) :

        def lookup(msg_id, language, **named_parameters) :
            """Returns message according to msgi_id in given language
               with substituted named_parameters.

It is programmer's work to create some shortcut methods that resolve
catalog, msg_id or language from some context provided by application
(HTTPRequest object, configuration, session, __name__ or such).


More information about the PEAK mailing list