Class ResourceBundleMessageResolver

java.lang.Object
com.oorian.i18n.ResourceBundleMessageResolver
All Implemented Interfaces:
MessageResolver

public class ResourceBundleMessageResolver extends Object implements MessageResolver
Resolves messages from Java ResourceBundle property files, with locale awareness.

Loads message templates from .properties files using the standard Java resource bundle mechanism. The locale is determined by OorianLocale.get(), so messages are automatically resolved in the user's current locale.

If a key is not found in the locale-specific bundle, the resolver falls back to the DefaultMessages English defaults.

Property file naming:

  • ValidationMessages.properties — default (English)
  • ValidationMessages_de.properties — German
  • ValidationMessages_fr.properties — French
  • ValidationMessages_ja.properties — Japanese

Example property file (ValidationMessages_de.properties):

 validation.required = Dieses Feld ist erforderlich
 validation.email = Bitte geben Sie eine gültige E-Mail-Adresse ein
 validation.length.between = Muss zwischen {min} und {max} Zeichen lang sein
 

Usage:


 // Configure in Application.initialize()
 MessageConfiguration.setMessageResolver(
     new ResourceBundleMessageResolver("ValidationMessages"));

 // Messages are now resolved per-locale
 OorianLocale.set(Locale.GERMANY);
 MessageConfiguration.resolve(DefaultMessages.REQUIRED);
 // → "Dieses Feld ist erforderlich"
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ResourceBundleMessageResolver

      public ResourceBundleMessageResolver(String baseName)
      Creates a new resource bundle message resolver.
      Parameters:
      baseName - the base name of the resource bundle (e.g., "ValidationMessages")
  • Method Details

    • resolve

      public String resolve(String key, Object... params)
      Resolves a message from the resource bundle for the current locale.

      The locale is obtained from OorianLocale.get(). If the key is not found in the bundle, resolution falls back to DefaultMessages.

      Specified by:
      resolve in interface MessageResolver
      Parameters:
      key - the message key
      params - alternating key-value pairs for parameter substitution
      Returns:
      the resolved and parameterized message