Re: Python Statements/Keyword Localization



Emanuele D'Arrigo wrote:
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?

It might be necessary to work in tokens, where a token is a word or a
string (or maybe also a comment). Your example would be encoded to:

«1» «2»(«3»):
«4» «5»(«6», «7»):
«8» «7» == «9»:
«10» «11»
«12»:
«10» «13»

with either English:

«1» class
«2» MyClass
«3» object
«4» def
«5» myMethod
«6» self
«7» aVariable
«8» if
«9» True
«10» print
«11» "It's True!"
«12» else
«13» "It's False!"

or Italian:

«1» classe
«2» LaMiaClasse
«3» oggetto
«4» def
«5» ilMioMetodo
«6» io
«7» unaVariabile
«8» se
«9» Vero
«10» stampa
«11» "É Vero!"
«12» altrimenti
«13» "É Falso!"

Any messages produced by, or format strings used by, the runtime would
also be tokens.

Python currently does lexical analysis on the source code to identify
names, strings, etc; a new tokenised file format would partially bypass
that because the names and strings (and comments?) have already been
identified.
.



Relevant Pages

  • Re: Substituting the main menu bar(s)
    ... like everything to be in English, partly because my user guide is in ... But I do not try to do anything about other strings that might be displayed in the language of the operating system. ... You mention one disadvantage of your dictionary to be that each English string can only have one translation. ... But you could get around this by having two dictionaries; one for menu/control text and another for tooltip text. ...
    (microsoft.public.vc.mfc)
  • Python Statements/Keyword Localization
    ... transform a Chinese xml file (inclusive of ... handled by python but also of its built-in keywords, such as "if", ... 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 ...
    (comp.lang.python)
  • Re: Python Statements/Keyword Localization
    ... Python is designed to be read by people. ... Fixed keywords are not an undue burden because any educated person should learn to read Latin characters a-z,0-9. ... 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 ...
    (comp.lang.python)
  • Troubles with python internationalization
    ... I'm studying the migration of my website (mixed english and french ... From what I've read so far, using translation "tags" ... substitute placeholders in translated strings. ... extract them and add them to the standard gettext translation chain. ...
    (comp.lang.python)
  • FREE TRANSLATION
    ... Free Online Translation ... Free English To Spanish Translation ... Free Online Translations ...
    (rec.sport.softball)