Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-07
1
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

721 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