Package org.apache.openjpa.lib.util
Class Localizer
- java.lang.Object
-
- org.apache.openjpa.lib.util.Localizer
-
public class Localizer extends java.lang.Object
The Localizer provides convenient access to localized strings. It inlcudes built-in support for parameter substitution through the use of theMessageFormat
utility. Strings are stored in per-packageProperties
files. The property file for the default locale must be namedlocalizer.properties
. Additional locales can be supported through additional property files using the naming conventions specified in theResourceBundle
class. For example, the german locale could be supported through alocalizer_de_DE.properties
file.- Author:
- Abe White
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Localizer.Message
AMessage
can provide a localized message via theLocalizer.Message.getMessage()
method call, and can also provide the original key, package, and substitution array that were used to assemble the message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addProvider(org.apache.openjpa.lib.util.ResourceBundleProvider provider)
Register a resource provider.static Localizer
forPackage(java.lang.Class<?> cls)
Return a Localizer instance that will access the properties file in the package of the given class using the system default locale.static Localizer
forPackage(java.lang.Class<?> cls, java.util.Locale locale)
Return a Localizer instance that will access the properties file in the package of the given class using the given locale.Localizer.Message
get(java.lang.String key)
Return the localized string matching the given key.Localizer.Message
get(java.lang.String key, java.lang.Object sub)
Return the localized string matching the given key.Localizer.Message
get(java.lang.String key, java.lang.Object[] subs)
Return the localized string matching the given key.Localizer.Message
get(java.lang.String key, java.lang.Object sub1, java.lang.Object sub2)
Return the localized string for the given key.Localizer.Message
get(java.lang.String key, java.lang.Object sub1, java.lang.Object sub2, java.lang.Object sub3)
Return the localized string for the given key.Localizer.Message
getFatal(java.lang.String key)
Return the localized string matching the given key.Localizer.Message
getFatal(java.lang.String key, java.lang.Object sub)
Return the localized string matching the given key.Localizer.Message
getFatal(java.lang.String key, java.lang.Object[] subs)
Return the localized string matching the given key.Localizer.Message
getFatal(java.lang.String key, java.lang.Object sub1, java.lang.Object sub2)
Return the localized string for the given key.static boolean
removeProvider(org.apache.openjpa.lib.util.ResourceBundleProvider provider)
Remove a resource provider.
-
-
-
Method Detail
-
forPackage
public static Localizer forPackage(java.lang.Class<?> cls)
Return a Localizer instance that will access the properties file in the package of the given class using the system default locale.- See Also:
forPackage(Class,Locale)
-
forPackage
public static Localizer forPackage(java.lang.Class<?> cls, java.util.Locale locale)
Return a Localizer instance that will access the properties file in the package of the given class using the given locale.- Parameters:
cls
- the class whose package to check for the localized properties file; if null, the system will check for a top-level properties filelocale
- the locale to which strings should be localized; if null, the system default will be assumed
-
addProvider
public static void addProvider(org.apache.openjpa.lib.util.ResourceBundleProvider provider)
Register a resource provider.
-
removeProvider
public static boolean removeProvider(org.apache.openjpa.lib.util.ResourceBundleProvider provider)
Remove a resource provider.
-
get
public Localizer.Message get(java.lang.String key)
Return the localized string matching the given key.
-
getFatal
public Localizer.Message getFatal(java.lang.String key)
Return the localized string matching the given key.
-
get
public Localizer.Message get(java.lang.String key, java.lang.Object sub)
Return the localized string matching the given key. The givensub
object will be packed into an array and substituted into the found string according to the rules of theMessageFormat
class.- See Also:
get(String)
-
getFatal
public Localizer.Message getFatal(java.lang.String key, java.lang.Object sub)
Return the localized string matching the given key. The givensub
object will be packed into an array and substituted into the found string according to the rules of theMessageFormat
class.- See Also:
getFatal(String)
-
get
public Localizer.Message get(java.lang.String key, java.lang.Object sub1, java.lang.Object sub2)
Return the localized string for the given key.- See Also:
get(String,Object)
-
getFatal
public Localizer.Message getFatal(java.lang.String key, java.lang.Object sub1, java.lang.Object sub2)
Return the localized string for the given key.- See Also:
getFatal(String,Object)
-
get
public Localizer.Message get(java.lang.String key, java.lang.Object sub1, java.lang.Object sub2, java.lang.Object sub3)
Return the localized string for the given key.- See Also:
get(String,Object)
-
get
public Localizer.Message get(java.lang.String key, java.lang.Object[] subs)
Return the localized string matching the given key. The givensubs
objects will be substituted into the found string according to the rules of theMessageFormat
class.- See Also:
get(String)
-
getFatal
public Localizer.Message getFatal(java.lang.String key, java.lang.Object[] subs)
Return the localized string matching the given key. The givensubs
objects will be substituted into the found string according to the rules of theMessageFormat
class.- See Also:
getFatal(String)
-
-