Feeds:
Posts
Comments

Archive for the ‘Hindi’ Category

My Experiments With Hindi Part I

I had always wanted to learn Hindi although it was usually a low priority task. Hindi’s significance probably increases when you go to some foreign country like US. Most Indians here  know Hindi and the subtle pressure to learn Hindi increases. There is also the usual BS about it being the national language.

So finally I decided to learn Hindi . I had made some half hearted measures before and had abandoned my Hindi learning within weeks. So I was determined not to do it again. So here are the various steps I took to learn Hindi.

Ubuntu Changes

I realized that I will be using Hindi a lot – for eg reading articles or writing some basic text. So I added Hindi support to my OS (Ubuntu  – Karmic) . I am sure the steps given here will be  applicable to older Ubuntu versions too . Again , for other versions of Linux /Windows / Mac OS the steps can found in net.

Enabling Hindi Language Support :

1. System –> Administration –> Language Support.

2. Select Install / Remove Languages

3. Select Hindi from the list of languages.

4. Ubuntu will install necessary Hindi support for Ubuntu.

 

Toggling between Keyboards :

If you are like me , then you will primarily working in English and occasionally toggling to Hindi. To do that :

1. System –> Preference –> Keyboard

2. Select Hindi

3. Click on “Layout Option” button.

4. In the new window, select the option “Key(s) to change layout” . You can select any combination of keys to toggle between languages. I settled on Shift+Caps Lock.

 

Keyboard Indicator :

It is usually very useful to know which language keyboard is being used currently. Sometimes the reason the system is not accepting the password might be because, you were typing it in Hindi !! That has bitten me quite some time. If you are in Ubuntu, it is very easy to fix it.

On any GNOME panel right click and select “Keyboard Indicator” applet. It gives concise information about the current application’s keyboard. In Linux, each application can use one of keyboards simultaneously. For eg I can type in Vim in Hindi and use English in Firefox with no problems.

Hindi Fonts :

There are lot of free fonts from multiple places for Hindi. Do a simple Google search to get them.

Typing In Hindi :

The input methods (IME) in Ubuntu , does not really use a transliteration based typing. The mechanism used took some time to get used and after some time became very natural.

a) Consonants are typed with the appropriate letter for the sound. ie you type k to get क (not ka) . To get ख, you type K (k in caps).

b) The vowels are used to get the various combinations –

ka gives  का 
ke gives के 

kE gives कै
ki gives कि

kI gives की
ko gives को

kO gives कौ
ku gives कु

kU gives कू

 

Books And Courses

1. I looked around and finally settled on Teach Yourself Hindi by Rupert Snell as the book to follow, partly due to SOAS’s recommendation. It can be got at this Amazon link.

2. I found some good courses and course materials at UPenn, NCSU , Yale etc. More can be found by Googling. Take a look !!

Good Hindi Websites

I have not done extensive research into all good Hindi learning sites , I found some very useful ones.

1. ISpeakHindi – I Speak Hindi was probably the most comprehensive of all of the sites. They also have a very useful  podcast series for learning Hindi.  I try to learn a podcast or two everyday. Their wiki page has lot of useful information. It has a good classification of lessons from which you can sample.

2.  News Sites : There are lot of good Hindi news sites which gives news in reasonably simple Hindi. The most prominent of them is BBC Hindi site . Their Hindi site for Indian news is also good.   Of course, to get more authentic , Indian Hindi News from Indian newspapers see Google News Hindi site.

3. LiveMocha : I was told LiveMocha was useful for learning other languages although I did not find it very useful.

 

Other Tools

I also wrote some tools to help make my Hindi learning easier.

1. Hindi Translator : This is a Python script which takes a file and source,destination languages and converts the words in the file (which is in source language) to destination file using Google Translate API.  It can found here.

2. Flash Cards : This is a Flashcard like application which I used to quiz myself on the Hindi/English words. It expects all the files to be put in some folder (for eg one per chapter) . It now allows you to select one /all of the files for quizzing you. It allows both English to Hindi and Hindi To English. Unfortunately , I wrote the code in PythonCard, so I doubt it working in non Linux OS. It is also the code makes lot of assumptions , so might need some changes before being reusable. The code can be obtained here.

3. GNOME Hindi Scroller Applet : This is a simple GNOME applet which when added to a panel, keeps showing some Hindi word and its meaning every 10 seconds. It accepts its input from a file . I had written about this more at this blog post . The code can be obtained here .

 

I will keep adding more posts in this series as I learn more Hindi !!

Advertisements

Read Full Post »

I am currently learning Hindi (more on that in another post). I was thinking of  ways to improve my vocabulary. I decided to write a GNOME applet, that will display Hindi words and its meaning in the panel and refresh them periodically.
I chose to use Python, partly because I was lazy and partly because the app itself is pretty trivial.

I was surprised to find that there is not much documentation to develop GNOME applets in Python. Of all the sites I looked at only one had useful information , but even that was buried in the search results . The top result seems to be this page but it is woefully old. It does give you a basic idea but lot have changed after 2004 ! (For eg gnome.applet became gnomeapplet, God Knows why).  If you prefer code , you can check here and here ,although they dont have much explanation.

GNOME applets consist of two parts. A server file and the actual python file for the applet. The server file gives basic information about your applet like its unique id , title , description , the location of the executable etc. Its pretty much simple and straightforward that you can take any sample server file such as this and then start modifying it.

