Hello
 
> Hi Evgeny and hi everyone reading,
> i've tried all the day to find a workaround but it seems that the
> fmt:setLocale is not a solution.
> I ended my tests with this basic try that demonstrates that, given two
> resources named MyResource_it.properties and MyResource.properties, you cant
> switch on the fly the Locale used in a tld.
> 
> ---- case 1:
> <fmt:setBundle basename="MyResource" var="res" /><br/>
> <fmt:setLocale value="it" />
> Italiano: <fmt:message key="sayhello" bundle="${res}"/><br/>
> <fmt:setLocale value="en" />
> English: <fmt:message key="sayhello" bundle="${res}"/><br/>
> 
> ---- result 1:
> Italiano: Ciao!
> English: Ciao!
> 
> ---- case 2: (simply switch the order of the setLocale, first en then it)
> <fmt:setBundle basename="MyResource" var="res" /><br/>
> <fmt:setLocale value="en" />
> English: <fmt:message key="sayhello" bundle="${res}"/><br/>
> <fmt:setLocale value="it" />
> Italiano: <fmt:message key="sayhello" bundle="${res}"/><br/>
> 
> ---- result 2:
> English: Hello!
> Italiano: Hello!
> 
> so, back to my problem, the ability to localize a <stripes:message/> in
> different languages in different areas of the page cant be relied upon a
> setLocale, since the setLocale can be set only once before any localized
> output.
> 
> if u have any idea to achieve this, it would be welcome. otherwise i'm
> thinkinkg to write my own <mycustomtag:message /> that accept a lang
> parameter
> 
> thank u very much
> mirko
> 

Hello,
Well, your code shouldn’t work at all. Because you calling setBundle _before_ 
setting locale, so your bundle variable is created with _current_ locale and 
not the one you're setting in next step.

First do the following 

Add to web.xml
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>StripesResources</param-value>
    </context-param>

This tells servlet container to use StripesResources as default bundle, so JSTL 
will use this file while calling to fmt:message and you shouldn’t pass bundle 
variable to fmt:message. But this is optional if you don't want 
StripesResources to be used as default bundle.

Secondly try the code below anywhere in your JSP

    <fmt:setLocale value="it"/>
    <fmt:message key="sayhello"/>

    <fmt:setLocale value="en"/>
    <fmt:message key="sayhello"/>

It works like a charm. Plz note that you have to call setLocale first and later 
call your fmt tags.


-- 
Regards,
Evgeny Shepelyuk


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to