You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ulf Liedén <ul...@gmail.com> on 2010/03/19 14:14:57 UTC

Re: [Struts 2.1.8.1] Internationalization: how to remain in the current page ?

Hi Celinio,

personally, I would build a method that gives back the URL of the page you
are currently visiting, including all parameters. You put this method in a
superclass of all your actions, so that its available everywhere. In the
code you decide which locale parameter to set, according to your current
locale.

The method in the action class could look something like this:

 public String getLocaleSwitchURL() { String url = getContextPath() +
ServletActionContext.getActionMapping().getName() + ".action?" +
"request_locale="; if (getLocale().toString().equals("en_EN")) { url +=
"fr_FR"; flagURL = "fra.jpg"; } else { url += "en_EN"; flagURL = "eng.jpg";
} url += "&"; url += ServletActionContext.getRequest().getQueryString();
return url; } public String getFlagURL() { return getContextPath() +
"images/" + this.flagURL; }
All Strings should of course be configurable, and not hard coded like this.
But just to give you an idea how it could work.  You output the link like
this:

<a href="<s:property value="localeSwitchURL" escape="false"/>">
   <img src="<s:property value="flagURL" escape="false"/>" />
</a>

So if the user clicks the link, he will actually call the same page again,
with the same parameters.

Regards,
Ulf

On Fri, Mar 19, 2010 at 12:33 PM, Celinio Fernandes <ce...@yahoo.com>wrote:

> hi,
> I have a quick and basic question.
> Regarding internationalization, whenever a user clicks on a link with a
> flag, i want to change the locale (language)
> of the web application.
> That works well with the i18n interceptor.
> However i always redirect the user to the home page (home.jsp) when i do
> that because that is how i have setup the input result :
>    <action name="changeLanguage" class="ServicesAction"
>      method="changeLocale">
>   <result name="input">/home/home.jsp</result>
>    </action>
>
> My JSP looks like this :
> <s:url id="url" action="changeLanguage.action">
>      <s:param name="request_locale">fr</s:param>
>     </s:url>
>     <s:a href="%{url}" theme="xhtml"><img
> src="<%=request.getContextPath()%>/images/flag_fr.png" /></s:a>
>
> So my question is :
> how do you specify the current page in the input result name ?
> so that the user stays on the current page when he changes languages.
> Thanks for helping.
>
>
>

Re: [Struts 2.1.8.1] Internationalization: how to remain in the current page ?

Posted by Paweł Wielgus <po...@gmail.com>.
Hi,
i don't remeber that for sure, but try s:url without action and
namespace, i think it might be what You are looking for.

Best greetings,
Pawel Wielgus.

2010/3/19, Ulf Liedén <ul...@gmail.com>:
> Hi Celinio,
>
> personally, I would build a method that gives back the URL of the page you
> are currently visiting, including all parameters. You put this method in a
> superclass of all your actions, so that its available everywhere. In the
> code you decide which locale parameter to set, according to your current
> locale.
>
> The method in the action class could look something like this:
>
>  public String getLocaleSwitchURL() { String url = getContextPath() +
> ServletActionContext.getActionMapping().getName() + ".action?" +
> "request_locale="; if (getLocale().toString().equals("en_EN")) { url +=
> "fr_FR"; flagURL = "fra.jpg"; } else { url += "en_EN"; flagURL = "eng.jpg";
> } url += "&"; url += ServletActionContext.getRequest().getQueryString();
> return url; } public String getFlagURL() { return getContextPath() +
> "images/" + this.flagURL; }
> All Strings should of course be configurable, and not hard coded like this.
> But just to give you an idea how it could work.  You output the link like
> this:
>
> <a href="<s:property value="localeSwitchURL" escape="false"/>">
>    <img src="<s:property value="flagURL" escape="false"/>" />
> </a>
>
> So if the user clicks the link, he will actually call the same page again,
> with the same parameters.
>
> Regards,
> Ulf
>
> On Fri, Mar 19, 2010 at 12:33 PM, Celinio Fernandes <ce...@yahoo.com>wrote:
>
>> hi,
>> I have a quick and basic question.
>> Regarding internationalization, whenever a user clicks on a link with a
>> flag, i want to change the locale (language)
>> of the web application.
>> That works well with the i18n interceptor.
>> However i always redirect the user to the home page (home.jsp) when i do
>> that because that is how i have setup the input result :
>>    <action name="changeLanguage" class="ServicesAction"
>>      method="changeLocale">
>>   <result name="input">/home/home.jsp</result>
>>    </action>
>>
>> My JSP looks like this :
>> <s:url id="url" action="changeLanguage.action">
>>      <s:param name="request_locale">fr</s:param>
>>     </s:url>
>>     <s:a href="%{url}" theme="xhtml"><img
>> src="<%=request.getContextPath()%>/images/flag_fr.png" /></s:a>
>>
>> So my question is :
>> how do you specify the current page in the input result name ?
>> so that the user stays on the current page when he changes languages.
>> Thanks for helping.
>>
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org