Discussion:
Changing portal language in Struts 1 (I18N) working only for one page
nordi
2011-08-10 06:48:20 UTC
Permalink
Hi All,

I've been trying to do language selection in Struts 1 (yes, i have to use
those). However, after sucessfully changing the language on the login page,
after logging in the language just reverts to using the default property
file. Can you tell me what i'm doing wrong here? What i need to do is select
the language for the whole portal from the login page. Here's what I've done
so far:

1) I have 3 property files with translated messages:
default ApplicationResources.properties
english ApplicationResources_en.properties
russian ApplicationResources_ru.properties

2) Entry to struts-config.xml
view plaincopy to clipboardprint?

1. <action path="/locale" type="xxx.LanguageSelectAction"
parameter="method">
2. <forward name="success" path="login.page" redirect="true"
</forward>
3. </action>
4.
5. ...
6.
7. <message-resources parameter="xxx.ApplicationResources"/>


3) LanguageSelectAction class

1. public class LanguageSelectAction extends DispatchAction {
2.
3. public ActionForward english(ActionMapping mapping, ActionForm
form,
4. HttpServletRequest request, HttpServletResponse response)
5. throws Exception {
6. request.getSession().setAttribute(Globals.LOCALE_KEY,
Locale.ENGLISH);
7. return mapping.findForward("success");
8. }
9.
10. public ActionForward russian(ActionMapping mapping, ActionForm
form,
11. HttpServletRequest request, HttpServletResponse response)
12. throws Exception {
13. request.getSession().setAttribute(Globals.LOCALE_KEY, new
Locale("ru"));
14. return mapping.findForward("success");
15. }
16.
17. }

4) Links in login.jsp:

<html:link page="/locale.do?method=english">English</html:link>
<html:link page="/locale.do?method=russian">Russian</html:link>



Any idea what i'm doing wrong here? Any advice is appreciated! I might be
making some obvious beginner error, since i've only been using struts since
yesterday:P

--
View this message in context: http://struts.1045723.n5.nabble.com/Changing-portal-language-in-Struts-1-I18N-working-only-for-one-page-tp4684829p4684829.html
Sent from the Struts - User mailing list archive at Nabble.com.
nordi
2011-08-10 05:29:22 UTC
Permalink
Hi All,

I've been trying to do language selection in Struts 1 (yes, i have to use
those). However, after sucessfully changing the language on the login page,
after logging in the language just reverts to using the default property
file. Can you tell me what i'm doing wrong here? What i need to do is select
the language for the whole portal from the login page. Here's what I've done
so far:

1) I have 3 property files with translated messages:
default ApplicationResources.properties
english ApplicationResources_en.properties
russian ApplicationResources_ru.properties

2) Entry to struts-config.xml
view plaincopy to clipboardprint?

1. <action path="/locale" type="xxx.LanguageSelectAction"
parameter="method">
2. <forward name="success" path="login.page" redirect="true"
</forward>
3. </action>
4.
5. ...
6.
7. <message-resources parameter="xxx.ApplicationResources"/>


3) LanguageSelectAction class

1. public class LanguageSelectAction extends DispatchAction {
2.
3. public ActionForward english(ActionMapping mapping, ActionForm
form,
4. HttpServletRequest request, HttpServletResponse response)
5. throws Exception {
6. request.getSession().setAttribute(Globals.LOCALE_KEY,
Locale.ENGLISH);
7. return mapping.findForward("success");
8. }
9.
10. public ActionForward russian(ActionMapping mapping, ActionForm
form,
11. HttpServletRequest request, HttpServletResponse response)
12. throws Exception {
13. request.getSession().setAttribute(Globals.LOCALE_KEY, new
Locale("ru"));
14. return mapping.findForward("success");
15. }
16.
17. }

4) Links in login.jsp:

<html:link page="/locale.do?method=english">English</html:link>
<html:link page="/locale.do?method=russian">Russian</html:link>



Any idea what i'm doing wrong here? Any advice is appreciated! I might be
making some obvious beginner error, since i've only been using struts since
yesterday:P

--
View this message in context: http://struts.1045723.n5.nabble.com/Changing-portal-language-in-Struts-1-I18N-working-only-for-one-page-tp4684665p4684665.html
Sent from the Struts - User mailing list archive at Nabble.com.

Loading...