Posts Tagged ‘requst_locale’

How to change locale in Struts2 from database

i need to change the language of the user from the database, so to do this all in need is to set “request_locale”, see example. if i put this code below in my struts.properties, then dutch will be my default language

struts.locale = du_NL

a user can also change language, so i have to save the language settings in database, so that next time when the user logs in, he/she will get his/her language instead of the default one. to do this i have added “param” in my struts.xml

<result name="success" type="redirectAction">
                <param name="actionName">myAction</param>
                <param name="request_locale">${userLang}</param>
            </result>

“userLang” is what i have set from the action i.e. en, du or fr. once the “request_locale” is set the page will be displayed as per the “userLang”. we can see this by using the code below

session.get("WW_TRANS_I18N_LOCALE").toString();

because myAction.action?request_locale=en_US or myAction.action?request_locale=du_NL etc will set the locale in user session. i must say struts2 is really cool.

Advertisements