• Post Reply Bookmark Topic Watch Topic
  • New Topic

Internationalization of Exception Messages  RSS feed

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How does the JDK handle the Internationalisation of the messages from the different exception in the JDK.
Any help would be greatly appreciated.
Thanks
Sumit
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All internationalization is done through ResourceBundles. If you wanted to localize exception messages, you would need to pass ResourceBundle property keys as the exception message value, then whereever you do a System.out.println(exception.getMessage()), you would need to first retrieve the i18nized string from the ResourceBundle before invoking println.
 
sopal Pal
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for your message.
Throwable class in JDK has a methods called - getLocalizedMessage, is that something that one needs to override in order to Localise message.
I do understand the process of Internationalization and how Resource bundles are to be used, however I am not sure if when SUN delivers the JDK for Japanese Locale are their Exception messages Localised.
If so how do they do it.
Thanks
Sumit
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry about that. The fact that function existed is new to me. But yes--according to the API docs, you need to override the function and return the localized string. I would assume you would pass a parameter to the constructor, maybe in addition to an unlocalized message string if your exception will be used by components that don't recognize or use the getLocalizedString method.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it all depends on how you implement getMessage().
You cannot pass a Locale to a Throwable (you could of course create a subclass that does accept one).
If you implement getMessage() to return localised messages it will effectively do what Sun intended getLocalizedMessage() to be.
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I found how to use ResourceBundle class in Exceptional practices, Part 3, maybe you ought gain some benefit from it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!