Here is the server file, I had used. (I am copying all the code here as I am having problem uploading arbitrary files to WordPress.)

Some things to note are :

a) I have given the full path of the python file. There are other alternate ways too but this is the easiest.

b) The IID in the server file and the python file has to match.

<oaf_info>

<oaf_server iid="OAFIID:GNOME_HindiScroller_Factory"
            type="exe"
            location="/home/neo/applet/hindiscroller.py">

        <oaf_attribute name="repo_ids" type="stringv">
                <item value="IDL:Bonobo/GenericFactory:1.0"/>
                <item value="IDL:Bonobo/Unknown:1.0"/>
        </oaf_attribute>
        <oaf_attribute name="name" type="string" value="HindiScroller"/>
        <oaf_attribute name="description" type="string" value="Python Hindi Scroller Applet"/>
</oaf_server>

<oaf_server iid="OAFIID:GNOME_HindiScroller"
            type="factory"
            location="OAFIID:GNOME_HindiScroller_Factory">

        <oaf_attribute name="repo_ids" type="stringv">
                <item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
                <item value="IDL:Bonobo/Control:1.0"/>
                <item value="IDL:Bonobo/Unknown:1.0"/>
        </oaf_attribute>
        <oaf_attribute name="name" type="string" value="HindiScroller"/>
        <oaf_attribute name="description" type="string" value="Python Hindi Scroller Applet"/>
        <oaf_attribute name="panel:category" type="string" value="Utility"/>
        <oaf_attribute name="panel:icon" type="string" value="iconimage.png"/>
</oaf_server>
</oaf_info>

The python code for the flasher is here. It is pretty simple and I have added basic comments to it.  The main reason I wanted to upload the code was to give an example of developing gnome applets using Python and OOPs. Most examples in net were doing applets without using classes. There are some basic things to note :

a)The parent class is gnomeapplet.Applet (not gnome.applet.Applet)

b) To add a timeout use gobject.timeout_add

c) The best way to debug the applet is to make it a separate window of its own. For my program adding a “-d” option makes it run in debug mode.

d) GTK label has set_markup function which allows HTML based code to be used as label text. Neat !

e) The python file has to be readable and executable by everyone.

The code per se , is very simple for the Python cognoscenti.


#!/usr/bin/env python
import pygtk
pygtk.require('2.0')

import gtk
import gnomeapplet
import gobject

import sys
import codecs
import random

class HindiScroller(gnomeapplet.Applet):
	#Reads a utf-8 file, reads all lines and returns them as a list with newlines stripped
	def readFile(self,fileName):
		f = codecs.open(fileName)
		allLines = f.readlines()
		f.close()
		strippedLines = [line.strip()  for line in allLines]
		return strippedLines

	#Picks a random word from the list. If its empty, it starts with original list again.
	def getNextWord(self):
		if len(self.wordsToShow) == 0:
			self.wordsToShow = self.allWords[:]
		selectedWord = random.choice(self.wordsToShow)
		self.wordsToShow.remove(selectedWord)
		english,hindi = selectedWord.split("|")
		wordInMarkups = "<b>" + english + "</b>   " + hindi
		return wordInMarkups

	#Displays the next word to GUI. Uses set_markup to use HTML
	def displayNextWord(self):
		wordToShow = self.getNextWord()
		self.label.set_markup(wordToShow)
		return True

	def __init__(self,applet,iid):
		self.timeout_interval = 1000 * 10 #Timeout set to 10secs
		self.applet = applet

		#File used as source expects each line in english|hindi format
		self.fileName = "/home/neo/applet/hindidict.txt"

		self.wordsToShow = []
		self.allWords = self.readFile(self.fileName)

		wordToShow = self.getNextWord()

		self.label = gtk.Label("")
		self.label.set_markup(wordToShow)
		self.applet.add(self.label)

		self.applet.show_all()
		gobject.timeout_add(self.timeout_interval, self.displayNextWord)

#Register the applet datatype
gobject.type_register(HindiScroller)

def hindi_scroller_factory(applet,iid):
	HindiScroller(applet,iid)
	return gtk.TRUE

#Very useful if I want to debug. To run in debug mode python hindiScroller.py -d
if len(sys.argv) == 2:
	if sys.argv[1] == "-d": #Debug mode
		main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		main_window.set_title("Python Applet")
		main_window.connect("destroy", gtk.main_quit)
		app = gnomeapplet.Applet()
		hindi_scroller_factory(app,None)
		app.reparent(main_window)
		main_window.show_all()
		gtk.main()
		sys.exit()

#If called via gnome panel, run it in the proper way
if __name__ == '__main__':
	gnomeapplet.bonobo_factory("OAFIID:GNOME_HindiScroller_Factory", HindiScroller.__gtype__, "hello", "0", hindi_scroller_factory)

I have to say , I am pretty much exhausted trying to upload/format code in WordPress. So I am not going to write a good tutorial as I originally intended to 😦 . Instead what I have done is that I have highlighted some lines which I think are important.

Some comments : Do read the files in the folder /usr/share/doc/python-gnomeapplet/examples . It has some sample files and the README file gives some nice information.

For a step by step discussion look here. Also PyGTK reference manual is here. You can also check out the GTK reference which is really good , but I had a hard time converting it to Python’s class structure.

Have fun !!

Read Full Post »