• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I18n: using Resources

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic