简体   繁体   中英

Localization in struts1

I have a requirement in my project to support Localization in web application.

The project is a web application which provides services to its users.

It is based on Struts 1.2.

Requirement: The labels in the jsp page can be controlled according to the user's preference ie the labels can differ according to the user logged in.

The user can change the text of the label what he/she wants to see.

How can I achieve this in Struts 1.2?

I know about Struts i18n, but it is based on the locale.

What I'm thinking is to create a separate property file for each user. How can I use the same property file for displaying the labels in JSP in Struts 1.2?

Please help.

In a single property file, you can have multiple resource ids with different username.

For ex:
user1.title=Title for user1

user2.title=title for user2

and create dynamic key in bean:message depends upon the user loggedin.

In struts-config.xml

<message-resources parameter="com.struts.MessageResource" key="appResource"></message-resources>

In JSP:

<%  
String username= (String) request.getAttribute("username");  
%>
<bean:message bundle="appResource" key="<%= username + ".title"%>" />

Instead of having different labels with respect to user for their preferences, you can control user's preferences by creating your own templates and make use of them. This way, you don't need to add resource ids for every new user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM