Python Statements/Keyword Localization

Emanuele D'Arrigo manu3d at gmail.com
Wed Nov 25 20:02:39 CET 2009


Greetings everybody,

some time ago I saw a paper that used an XSL transformation sheet to
transform (if I remember correctly) a Chinese xml file (inclusive of
Chinese-script XML tags) into an XHTML file.

More recently you might have all heard how the ICANN has opened up the
way for non-latin characters in domain names, so that we'll soon start
seeing URLs using Russian, Asian and Arabic characters.

In this context I was wondering if there has ever been much thought
about a mechanism to allow the localization not only of the strings
handled by python but also of its built-in keywords, such as "if",
"for", "while", "class" and so on. For example, the following English-
based piece of code:

class MyClass(object):
    def myMethod(self, aVariable):
         if aVariable == True:
            print "It's True!"
         else:
            print "It's False!"

would become (in Italian):

classe LaMiaClasse(oggetto):
    def ilMioMetodo(io, unaVariabile)
         se unaVariabile == Vero:
             stampa "E' Vero!"
         altrimenti:
             stampa "E' Falso!"

I can imagine how a translation script going through the source code
could do a 1:1 keyword translation to English fairly quickly but this
would mean that the runtime code still is in English and any error
message would be in English. I can also imagine that it should be
possible to "simply" recompile python to use different keywords, but
then all libraries using the English keywords would become
incompatible, wouldn't they?

In this context it seems to be the case that the executable would have
to be able to optionally accept -a list- of dictionaries to internally
translate to English the keywords found in the input code and at most -
one- dictionary to internally translate from English output messages
such as a stack trace.

What do you guys think?

Manu



More information about the Python-list mailing list