You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alireza Fattahi <af...@yahoo.com> on 2013/09/08 13:10:07 UTC

s:if and locale

HI,
 
I have used the strtuts I18n feature for managing the localization.  The site works fine and the messages are selected from correct resource bundels.
 
I have this problem....
 
I want to change css base on the user locale.
So I use below code in jsp:
**************************
The locale is = ${locale}  //Here the correct locale is displayed!
<s:if test="%{locale == 'en_US'}"> //This condition is always false
     <link href="site-en.css" rel="stylesheet" type="text/css" />
</s:if>
<s:else>
   <link href="site-other.css" rel="stylesheet" type="text/css" />
</s:else>
**************************

No matter what the locale value is, always the else condition is triggered !!
The jsp out puts 
**************
The locale is=en_US
   <link href="site-other.css" rel="stylesheet" type="text/css" />
**********


When I see the Struts ValueStack with <s:debug/> the locale value is correct and is what it has too.

Is there any thing wrong with my test conditin please help!

~Regards,
~~Alireza Fattahi

Re: s:if and locale

Posted by Dave Newton <da...@gmail.com>.
Is the locale a string?
On Sep 8, 2013 7:10 AM, "Alireza Fattahi" <af...@yahoo.com> wrote:

> HI,
>
> I have used the strtuts I18n feature for managing the localization.  The
> site works fine and the messages are selected from correct resource bundels.
>
> I have this problem....
>
> I want to change css base on the user locale.
> So I use below code in jsp:
> **************************
> The locale is = ${locale}  //Here the correct locale is displayed!
> <s:if test="%{locale == 'en_US'}"> //This condition is always false
>      <link href="site-en.css" rel="stylesheet" type="text/css" />
> </s:if>
> <s:else>
>    <link href="site-other.css" rel="stylesheet" type="text/css" />
> </s:else>
> **************************
>
> No matter what the locale value is, always the else condition is triggered
> !!
> The jsp out puts
> **************
> The locale is=en_US
>    <link href="site-other.css" rel="stylesheet" type="text/css" />
> **********
>
>
> When I see the Struts ValueStack with <s:debug/> the locale value is
> correct and is what it has too.
>
> Is there any thing wrong with my test conditin please help!
>
> ~Regards,
> ~~Alireza Fattahi

Re: s:if and locale

Posted by Hernán <he...@gmail.com>.
I know this works correctly:

    <s:div cssClass="title">
        <s:if test="#session.request_locale == 'es'">
            <s:property value="#request.genericPresentation.titleEs"
escapeHtml=""/>
        </s:if>
        <s:elseif test="#session.request_locale == 'en'">
            <s:property value="#request.genericPresentation.titleEn" />
        </s:elseif>
        <s:elseif test="#session.request_locale == 'pt'">
            <s:property value="#request.genericPresentation.titlePt" />
        </s:elseif>
    </s:div>


On Tue, Sep 10, 2013 at 3:08 PM, Chris Pratt <th...@gmail.com>wrote:

