Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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

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
brian-barnett
Asked:
brian-barnett
1 Solution
 
brian-barnettAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now