Sunday, 8 June 2008

Yoruba Custom Keyboard in Ubuntu

I found it interesting that there was any support at all for yoruba when I first started using ubuntu two years ago. So since I'm not in school this summer and work is getting progressively more boring - i never thot I'd get fed up programming - I decided to spend the better part of this sunday getting the yoruba keyboard working on my system. Here are the steps I took to get it to work:

1. Create a file called yo.
2. Copy the following lines into the file you just created

// $XKeyboardConfig: xkeyboard-config/symbols/gb,v 1.11 2006-10-03 22:25:41 svu Exp $
// based on a keyboard map from an 'xkb/symbols/gb' file
// $XFree86: xc/programs/xkbcomp/symbols/gb,v 1.6 2003/10/04 10:25:14 pascal Exp $

partial default alphanumeric_keys
xkb_symbols "basic" {

// Describes the differences between a very simple en_US
// keyboard and a very simple yoruba keyboard layout defined by ... blah blah blah

include "latin"

name[Group1]="Yoruba Nigeria";

key { [ obelowdot, Obelowdot, q, Q ] };
key { [ U1E63, U1E62, z, Z ] };
key { [ ebelowdot, Ebelowdot, x, X ] };

//grave
key { [ U0340, U0341, v, V ] };
//acute
key { [ U0341, U0340, c, C ] };

include "level3(ralt_switch_multikey)"
};

3. Move the file to /etc/X11/xkb/symbol

- open your terminal
- run the following command. (I'm assuming that the file you just created was stored your desktop). Also note that you may have to specify your admin password to successful complete this command.

sudo mv ~/Desktop/yo /etc/X11/xkb/symbols/yo

4. Append the following lines to the file /etc/X11/xkb/rules/xorg.xml under the layout section


<layout>
<configitem>
<name>yo</name>
<shortdescription>Yo</shortdescription>
<description>Yoruba</description>
</configitem>
<variantlist>
</variantlist>
</layout>

5. Append the following line to the file /etc/X11/xkb/rules/xorg.lst under the ! layout section

yo Yoruba

6. Load the custom keyboard we just created.
- Open System -> Preferences -> Keyboard
- Select the Layouts Tab and Click the Add button. Look for the Layout matching the description you entered in step 4. If you've been following this tutorial verbatim then you should be looking for a layout called Yoruba
- One last thing you may want to do is make sure you know what the shortcut for switching keyboard layouts on your computer is. On my laptop pressing both Alt buttons together switches the keyboard layout. I also added you the MS Icon button. You can edit the shortcut for switching keyboard layouts by clicking the "Layout Options" button and then selecting "Layout Switching". Check/Uncheck whatever keys you wish to use for your shortcuts.
- You can close the keyboard configuration window now.

7. logout and log báck in. (Ctrl-Alt-Backspace if you like)

As always Ubuntu (and X based systems in general) rox.

Ok. Now if you want to know the how and why of all the voodoo that just took place here are a few links you can look up...

http://wikisource.org/wiki/Transwiki:Table_of_Unicode_characters,_32_to_9999
http://people.uleth.ca/~daniel.odonnell/Blog/custom-keyboard-in-linuxx11
http://www.linux.com/articles/113715

http://www.alt-i.org/projects.htm

you'd also want to look up /usr/include/X11/keysymdef.h which contains the key name definitions

On a final note, I've got to say thanks to Daniel O' Donnell for blogging on how to create custom keyboards. Also if you click on the last link I gave above you'd notice that the keymap I used in this tutorial is based on the QWERTY keyboard you've in that project. I figured since they say that they've done their research theirs would be a good example to follow.



I might put up pictures if the need arises but I'm lazy so dont count on it :D



Just for the fun of it... here's some stuff I typed on my keyboard: ... Eniyan ni eyi ṣòro fun; ṣugbọn fun Ọlọrun ohun gbogbo ni ṣiṣe

Thursday, 1 November 2007

Yoruba & Scala

Okay! I'm really bored... but then that's what this blog is about... and by the way i'll be posting a lot about scala (my new night time hobby) from now on :)

I've been playing around some with SCALA recently (for more info on scala see www.scala-lang.org). So I figured let's say some one has a free dictionary and he wants to make the search feature that's real neat. So he offers alternative spellings of the search word that the user enters. Well functional programming and SCALA in particular makes this really easy to do. Just take a look at the code below.

object YorubaOptions {
def alternative(info:String):List[String]={
if(info==null || info.length==0) List("")
else if (info.length==1)
info match {
case "e"=>List("e", "\\u232", "\\u233")
case "o"=>List("o", "\\u242", "\\u243")
case "i"=>List("i", "\\u236", "\\u237")
case "u"=>List("u", "\\u249", "\\u250")
case "a"=>List("a", "\\u224", "\\u224")
case "s"=>List("s", "\\u7779")
case _=>List(info)
}
else
combine(alternative(info.substring(0, info.length-1)), alternative(info.substring(info.length-1)))
}

def combine(lhs:List[String], rhs:List[String]):List[String]=for(word1<-lhs;word2<-rhs)yield word1+word2

def main(args : Array[String]) : Unit = {
YorubaOptions.alternative("akin").foreach(println)
}
}



It's a divide and conquer algorithm. Really straight forward... Divide the search word until it's lenght is '1'. Then either produce a list of alternatives.

Now it's true that this code only makes sense when run in a unicode environment but porting it to javascript and setting the html encoding will take care of this. On the other hand, code like this can be in the back end (PHP, JEE, ASP.NET, whatever your fancy) so that search results can be generated based on the user's search key word.

So what's next...

I've written a small script to change the keyboard so that you can practically change type yoruba characters with the normal english keyboard in an html control. I'll probably look into creating a linux xkeyboard symbols file so that I can type yoruba straight up from my OS too. Then when I'm really bored I'll look at a windows solution (let's not get me started on why poor naija students, like I was, should jump on the linux band wargon if nothing to save cost and learn practically).

Phew... I did all this typing and I've still got about 24 minutes before SUPERNATURAL starts... now what I'm going to do for the next 20 minutes :(