> locale.language is just the language, so it will never match the Language
> plus the Country.  If you need to test both you could do:
>
> <s:if test="%{(locale.language == 'en') && (locale.country == 'US')}">
>
> You might even be able to get away with:
>
> <s:if test = %{(locale.language + '_' + locale.country) == 'en_US'}">
>
> But I haven't tested it to be sure.
>   (*Chris*)
>
>
> On Tue, Sep 10, 2013 at 12:39 AM, Alireza Fattahi <afattahi@yahoo.com
> >wrote:
>
> > Thanks for your solution .
> > The
> > <s:if test="%{locale.language == 'en_US'}">
> > did not work! I don't know why !
> >
> > But I used your solution which seems much better tahn mine !
> >
> > ~Regards,
> > ~~Alireza Fattahi
> >
> >
> > ________________________________
> >  From: Chris <ch...@yahoo.fr>
> > To: Struts Users Mailing List <us...@struts.apache.org>; Alireza Fattahi
> <
> > afattahi@yahoo.com>; Chris <ch...@yahoo.fr>
> > Sent: Monday, 9 September 2013, 7:49
> > Subject: Re: s:if and locale
> >
> >
> > Hello ,
> > Could you please write how do you define
> >
> > The locale is = ${locale}  //Here the correct locale is displayed!
> > I see in my browser  ( even source code )
> >
> > The locale is =   //Here the correct locale is displayed!
> >
> >
> > ________________________________
> > Please try this expresion and tell us if it works
> > <s:if test="%{locale.language == 'en_US'}">
> >
> > You will have to test your "locale" it in every jsp ?
> > Couldn't you use for example, a global.properties file and struts.xml
> > <constant name="struts.custom.i18n.resources" value="global" />
> >
> > in the file global.properties :cssfile=englshstyle.css
> > in the file global_es.properties :cssfile=spanishstyle.css
> > in yourjsp : <link href='<s:text name="cssfile" />' rel="stylesheet"
> > type="text/css" />
> > It works with sample
> >
> http://struts.apache.org/development/2.x/docs/message-resource-files.html
> > but the links are with parameter like .... action?request_locale=en
> > and you will need many properties file
> >
> >
> >
> > ________________________________
> > HI,
> >
> > I have used the strtuts I18n feature for managing the localization.  The
> > site works fine and the messages are selected from correct resource
> bundels.
> >
> > I have this problem....
> >
> > I want to change css base on the user locale.
> > So I use below code in jsp:
> > **************************
> > The locale is = ${locale}  //Here the correct locale is displayed!
> > <s:if test="%{locale == 'en_US'}"> //This condition is always false
> >      <link href="site-en.css" rel="stylesheet" type="text/css" />
> > </s:if>
> > <s:else>
> >    <link href="site-other.css" rel="stylesheet" type="text/css" />
> > </s:else>
> > **************************
> >
> > No matter what the locale value is, always the else condition is
> triggered
> > !!
> > The jsp out puts
> > **************
> > The locale is=en_US
> >    <link href="site-other.css" rel="stylesheet" type="text/css" />
> > **********
> >
> >
> > When I see the Struts ValueStack with <s:debug/> the locale value is
> > correct and is what it has too.
> >
> > Is there any thing wrong with my test conditin please help!
> >
> > ~Regards,
> > ~~Alireza Fattahi
> >
>



-- 
Hernán

Re: s:if and locale

Posted by Chris Pratt <th...@gmail.com>.
locale.language is just the language, so it will never match the Language
plus the Country.  If you need to test both you could do:

<s:if test="%{(locale.language == 'en') && (locale.country == 'US')}">

You might even be able to get away with:

<s:if test = %{(locale.language + '_' + locale.country) == 'en_US'}">

But I haven't tested it to be sure.
  (*Chris*)


On Tue, Sep 10, 2013 at 12:39 AM, Alireza Fattahi <af...@yahoo.com>wrote:

> Thanks for your solution .
> The
> <s:if test="%{locale.language == 'en_US'}">
> did not work! I don't know why !
>
> But I used your solution which seems much better tahn mine !
>
> ~Regards,
> ~~Alireza Fattahi
>
>
> ________________________________
>  From: Chris <ch...@yahoo.fr>
> To: Struts Users Mailing List <us...@struts.apache.org>; Alireza Fattahi <
> afattahi@yahoo.com>; Chris <ch...@yahoo.fr>
> Sent: Monday, 9 September 2013, 7:49
> Subject: Re: s:if and locale
>
>
> Hello ,
> Could you please write how do you define
>
> The locale is = ${locale}  //Here the correct locale is displayed!
> I see in my browser  ( even source code )
>
> The locale is =   //Here the correct locale is displayed!
>
>
> ________________________________
> Please try this expresion and tell us if it works
> <s:if test="%{locale.language == 'en_US'}">
>
> You will have to test your "locale" it in every jsp ?
> Couldn't you use for example, a global.properties file and struts.xml
> <constant name="struts.custom.i18n.resources" value="global" />
>
> in the file global.properties :cssfile=englshstyle.css
> in the file global_es.properties :cssfile=spanishstyle.css
> in yourjsp : <link href='<s:text name="cssfile" />' rel="stylesheet"
> type="text/css" />
> It works with sample
> http://struts.apache.org/development/2.x/docs/message-resource-files.html
> but the links are with parameter like .... action?request_locale=en
> and you will need many properties file
>
>
>
> ________________________________
> HI,
>
> I have used the strtuts I18n feature for managing the localization.  The
> site works fine and the messages are selected from correct resource bundels.
>
> I have this problem....
>
> I want to change css base on the user locale.
> So I use below code in jsp:
> **************************
> The locale is = ${locale}  //Here the correct locale is displayed!
> <s:if test="%{locale == 'en_US'}"> //This condition is always false
>      <link href="site-en.css" rel="stylesheet" type="text/css" />
> </s:if>
> <s:else>
>    <link href="site-other.css" rel="stylesheet" type="text/css" />
> </s:else>
> **************************
>
> No matter what the locale value is, always the else condition is triggered
> !!
> The jsp out puts
> **************
> The locale is=en_US
>    <link href="site-other.css" rel="stylesheet" type="text/css" />
> **********
>
>
> When I see the Struts ValueStack with <s:debug/> the locale value is
> correct and is what it has too.
>
> Is there any thing wrong with my test conditin please help!
>
> ~Regards,
> ~~Alireza Fattahi
>

