This is a very simple login demo web-app in struts 1.3 which support Internationalization and Localization (or a multilingual application which in English, Hindi, German, French and Spanish ). So before going any forward I have something share few day before writing this post I attended an interview for Struts 1x I have around 2+ year of experience in struts 1 and then ask me how to handle Internationalization and Localization in struts. And I have never worked with multilingual application before but have some idea about multiple resource file ending with a locale so as I came back got some time wrote and demo for the multilingual app.
This project structure is maven-archetype-webapp. And depencencies use are listed below.
We have used 5 properties file for five languages.
Similar to above properties file. We have all the other properties files.
This jsp is the first thing to appear on the screen here one can login or can language from the bottom. To show all the label as per our selected language we have used bean:message tag to display text from properties file corresponding to there key.
This Action class is use to change Locale of the current session context. As you can see in the following code we setting a Globals.LOCALE_KEY in session to as per our selected language. Whatever parameter value you set in message-resources in struts-config.xml it will now pick the value and append ‘_’ and your locale, then it will look for that properties file. If that files is not founded it will load default file (means file without locale).
In our case if we have selected french it will look for “ApplicationResource_fr.properties” file.
This is very simple struts configuration file nothing much in it. we just have on form bean loginform , a LoginAction and ChangeLanguageAction that is used to change the language.
If you have any question can write it down in comment below.
You and find the source on github or you can download it from here. I am sure any one can understand this by just take look at complate source code.
DGStack is web blog by digvijay bhakuni. This blog is about computer programming tips and trick. And some short tutorial and gettings started post about the framework, libriay, api and much more. The blog target mostly open source stuff like java, j2ee, nodeJs, angularJs, spring, struts, mongodb, mean, etc
This website claims no credit for any images posted on this site unless otherwise noted. Images on this blog are copyright to its respectful owners. If there is an image appearing on this blog that belongs to you and do not wish for it appear on this site, please E-mail with a link to said image and it will be promptly removed. And the information is best of my knowledge one can always write comment or mail regarding information is this blog.