Localizing Python - Some hacking to force python accept more natural languages words

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > Python

Localizing Python - Some hacking to force python accept more natural languages words

ignite
Overall idea about this topic was inspired by my childrens. Some time ago I started to teach them programming. As a base language I choose Python. So the next step was an attractive subject to program examples and exercises . I create some "robot" program. There is nothing new in it: yet another logo-style game.
(See attacments)
The "robot" is actually lorry which moves at squire cells, concrete or ground and can't move through walls. It understands commands like "forward", "backward" and so on.
All sounds good as for now.
We started from program like this:

CODE
#!/usr/bin/python
# -*- coding: utf-8 -*-
from robot import Robot
robot=Robot('z4-4.maz')

while robot.clear_forward():
  robot.forward(1)
robot.right()
while robot.ground():
  robot.backward(1)
robot.forward(1)
while robot.ground():
  robot.plant()
  robot.forward(1)
robot.forward(1)


But, as you already noticed, I am not native english speaker. When I speak about this program with childrens I forced continuosly switch ukrainian-english and back again and again. So topic arised: can Python understand ukrainian? Or in global context: any language other then english?

I devide the overall task into three different in size and effort parts:
1) make python allows international symbols as identifiers: variables, classes, functions names.
2) translate parts of most used keywords and functions.
3) full python localization.

Part One.
As everybody knows characters represented inside computers as one or more bytes. Historically first widespread charset was ASCII coding standart. It declairs first 127 of 255 possible values of one byte. Later was introduced other 8-bit coding systems, such as latin1, koi8, win1252 etc. And finally was invented unicode, especially in utf-8 form. Utf-8 deffer from other unicode standarts by unique features: it compliant with ASCII code in first 127 values, and all other chars encoded by values from 127-255 vector, so no clash can occure with ASCII signs, digits and such.
Let's start.
Download latest python 2.5 source:
wget -c http://www.python.org/ftp/python/2.5/Python-2.5.tar.bz2
Extract archive:
tar -xjf Python-2.5.tar.bz2
cd Python-2.5

