17 April 2007

Free internationalized text in Java

The Locale object is absolutely phenomenal. It packs so much, for so little. If you've ever worked with any internationalized app, you know how hard it can be to get things translated and then figure out how to reference it later. Well, you can get a lot of stuff for free with Java. Take the snippet below for example.








import java.text.*;
import java.util.*;
public class DateInLanguage {

  public static void main (String[] args) {
    Locale[] locales = Locale.getAvailableLocales();
    Date d = new Date();
    for (int x=0; x<locales.length; x++) {
      Locale l = locales[x];
      DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, l);
      String country = l.getDisplayCountry();
      String language = l.getDisplayLanguage();      
      String formattedDate = df.format(d);
      System.out.println(l.toString() "\t"+ country + "\t"+language + "\t"+formattedDate);
    }
  }
}




Now, take a look at the output (trimmed):

ar Arabic 17 أبريل, 2007
iw_IL Israel Hebrew יום שלישי 17 אפריל 2007
ja_JP Japan Japanese 2007年4月17日
ko Korean 2007년 4월 17일 화요일
de_LU Luxembourg German Dienstag, 17. April 2007
el Greek Τρίτη, 17 Απρίλιος 2007
en_IE Ireland English 17 April 2007
en_IN India English Tuesday, 17 April, 2007
mk Macedonian вторник, 17, април 2007
tr_TR Turkey Turkish 17 Nisan 2007 Salı
uk Ukrainian вівторок, 17, квітня 2007
en English Tuesday, April 17, 2007


We just got a huge amount of stuff for free! Check it out:

  • translated, in language names for things like the day and month names

  • separators (commas switch to periods) by Locale

  • Ordering of elements in a Locale sensitive manner



Sure- the Locale object is programmed to do this. It should behave like so. But the translations are there too, and you get them on the house. If you look at Locale closely, you can even use it to get language and country names, in other Locales, thereby allowing you to generate a list of languages, with each language in the language it is in. Really helpful when you want to try and present a language or country selection.

16 April 2007

A new favorite: Gentoo

The folks at work delivered a spanking new machine to me about a week ago. A dual-dual-core Xeon. It looks a little like a mini-refrigerator. Pohl once posed a question to me after I had finished building my dream rig some four years back: "So, what operating system do you intend to run all that nice hardware with?"

My new rule is not to get comfortable. Ubuntu had become too easy. And mind-numbing: I didn't know what was going on under the hood any more, or I didn't have to worry about it. But isn't that half the fun?

I downloaded the Gentoo 2006.1 CD, and peeked at the excellent installation documentation. Even if you aren't going to install Gentoo, but want a good reference on what a Linux installation does, this is a fantastic resource. Going through the installation is like a practical exercise in understanding a lot of basics. The documentation even has links to further reading.

The biggest hurdle I encountered was trying to get my new kernel to boot. The problem turned out to be a non-issue. I didn't realize that the box was equipped with Serial Attached SCSI, and assumed that the disks were attached to a regular SATA-2 port. With that figured out, things went real smooth. The last time I had built a kernel must have been on 2.4.x, but with the 2.6.x builds, the process is really much simpler.

The package management system on Gentoo, Portage is about as simple to use as the APT system. Except, that you get to configure what your builds compile in via a make.conf file that provides explicit flags on library support you want or not. I've eschewed gnome, and found XFCE to be a comfortable, light environment that really does everything that Gnome did for me, with a little more ease, and quicker. Really- when was the last time that the wireless-networking applet worked better then a couple of iwconfig calls?

Oh, and then I accidentally stumbled on a fancy little music player called waif. Dubbed the "Console Audio Unfrontend", it approaches the concept of an audio player without the need for a front-end at all. Needless to say, I'm hooked.