Re: s:if and locale

Posted by Chris <ch...@yahoo.fr>.
Hello, 


When you said : "But I used your solution" Did you mean with parameters in the links like the sample ? 
http://struts.apache.org/development/2.x/docs/message-resource-files.html
This sample works with the second jsp, called register.jsp , with links and parameter given in the first jsp , called index.jsp
like this :

Please register for our prize drawing.
            http://localhost:xxxx/message_resource/registerInput.action;jsessionid=xxx?request_locale=en

I don't know if I'll have to work with country's parameter in links....

But for your example, do you have to find the user's country ? I mean with his browser or when he send his parameter himself with the link ( like the sample)

Or do you use the server's value , Locale.getDefault(), ...so the same for everybody ?




________________________________
 Thanks for your solution .
The 
<s:if test="%{locale.language == 'en_US'}"> 
did not work! I don't know why !

But I used your solution which seems much better tahn mine !

~Regards,
~~Alireza Fattahi


________________________________
From: Chris <ch...@yahoo.fr>
To: Struts Users Mailing List <us...@struts.apache.org>; Alireza Fattahi <af...@yahoo.com>; Chris <ch...@yahoo.fr> 
Sent: Monday, 9 September 2013, 7:49
Subject: Re: s:if and locale
  

Hello ,
Could you please write how do you define 

The locale is = ${locale}  //Here the correct locale is displayed!
I see in my browser  ( even source code ) 

The locale is =   //Here the correct locale is displayed!


________________________________
Please try this expresion and tell us if it works
<s:if test="%{locale.language == 'en_US'}"> 

You will have to test your "locale" it in every jsp ? 
Couldn't you use for example, a global.properties file and struts.xml
<constant name="struts.custom.i18n.resources" value="global" />

in the file global.properties :cssfile=englshstyle.css
in the file global_es.properties :cssfile=spanishstyle.css
in yourjsp : <link href='<s:text name="cssfile" />' rel="stylesheet" type="text/css" /> 
It works with sample http://struts.apache.org/development/2.x/docs/message-resource-files.html
but the links are with parameter like .... action?request_locale=en
and you will need many properties file  



________________________________
HI,
 
I have used the strtuts I18n feature for managing the localization.  The site works fine and the messages are selected from correct resource bundels.
 
I have this problem....
 
I want to change css base on the user locale.
So I use below code in jsp:
**************************
The locale is = ${locale}  //Here the correct locale is displayed!
<s:if test="%{locale == 'en_US'}"> //This condition is always false
     <link href="site-en.css" rel="stylesheet" type="text/css" />
</s:if>
<s:else>
   <link href="site-other.css" rel="stylesheet" type="text/css" />
</s:else>
**************************

No matter what the locale value is, always the else condition is triggered !!
The jsp out puts 
**************
The locale is=en_US
   <link href="site-other.css" rel="stylesheet" type="text/css" />
**********


When I see the Struts ValueStack with <s:debug/> the locale value is correct and is what it has too.

Is there any thing wrong with my test conditin please help!

~Regards,
~~Alireza Fattahi

Re: s:if and locale

Posted by Alireza Fattahi <af...@yahoo.com>.
Thanks for your solution .
The 
<s:if test="%{locale.language == 'en_US'}"> 
did not work! I don't know why !

But I used your solution which seems much better tahn mine !

~Regards,
~~Alireza Fattahi
 

________________________________
 From: Chris <ch...@yahoo.fr>
To: Struts Users Mailing List <us...@struts.apache.org>; Alireza Fattahi <af...@yahoo.com>; Chris <ch...@yahoo.fr> 
Sent: Monday, 9 September 2013, 7:49
Subject: Re: s:if and locale
  

Hello ,
Could you please write how do you define 

The locale is = ${locale}  //Here the correct locale is displayed!
I see in my browser  ( even source code ) 

The locale is =   //Here the correct locale is displayed!


________________________________
Please try this expresion and tell us if it works
<s:if test="%{locale.language == 'en_US'}"> 

You will have to test your "locale" it in every jsp ? 
Couldn't you use for example, a global.properties file and struts.xml
<constant name="struts.custom.i18n.resources" value="global" />

