Sunday, November 25, 2007

Java web application Internationalization @ i18n

In order for an application to support i18n, generally, all of the permanent hard-coded text must be turned into labels and the actual text should be stored in a properties file commonly known as Application Resource or Resource Bundle.

The next step is, to declare that the view components (html/jsp/jsf) are using the UTF-8 encoding. This is very important as UTF-8 encoding supports most typeface (fonts) if not all of the languages in the world.

For static html. this can be done by using the meta tag in the
< head >
tag. example:
< meta equiv="Content-Type" content="" charset="utf-8" >

for the jsp/jsf, we can use this scriptlet before the < html > tag:
<%@ page contentType="text/html; charset=UTF-8" %>

if we are using struts as our web framework, we can skip doing the tedious and boring job of adding each of the pages with the scriptlet codes by adding this code in our struts-config.xml:
< controller contenttype="text/html; charset=UTF-8">


For the struts part, it will only work if none of the jsp/jsf skips the controller servlet. (direct linking from page to page without using global forwards).

If the Resource files are in a language that uses characters other than the normal English characters, we must convert them into Unicode ASCII characters. for example, if we have a Resource file that contains Chinese characters. In this case, we must convert it into Unicode ASCII characters.

to do this, we can use the native2ascii program that comes with the JDK itself. If we have already set the environment variable to point to our JDK directory, then we can already invoke the native2ascii command from anywhere.

Anyway, here's an example on how to convert a resource file with Chinese characters named ApplicationResources_cn.properties to Unicode ASCII encoding.

native2ascii -encoding UTF-8 ApplicationResources_zh.properties ApplicationResources_zh.properties.

Open the file again and you will see that the Chinese characters are now converted into sequences of \uxxxx. Don't worry, it will display fine when you deployed it in your web container and run it in your web browser.

Monday, November 5, 2007

Cherating - company trip

I just got back from Cherating, Pahang. It was really tiring but I had a lot of fun although I do feel a bit bored at certain times. It was company trip. Something like a family day where we get into teams and play against each other.

The journey took about 4 hours from KL, from the Patimas office to be exact. Although I only slept for about 4 hours the night before, I didn't feel sleepy at all. Arrived at Suria Beach Resort, Cherating around 5.30pm and checked in. I got the room 231 all for myself as my should be roommate decided not to come (I think, or maybe I am given the room for myself..LOL). Went down to the team 'war cry' at 6 and had dinner at an open air lounge at 8. The food was quite okay and after the selection of games, (I was drafted to play beach soccer. Damn, what I really wanted is to play paintball) i just went back to my room, had a nice warm shower and lay down for a while when later at 12 I decided to go for a walk around the hotel compound. So I went to the lobby with the intent of watching the large TV there (it can tune to channels that the TVs in the hotel rooms don't have) when suddenly a guy (I forgot to ask his name) came and told me that some people invited me to their room and it turns out to be Woon Fei and Jian Li and they invited me to join them playing cards. I don't know what the game was called but it's good enough to kill the time. Around 1am, I went back to my room and tuned in to Cinemax and watched Dragonheart: A New Beginning. Quite a nice movie but it doesn't suit to be labeled as an action film. I went to dreamland around 2.30am.

The next day, I woke up at 730am. Tune in to MTv, took a warm shower, get dressed up and straight away headed to the lounge for breakfast. Chatted with a few guys and later head directly to the games venue. First half of the day, I was already exhausted. It's been a long time since I played any sports. Not to mention that it has been a long time since I exercised (LOL).
By the way, my soccer team loses big time. Most that made up the team are old timers and the yougsters (including me) are not in good shape at all to play stamina draining games like that.

Being sneaky, I went back to my room at 1145am, took another warm shower to ease my aching muscles and took a nap. Woke up at 2pm, missed my lunch (I don't have the appetite to eat anyway with all the muscle cramps and ache) and continued the other half of the day with the tele-matches which aggravated my muscle pain. But I rather enjoyed the tug of war. It's not that tiring. Maybe it's because that during all theses years, only my stamina is drained, and not the strength that I acquired during my younger years practicing the martial arts (LOL). After all is done, I went for a swim at both the sea and later, hotel's swimming pool.

After the dinner and the prize giving ceremony, (my team, the Thundercats got the 2nd place) I hang out with my PSG colleague: Jocelyn, Chen Hao and Yih Ching at the beach, looking at hermit crabs and Anselm went into the waters to see if there's any planctons there (and yeah, there was a lot of them). Later on, we loiter at the lounge having some chit chat with Susan andn Mei Yan. Yih Ching was so enthusiastic on going to the stage for karaoke (i don't do karaokes, I don't have a beautiful voice but Yih Ching's enthusiasm and her really cute face when she smiles made me unable to resist on not to follow..LOL) when some of the other male colleagues (from HPD, i think), got really dead drunk and forced us (not including me, I ran away to the next table just in time) to drink liquor. I was like WTH??? I don't care if it's your birthday or what but forcing people against their will is really wrong. Not to mention that they're making a fool of themselves with their stupid, 'disturbing' and really disgusting acts. Just because of that, we had to cancel the karaoke plan and moved to the lobby. Had a nice chit chat about many things including ghost stories and Anselm joined us again while playing pool (which i lost twice with him, badly.. LOL)

Earlier, we planned to watch the sunrise together but since it was so late (it was 2 am when we went back to our rooms) and I forgot who answered 'no' when I asked again that were we to continue the plan so since I am already determined to see the sunrise at the beach, (it's already 10 years since my last time) i woke up at 530, took a long nice refreshing warm shower,performed the morning prayer and head out to beach. The sky was really clear with only a bit of clouds and it was really starry. I got to see the first light of dawn, it was really beautiful. Red, violet, blue and black in a colour gradient with twinkling stars and I was there sitting on the sand staring at the scenery, enjoying the song of the waves. Around 6am, I went back to my room to pack up my things, and took a nap before the breakfast and around 1030am, we departed back to KL.

and now I'm having stiff muscles and the pain is undescribable. I had a hard time getting myself up from the bed. LOL.

That's all for now. Time to get ready for work.