org.clazzes.util.aop.i18n
Interface Messages

All Known Implementing Classes:
MessagesImpl

public interface Messages

Interface for i18n message retrieval through a ResourceBundle and abbreviated formatting using String.format(java.util.Locale, String, Object...).

Additionally, this interface supports mapping to plural forms using a given PluralRule.


Method Summary
 String formatPluralString(double n, String key, Object... args)
          Format the given localized message with possible plural forms with a set of arguments.
 String formatString(String key, Object... args)
          Format the given localized message with a set of arguments.
 Locale getLocale()
           
 PluralRule getPluralRule()
           
 String getPluralString(double n, String key)
          Find a localized message with possible plural forms.
 String getString(String key)
           
 

Method Detail

getLocale

Locale getLocale()
Returns:
The underlying locale.

getPluralRule

PluralRule getPluralRule()
Returns:
The underlying plural rule.

getString

String getString(String key)
Parameters:
key - The key to search for in the message catalog.
Returns:
The localized message.
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string

formatString

String formatString(String key,
                    Object... args)
Format the given localized message with a set of arguments. A shortcut for
 String.format(i18n.getLocale(),i18n.getString(key),args)
 

Parameters:
key - The key to search for in the message catalog.
args - The argument to the format string.
Returns:
The formatted localized message.
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string

getPluralString

String getPluralString(double n,
                       String key)
Find a localized message with possible plural forms. This method searches for the key <key>.<tag>, if the associated PluralRule return a non-null plural tag like one or zero. If a message for these special keys is not found or the plural rule return NullPointerException, the unmodified key is used to fetch the message.

Parameters:
n - The plural denominator.
key - The key to search for in the message catalog.
Returns:
The localized message.
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string

formatPluralString

String formatPluralString(double n,
                          String key,
                          Object... args)
Format the given localized message with possible plural forms with a set of arguments. A shortcut for
 String.format(i18n.getLocale(),i18n.getPluralString(n,key),args)
 

Parameters:
n - The plural denominator.
key - The key to search for in the message catalog.
args - The argument to the format string.
Returns:
The formatted localized message.
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string


Copyright © 2013. All Rights Reserved.