in the file global.properties :cssfile=englshstyle.css
in the file global_es.properties :cssfile=spanishstyle.css
in yourjsp : <link href='<s:text name="cssfile" />' rel="stylesheet" type="text/css" /> 
It works with sample http://struts.apache.org/development/2.x/docs/message-resource-files.html
but the links are with parameter like .... action?request_locale=en
and you will need many properties file  



________________________________
HI,
 
I have used the strtuts I18n feature for managing the localization.  The site works fine and the messages are selected from correct resource bundels.
 
I have this problem....
 
I want to change css base on the user locale.
So I use below code in jsp:
**************************
The locale is = ${locale}  //Here the correct locale is displayed!
<s:if test="%{locale == 'en_US'}"> //This condition is always false
     <link href="site-en.css" rel="stylesheet" type="text/css" />
</s:if>
<s:else>
   <link href="site-other.css" rel="stylesheet" type="text/css" />
</s:else>
**************************

No matter what the locale value is, always the else condition is triggered !!
The jsp out puts 
**************
The locale is=en_US
   <link href="site-other.css" rel="stylesheet" type="text/css" />
**********


When I see the Struts ValueStack with <s:debug/> the locale value is correct and is what it has too.

Is there any thing wrong with my test conditin please help!

~Regards,
~~Alireza Fattahi

Re: s:if and locale

Posted by Chris <ch...@yahoo.fr>.
Hello ,
Could you please write how do you define 

The locale is = ${locale}  //Here the correct locale is displayed!
I see in my browser  ( even source code ) 

The locale is =   //Here the correct locale is displayed!


________________________________
Please try this expresion and tell us if it works
<s:if test="%{locale.language == 'en_US'}"> 

You will have to test your "locale" it in every jsp ? 
Couldn't you use for example, a global.properties file and struts.xml
<constant name="struts.custom.i18n.resources" value="global" />

in the file global.properties :cssfile=englshstyle.css
in the file global_es.properties :cssfile=spanishstyle.css
in yourjsp : <link href='<s:text name="cssfile" />' rel="stylesheet" type="text/css" /> 
It works with sample http://struts.apache.org/development/2.x/docs/message-resource-files.html
but the links are with parameter like .... action?request_locale=en
and you will need many properties file  



________________________________
HI,
 
I have used the strtuts I18n feature for managing the localization.  The site works fine and the messages are selected from correct resource bundels.
 
I have this problem....
 
I want to change css base on the user locale.
So I use below code in jsp:
**************************
The locale is = ${locale}  //Here the correct locale is displayed!
<s:if test="%{locale == 'en_US'}"> //This condition is always false
     <link href="site-en.css" rel="stylesheet" type="text/css" />
</s:if>
<s:else>
   <link href="site-other.css" rel="stylesheet" type="text/css" />
</s:else>
**************************

No matter what the locale value is, always the else condition is triggered !!
The jsp out puts 
**************
The locale is=en_US
   <link href="site-other.css" rel="stylesheet" type="text/css" />
**********


When I see the Struts ValueStack with <s:debug/> the locale value is correct and is what it has too.

Is there any thing wrong with my test conditin please help!

~Regards,
~~Alireza Fattahi

Re: s:if and locale

Posted by Chris <ch...@yahoo.fr>.
Hello

Please try this expresion and tell us if it works

<s:if test="%{locale.language == 'en'}"> 

You will have to test the "locale" it in every jsp ? 
Couldn't you use for example, a global.properties file and struts.xml
<constant name="struts.custom.i18n.resources" value="global" />



________________________________
HI,
 
I have used the strtuts I18n feature for managing the localization.  The site works fine and the messages are selected from correct resource bundels.
 
I have this problem....
 
I want to change css base on the user locale.
So I use below code in jsp:
**************************
The locale is = ${locale}  //Here the correct locale is displayed!
<s:if test="%{locale == 'en_US'}"> //This condition is always false
     <link href="site-en.css" rel="stylesheet" type="text/css" />
</s:if>
<s:else>
   <link href="site-other.css" rel="stylesheet" type="text/css" />
</s:else>
**************************

No matter what the locale value is, always the else condition is triggered !!
The jsp out puts 
**************
The locale is=en_US
   <link href="site-other.css" rel="stylesheet" type="text/css" />
**********


When I see the Struts ValueStack with <s:debug/> the locale value is correct and is what it has too.

Is there any thing wrong with my test conditin please help!

~Regards,
~~Alireza Fattahi