aspose file tools*
The moose likes JSP and the fly likes How to avoid question marks in internationalization using JSTL fmt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to avoid question marks in internationalization using JSTL fmt " Watch "How to avoid question marks in internationalization using JSTL fmt " New topic
Author

How to avoid question marks in internationalization using JSTL fmt

Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

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

Joined: Jan 24, 2006
Posts: 106
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

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

Joined: Jan 24, 2006
Posts: 106
worked like a charm! another happy client...
Thank you..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Vinay mailtovinay
Greenhorn

Joined: Jan 23, 2013
Posts: 1

We have a similar requirement , can someone explain in detail what exactly needs to be done to hide ???.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

What's wrong with the approach already described?
 
Consider Paul's rocket mass heater.
 
subject: How to avoid question marks in internationalization using JSTL fmt