• 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

How to avoid question marks in internationalization using JSTL fmt

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JSTL when we use a tag like
<fmt:message key="my.pending.key"/>

And if the resource bundle does not have an entry for that key, the HTML output will look like ???my.pending.key???

I know this helps in identifying the missing entries in the resource bundle and hence one can go and add them. But is there a way to tell JSTL not to render the question marks and just render the value as my.pending.key

Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JSTL Spec describes all the capabilities of the <fmt:message> tag, and customizing the error output is not one of them.

I personally cannot think of any reason to do so. Are you trying to provide some sort of customer-visible default?
 
Babji Reddy
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a prototype, I need to use a run time translator service provided by the customer, and for certain strings that have capitalized strings the translated value remains same and the service does not add such strings to the bundle. The expected behavior is that if you don't find the translation display the source as is.

I have discussed with the customer to add the strings to bundle even if there is no translation, but in turn I was asked to see if I can render the original text as is. And JSTL adds the question marks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah -- lazy client syndrome.

One approach you might take is to create a tag file that would handle this for you. The tag file could use the <fmt:message> tag with the var attribute to assign the value to a scope variable. You can check the variable, and if needed, use the key directly rather than the error output.
 
Babji Reddy
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your suggestion seems much elegant than the if/else check that I am doing in JSTL. These if/else are making my JSTL tags messy
Can you please elaborate with a bit more if you do not mind.
How would such custom tag syntax looks like? and how will the code behind the tag looks like?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing tag files is easy. Look up a tutorial or in the JSP Spec.

Within the tag file, assuming that it is defined with an attribute named key, you can use:This will write the result of the lookup into scoped variable value, which you can then test.
 
Babji Reddy
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
worked like a charm! another happy client...
Thank you..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

We have a similar requirement , can someone explain in detail what exactly needs to be done to hide ???.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with the approach already described?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic