Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to internationalize custom validation messages?  RSS feed

 
Daniel Amadei
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm creating a validator method in my Managed Bean. When I return a message indicating a validation error, I'd like this message to be internationalized.

Reading Sun's JSF tutorial, they use a ResourceBungle programmatically to load the message from the bundle. My question is: is there a standard way to create the message giving it a key and JSF looks up my bundle to get the internationalized version?

Thanks,
Daniel
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there is. Assuming that your standard language in English, which would be contained in (say) "MyMessages.properties", you can simply add another file called "MyMessages_fr.properties", and it would automagically be used if the Locale is French. Same for "MyMessages_it.properties" etc. You can even have different versions for the same language, e.g. MyMessages_en_US.properties and MyMessages_en_GB.properties if you need to differentiate between American English and British English.
 
Daniel Amadei
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

I believe I did not expressed my doubt correctly. Let me clear

I know how i18n works in Java, in Struts and even in JSF. What I wanna know is if I can add the key to my message and JSF loads the message from my bundle.

Thanks,
Daniel
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "add the key to my message" mean? A key is not added to a message - a key is used to look up a message from the resource bundle.
 
Daniel Amadei
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

What I want is something like the ModuleException avaiable for Struts. In the constructor of the exception you inform a key and when the exception message is displayed, the internationalized message is shown.

http://struts.apache.org/1.3.8/apidocs/org/apache/struts/util/ModuleException.html

[]s
Daniel
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!