Pyton checks for allowed symbols in tokenizer module: Parser/tokenizer.c. Open it with your favorite editor and locate first call of function isalpha(), it looks like:
CODE
        /* Identifier (most frequent token!) */
        if (isalpha(c) || c == '_') {

All we need to do is to allow symbols above 127 (hex 7F), so edit line to get something like:
CODE
        /* Identifier (most frequent token!) */
        if (isalpha(c) || c == '_' || c > 0x7F) {

Next point is 20 line firther, search for isalnum() function, lines look like:
CODE
                while (isalnum(c) || c == '_') {
                        c = tok_nextc(tok);
                }

Do exactly edentical edit:
CODE
                while (isalnum(c) || c == '_' || c > 0x7F) {
                        c = tok_nextc(tok);
                }

Thats all!
Just do regular things like conigure, make, install:
CODE
./configure
make
make install


Type /usr/local/bin/python and you'l get python interpreter wich allows all umlauts, accents and cyrillics.


Part Two.

.... to be continued: hack python grammar - translate keywords ("def", "while", "if") and builtin functions ("range")...

 

 

 


Reply

Lewisthemusician
kl, i am thinking about teaching myself python but i want to focus on getting the languages i know perfect before starting a new one.
Ill give it a week before i start more biggrin.gif
The Thing is though, you have some coding which won't work in other languages like in AS (action script) you have this coding

On (press) gotoandstop(2)

And in some languages they don't have a world for "on" by itself so it would be like and on in the word.

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. defining a step force in python - 27.59 hr back. (1)
  2. python localization - 273.95 hr back. (8)
  3. hacking python challenge - 429.98 hr back. (1)
Similar Topics

Keywords : localizing, python, hacking, force, python, accept, natural, languages, words

  1. Python Mysqldb Threading
    (0)
  2. Lpt Port And Python
    Using SWIG to build python wrappers (0)
    Some time ago i was asked to program device, connected to PC parallel port. Main program was written
    in python. First of all i found nice C library which perform the task: parapin . Building and
    installation is straightforward, so i don't stop on this. Then i start to build python wrapper.
    With SWIG its easy. First create file parapin.i , here is head of it: QUOTE %module parapin %{
    #include %} int pin_init_user(int lp_base); #define LPT1 0x378 #define LPT2 0x278 void
    set_pin(int pins); void clear_pin(int pins); void change_pin(int pins, int state); #define....
  3. Pagerank Checksum Algo For Python
    Google toolbar 4.0.x (0)
    google pagerank checksum algorithm in python Python is the best dynamic language:P....
  4. Prove Yourself As A Python Coder - Challenge Site
    (4)
    Recently I found a great site for python programmers. You have to find the url for the next level by
    solving a puzzle that requires Python (most other languages will also do quite well, but it's
    meant for python). The first levels you could do with some pen and paper or a calculator. But after
    a few puzzles they start to become more complicated and realy have to do more programming. Tell us
    how far you have comes. The challenge has 33 levels, but I only beated the first 3. That doesn't
    say much since I'm a total newbie at Python. -=jeroen=-....
  5. Python Versus Java ?
    Which of this language is the best? Why? (4)
    Chandler choosed Python, arguing that Python is more open source than Java. Apache brought an open
    source java to the market. Is Python covering so many domains than Java? Would it be possible to
    code every kind of application with Python? For wich reason would you choose Python for an
    application development? ....
  6. [python]got A Problem In My Little Program
    No reaction when button was pressed (1)
    I am a newbie in Python. After read some parts of 《OReilly -
    ProgrammingPython2ndEd.chm》, I try to write a small problem as following. But it is no
    reaction when I press the button. Does anyone can tell me why? CODE from Tkinter import * #
    get widget classes class Inputer(Frame): # subclass our GUI def __init__(self,
    parent=None): # constructor method  Frame.__init__(self, parent)
     self.pack()  ent = Entry(self)  ent.insert(0, 'Type words here')
    # set text  ent.pack(side=LEFT....
  7. Python For Series 60
    (0)
    Python for Series 60 brings the Python programming language to the Series 60 Platform. With Python
    for Series 60 installed, developers can write Series 60 applications in Python, or embed the Python
    interpreter into Symbian C++ applications for the platform. Python for Series 60 is based on Python
    2.2.2; However, in addition to supporting many of the Python Standard Library modules, Python for
    Series 60 includes a number of Platform-specific modules for access to native GUI widgets, Bluetooth
    and GPRS networking, GSM Location information, SMS Messaging, and more! P....
  8. Python (win32)
    Anyone Experienced? (1)
    So of late I've become increasingly interested in the whole bitTorrent trend, and I was possibly
    looking into dabbling in a release of my own... I was wondering if anyone has any experience with
    Python, and if so, which IDE should I use... I have Emacs (of course), but it's more hackerish
    than userfriendly, and I'm so noob with python i need to use a p*ssy prog that spoils you with
    dropdowns and context-sensitive help... Maybe I'm a dreamer, but oh well... Thx in advance...
    Oh yeah, this is for win32 development, as the people I would distribute my....
  9. Python : The Indentation
    How ? (4)
    Hi everyone , I program python since one month , and I have trouble with indentation with .... -
    Blocks with more than 1 conditions - Blocks with lists - And with caracters " strings " I'd
    like you to give me some examples if possible and explane me the bases of indentation. I need to
    know it if I want to progress. Thanks /biggrin.gif' border='0' style='vertical-align:middle'
    alt='biggrin.gif' /> Mathieu_021 ....
  10. Python
    just some questions about it. (5)
    I was wondering if anyone on here has used python. I want to create a program to handle some stuff
    in my table top RPGs, and that language was suggested to me as a good combination of speed and ease
    of learning. What do people on here think? Have any of you used python before? if so, what is a
    good IDE for mac, if you know? ....

    1. Looking for localizing, python, hacking, force, python, accept, natural, languages, words

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for localizing, python, hacking, force, python, accept, natural, languages, words
advertisement




Localizing Python - Some hacking to force python accept more natural languages words



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE