PyTongue Programming in Non-English Languages

2
6719
pytongue

Student learning programming

In this remarkable article, which is aimed at both those who teach programming at various levels and general programming enthusiasts, the author, who is the creator of PyTongue, shows how Python programming can be taught without the use of English, making it easy to program in vernacular languages.

Every program needs to be converted to a string of bits in order to run. This has been so ever since the inception of programmable computers. If this is the case, is it that all we need to do is write the proper string of bits to make any program? Then, what do programming languages do?
After all, we are not writing bit-strings but are writing text based programs. The bit-strings are all that a computer needs to run. Programming languages exist to help us make sense of what we have written. This means that programming in our own language is very much a possibility. All that is needed is a method of translating the language to the appropriate bit-string. This is where PyTongue comes in handy. It lets you teach people who do not know the Latin script how to program.
I developed PyTongue precisely for the purpose of teaching programming to children who do not know English. Thus I can teach them Python without having to teach them English first. Python3 was the choice of language as it has good Unicode support throughout and the inherent nature of Python is that it has a short learning period. After a while, people do have to learn English as it is the language of the trade. This way, however, I can make sure that a child who has the potential to program does not miss out simply because of a language barrier.
PyTongue has simple logic powering it. It is a transliteration service, to be precise. It takes a program written in one language and transliterates it to normal Python code, which is in English. The new code is then executed.
To get started with PyTongue, we must first install Python3 and then PyTongue. For this article, Ubuntu 14.04 was used.
First, let’s make sure that Python3 is installed. Next, we create a directory called pytongue_folder and download PyTongue in it.

sudo apt-get install python3
cd ~
mkdir pytongue_folder
cd pytongue_folder
git clone https://github.com/theSage21/pytongue
cd pytongue

In case the git command shows an error, you can download the Zip file from the same link and unzip it. The effect is the same. You need to have a folder called pytongue. After that, navigate into the folder.
In order to write code in a certain language, we need to get the mapping for it. Some mappings like Hindi, Russian, etc, are already provided. Mappings are obtained by running pytongue-mapgen hi for Hindi and so on. The two-word short forms are from <https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes>
A mapping is a word-for-word translation of the basic keywords and built-ins in Python. To create a mapping, we need to create a file with the required language name and write a JSON encoded dictionary with the general structure of <new_lang>:<python_keyword>.
This creates a mapping for the requested language. While it is downloading the language, it prints out the keywords mapped. After this, we begin to write a program. For purposes of demonstration, let’s first write a simple ‘Hello world’ program and then a simple calculator in Hindi.
To write these programs, any plain text editor will do (Gedit, Vim, Notepad, etc). The first line of the program must always be of the format # <language_code_in_capitals>

code 1

code 2

This prompts you for two numbers and then an operation to perform on them. It prints out the result of the operation on the two numbers. The translation created for this program is shown below:

a = int(input(‘Enter a number’))
b = int(input(‘Enter another number’))
op = input(‘Enter the operation:’)
if op == ‘+’:
print(a + b)
if op == ‘-’:
print(a - b)
if op == ‘*’:
print(a * b)
if op == ‘/’:
print(a / b)

How would someone know what words to use? That is done using the created maps. The maps are stored as JSON in the languages folder. They are thus editable by hand. Hence, if some translation seems strange to you, you can simply edit by hand to make it more to your liking. In order to know what a particular function is called, you simply need to open the particular language file ($ gedit ./languages/RU for Russian), and look up the particular translation pair.

After writing the desired code, we need to run it. Instead of the traditional python3 hello.py command we would normally have issued, we run the shell script called pytongue.sh hello.py
We have now successfully written Python in Hindi. For other languages, similar procedures are followed. To sum up, we need to do the following:
1. Map the required language
2. Source the code with first line as # <Language_code>
3. Run the program with pytongue.sh <my_code>.py

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here