Solved

How to get messages from resource file based on locale in Apache Axis.

Posted on 2009-07-07
1
226 Views
Last Modified: 2012-05-07
How do I get locale-sensitive messages from a message resource file (.properties file) while inside Apache Axis? Java/Struts provide a way to do this very easily in Action classes like the function listed in the code section below.

The correct message is returned from the correct locale-sensitive .properties file. How can I do this inside Apache Axis?



protected String getMessageResource(HttpServletRequest request, String resourceKey, Object[] args) {

	Locale userLocale = getLocale(request);
 

	ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);

	MessageResourcesConfig[] mrc = moduleConfig.findMessageResourcesConfigs();

        

	// Look through all module's MessageResources

	for (int i = 0; i < mrc.length; i++) {

		MessageResources resources = this.getResources(request, mrc[i].getKey());
 

		String text = resources.getMessage(userLocale, resourceKey, args);

            

		if (text != null) {

			return text;

		}

	}

	return "";

}

Open in new window

0
Comment
Question by:brian-barnett
1 Comment
 

Accepted Solution

by:
brian-barnett earned 0 total points
Comment Utility
Found a solution. Code snippet below.

My .properties files are in ../WEB-INF/classes/resources and are named like this:

messages_el_GR.properties
messages_es.properties
messages.properties

theLocale is a java.util.Locale object.
java.util.ResourceBundle bundle = org.apache.axis.i18n.Messages.getResourceBundle().getBundle("resources.messages", theLocale);

String text = bundle.getString("theKey");

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 37
word0 challenge 3 56
Java Jpanels and Jframe 8 19
Java JRE greater than 1.6 5 0
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now