Wednesday, August 10, 2011

Adding dictionaries to Android keyboard

I recently installed CyanogenMod-7.1.0-RC1 for my Wildfire, and I noticed that some dictionaries are missing from the default Gingerbread keyboard. What this means is that although you can select for example Dutch as input language, there will be no word suggestions. In this post I'll show you how to add those missing dictionaries.

Acquiring dictionaries
The keyboard application is stored in the file /system/app/LatinIME.apk. Online, you can find different LatinIME's that have more dictionaries. I have compiled a list of dictionaries available to two custom roms:

CyanogenMod: da, de, en, es, fr, it, iw, ka, pt, ru, sv
GingerVillain: da, de, en, es, it, nb, nl, sv

There are more custom roms available that may have different languages and you could also try official roms from HTC or any other company that publishes Android phones. When you've found and downloaded a good rom, store the file system/app/LatinIME.apk found in the zip.

Now there are two options. The first is replacing LatinIME.apk and the second is modifying the original to support extra dictionaries. In my case, the two keyboards I wanted are English and Dutch, so for me replacing the CyanogenMod's LatinIME.apk with the one from GingerVillain was good enough. You can see below how to copy the file.

Adding a dictionary
To add something to an apk, we first need to extract the apk. This is done using apktool. Download and extract both apktool and the helper scripts (depending on your OS) to the same folder.

Also make sure that you have adb, the android debugger and that you've set your phone to USB debugging mode (look here if you don't know how to do that). To get adb you need to install the SDK platform tools (see here).

Put the LatinIME.apk with the dictionary you want in the folder where you've stored apktool and rename it to LatinIME_new.apk. When you've done that open a console (cmd.exe in Windows) and navigate to the folder where you've stored apktool.

adb pull /system/app/LatinIME.apk LatinIME_old.apk
apktool d LatinIME_old.apk old
apktool d LatinIME_new.apk new

Now that you've done that, you have two new folder: old and new. The old one contains the contents of the original LatinIME.apk and the new folder contains the dictionary you want. Go to the new directory and find res/raw-YOURLANG, where YOURLANG is the two letter abbreviation of your language. Now copy this directory to res folder in the old directory.

Now that you've added the file to the extracted apk, it's time to repackage it.

apktool b old LatinIME.apk

The newly generated LatinIME.apk contains your dictionary, along with all the old ones. Now we have to upload this file to your phone.

Updating the LatinIME.apk file
When you've got the LatinIME.apk you want, we can overwrite the file in your /system/app directory on your phone. Unfortunately, the /system folder is mounted read-only, so we have to remount it first. For the following steps, we make use of the adb again.

adb pull /system/app/LatinIME.apk LatinIME_backup.apk
adb remount
adb push LatinIME.apk /system/app/LatinIME.apk
The first line makes a backup. You can leave that out if you've already done so.

Conclusion
Now that you've updated your LatinIME.apk, you'll need the reboot your phone. After that, you're all set to use your new, fancy dictionary!

No comments:

Post a Comment