• Post Reply Bookmark Topic Watch Topic
  • New Topic

I18n: using Resources  RSS feed

 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going through Learning Java (O'Reilly) and I'm playing with i18n. I'm just trying to write a simple program to help me become familiar with doing this. I'm getting a java.util.MissingResourceException at runtime. So, I must be doing something wrong when I define the resources. Can someone look at my code below and help me out?

Thanks,
Vince

 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Define your ListResourceBundle in their own files as public classes.
2) Your class for US locale is incorrectly defined. It should be named: Message_en_US
3) Your ListResourceBundle can include language and country in their names. If you just create them using their language, it will suffice for all locales that use that language. For instance Message_en should serve all locales whose language is English. However, if you want to use language and country, then your ResourceBundle will only serve that particular combination. Which takes me to your next mistake.
4) Your are creating your locale incorrectly. It should be create like this: Locale MALAY = new Locale("ms","MS") so that the ResourceBundle class that you defined can really be used.

The next code runs fine:






[ May 23, 2006: Message edited by: Edwin Dalorzo ]
 
Ramen Chatterjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vincente

Have a look at the Sun tutorial, it will answer your question and also cover using both classes and properties files as resources.

Come back if you are still stuck.

Ramen
 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Edwin and Ramen. I have it working now, using Edwin's examples and referring to the API at sun.com.

I'm going to read Sun's tutorial on the subject, too.

I favored using just the language code. This is applicable with Malay, too, as it is also spoken in Brunei and Indonesia.

This isn't for a real project yet. It's just for practice, now. However, I do anticipate doing some bilingual applications in the future. When I do work on something real, I'll probably look into tying my Resources into a database somehow. I saw a reference to that when I was trying to find the answer to my question before I posted.

Thanks,
Vince
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!