473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Translating Javascript programs to python.

Vyz
Hi,
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python.

Thanks
Vyz

Aug 22 '06 #1
5 1882
Vyz schrieb:
Hi,
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python.
Nope. Besides: in which environment does that script run - a browser?
Then it would be difficult if not impossible to execute even a
hypothetic result.

Diez
Aug 22 '06 #2

Vyz wrote:
Hi,
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python.

Thanks
Vyz
Not a tool, but assuming the javascript is not too complex you could
interpret some of it using python and the CGI module.

But really, what would be the use?

Aug 23 '06 #3
Vyz
Its a module to transliterate from telugu language written in roman
script into native unicode. right now its running in a browser window
at www.lekhini.org I Intend to translate it into python so that I can
integrate into other tools I have. I am able to pass arguments and get
output from the script also would be OK. or how about ways to wrap
these javascript functions with python.

Thanks
Vyz

supercoder wrote:
Vyz wrote:
Hi,
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python.

Thanks
Vyz

Not a tool, but assuming the javascript is not too complex you could
interpret some of it using python and the CGI module.

But really, what would be the use?
Aug 23 '06 #4

"Vyz" <vy*******@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Its a module to transliterate from telugu language written in roman
script into native unicode. right now its running in a browser window
at www.lekhini.org I Intend to translate it into python so that I can
integrate into other tools I have. I am able to pass arguments and get
output from the script also would be OK. or how about ways to wrap
these javascript functions with python.
Leaving aside the code the manipulated the display and user interaction,
the code should be pretty straightforward logic (if-else statements) and
table lookups, so translation to Python should be straightforward also.

I checked parser.js. I don't know javascript but it looks to me like a
mixture of C and Python. The for loop headers have to be rewritten, and
the switch changed to if-elif. What looks different is the attachment as
attributes of method functions to functions rather than classes.

As for 'wrapping': can you get a standard javascript interpreter? If so,
you could possibly adjust the js so you can pipe a roman string to the js
program and have it pipe back the telegu unicode version.
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python.
unicode.js is mostly a few hundred verbose lines like

Unicode.codePoints[Padma.lang_TELUGU].letter_PHA = "\u0C2B";

that setup the translation dict. Because the object model is different, I
suspect that these all need to be changed, but, I also suspect, in a
mechanical way.

If one were starting in Python, one might either just define a dict more
compactly like
TEL_uni = {letter_PHA:"\u0C2B", ...}
*or* probably better, use the builtin unicodedata module as much as
possible.
>>import unicodedata as u
pha = u.name(u'\u0c2b')
pha
'TELUGU LETTER PHA'
>>u.lookup(pha)
u'\u0c2b'

I don't know what you do with js statement like this:
Unicode.toPadma[Unicode.codePoints[Padma.lang_TELUGU].misc_VIRAMA +
Unicode.codePoints[Padma.lang_TELUGU].letter_KA] = Padma.vattu_KA;
where a constant seems to be assigned to a sum. But whatever these do
might correspond to the u.normalize function.

This appears to be based on a generic Indian-script transliteration program
(Padma), so there may be functions not really needed for Telegu. (I am
familiar with Devanagri but know nothing of Telegu and its script except
that it is Dravidian rather than Indo-European-Sanskritic.)

Good luck.

Terry Jan Reedy


Aug 24 '06 #5
Vyz
Yes, this is a trimmed down version of padma, a generic indic
transliteration tool
Thanks for comments though.

Terry Reedy wrote:
"Vyz" <vy*******@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Its a module to transliterate from telugu language written in roman
script into native unicode. right now its running in a browser window
at www.lekhini.org I Intend to translate it into python so that I can
integrate into other tools I have. I am able to pass arguments and get
output from the script also would be OK. or how about ways to wrap
these javascript functions with python.

Leaving aside the code the manipulated the display and user interaction,
the code should be pretty straightforward logic (if-else statements) and
table lookups, so translation to Python should be straightforward also.

I checked parser.js. I don't know javascript but it looks to me like a
mixture of C and Python. The for loop headers have to be rewritten, and
the switch changed to if-elif. What looks different is the attachment as
attributes of method functions to functions rather than classes.

As for 'wrapping': can you get a standard javascript interpreter? If so,
you could possibly adjust the js so you can pipe a roman string to the js
program and have it pipe back the telegu unicode version.
I have a script with hundreds of lines of javascript spread accross 7
files. Is there any tool out there to automatically or
semi-automatically translate the code into python.

unicode.js is mostly a few hundred verbose lines like

Unicode.codePoints[Padma.lang_TELUGU].letter_PHA = "\u0C2B";

that setup the translation dict. Because the object model is different, I
suspect that these all need to be changed, but, I also suspect, in a
mechanical way.

If one were starting in Python, one might either just define a dict more
compactly like
TEL_uni = {letter_PHA:"\u0C2B", ...}
*or* probably better, use the builtin unicodedata module as much as
possible.
>import unicodedata as u
pha = u.name(u'\u0c2b')
pha
'TELUGU LETTER PHA'
>u.lookup(pha)
u'\u0c2b'

I don't know what you do with js statement like this:
Unicode.toPadma[Unicode.codePoints[Padma.lang_TELUGU].misc_VIRAMA +
Unicode.codePoints[Padma.lang_TELUGU].letter_KA] = Padma.vattu_KA;
where a constant seems to be assigned to a sum. But whatever these do
might correspond to the u.normalize function.

This appears to be based on a generic Indian-script transliteration program
(Padma), so there may be functions not really needed for Telegu. (I am
familiar with Devanagri but know nothing of Telegu and its script except
that it is Dravidian rather than Indo-European-Sanskritic.)

Good luck.

Terry Jan Reedy
Aug 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Davis Marques | last post by:
hi; I'm translating some PHP scripts to Python and have hit a roadblock with a for statement. If someone could explain to me how one should translate the multiple increment, evaluations, etc....
2
by: Henrik S. Hansen | last post by:
How do you best go about translating characters like '\\n' to '\n'? This is for a configuration file parser, where the "backslash convention" is supported. The naive approach --...
13
by: cjl | last post by:
Hey all: I'm working on a 'pure' python port of some existing software. Implementations of what I'm trying to accomplish are available (open source) in C++ and in Java. Which would be...
10
by: Dave | last post by:
Anyone familiar with PHP? I'm trying to make a translation. In PHP you can get the current object's name by going like this: get_class(item) == 'ClassName' I've tried type(item), but since I...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
4
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
20
by: Guy Fawkes | last post by:
Hi, I was wondering if Python programs always need to include the source code with the program itself. I'm asking this because I don't want my program to be open-source and so far all the Python...
4
by: Berco Beute | last post by:
I wonder what it would take to implement Python in JavaScript so it can run on those fancy new JavaScript VM's such as Chrome's V8 or Firefox' tracemonkey. Much the same as Python implementations...
0
by: Luke Kenneth Casson Leighton | last post by:
On Sep 3, 10:02 pm, bearophileH...@lycos.com wrote: 1200 lines of code for the compiler, and about... 800 for a basic suite of builtin types (Dict, List, set, string). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.