[Desire Android Development] theGanymedes:
Locales

Well, since you started playing with it; let me teach you some fiddling I found out today:

Since I'm a Turkish guy and we have some extra letters in our alphabet; today I realized that the Busybox I compiled was unable to show those special characters; whilst Bash could (tab completion results were fine, but ls command was giving me crap :) )

Fiddling with, I learned about localedef and locale commands which are distributed with GlibC itself. Using those commands and setting a few variable can result to a very nice outcome...

What are those locale crap?

Well, if you didn't altered /data/share/i18n and /data/share/locale folders (after GlibC installation) you shall see that there are a lot of country codes and stuff there. These files are called "locale" folders; which keep information about the country's specific ways of handling characters, numeric format, date-time format etc..

In order to use them, first we need to install them to the system (in a proper manner) and then start using them!

How?

1- First, learn your country code and see if it's available at /data/share/i18n/locale folder. If it's, keep it in your mind (I'm going to use tr here, as I'm Turkish :D)

2- make a locale folder at your lib directory

mkdir /data/lib/locale

3- run the locale-installer command: localedef

localedef -c -i [B]<localefile>[/B] -f [B]<charmapfile>[/B] [B]<alias>[/B]

<localefile> is your locale file usually available at <cc>_<CC> format (like tr_TR) which is available at /data/share/i18n/locales folder.

<charmapfile> is your character code file. If you're not sure which is true, just use "UTF-8" which covers them all - it's what gave me best results.

<alias> an alias that you'll use. I made mine "tr.utf" for instance..

The command may give you errors; most of the times it's unimportant. If after following all those steps, you cannot make it work; just use another charmaps file suitable to you.

4- now, set LANG variable to your alias

export LANG=[B]<alias>[/B]

For instance, I wrote "export LANG=tr.utf" here. You write yours.

5- To test, run "iconv --help" command - voila! You see, help is in your language now! So is all your locale-supported applications!

*** What if I don't want the language, just the characters?

Then simply set LANGUAGE variable accordingly.

export LANGUAGE=en

Now it's English again..

*** NOTE: Sometimes shell doesn't apply your keyboard settings right away, even though it shows the characters. In order to fix it, bash should be restarted. Alas, there's no way for you to do that if you didn't install the bash I provided (because /etc/profile support is needed for initialization support).

How to make these settings apply automatically?

If you have installed the Bash I compiled; then all you have to do is making a initialization file.

1- make /etc/profile.d folder; if it doesn't exists.

mkdir -p /etc/profile.d

2- Now, run this command, by changing the necessary places:

cat <<EOF > /etc/profile.d/localeset.sh
export LANG=[B]tr.utf[/B] #use your alias here
export LANGUAGE=en # you don't have to put this, if you want your messages in your own language.
EOF

Now, everytime you run your shell, it's going to be in your locales!

I disliked it. How am I going to remove a locale?

Simple. just run this command:

localedef --delete-from-archive [B]<alias>[/B]

if you forgot your alias, just run

locale -a

and it will show you all installed locales.

If you need space, you can also delete locale support files which you don't want at /data/share/i18n/locales and /data/share/i18n/charmaps (these are character map files, actually). Also, the languages available in your system is at /data/share/locale folder - you can erase unused languages from here too if you wish.

So, what do you think? :)

**NOTE: I'm going to upload the Busybox with UTF support today - i didn't include UTF and Wide Char support before because I thought it was unnecessary; but not anymore! :)

What I realized is: magicly, now my keyboard buttons are recognized too (after shell restart of course)!

EDIT: Languages available in your system is listed in /data/share/locale folder; you can use the codes there to set LANGUAGE variable to show messages in that language ;)