Solved

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

Posted on 2009-07-07
1
228 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
ID: 24800129
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 96
advertisement module in core php 4 162
how to install java on RHEL image on EC2 4 27
Is Applet the way to go for my drag and drop system? 8 14
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

777 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