Package com.puppycrawl.tools.checkstyle
Class LocalizedMessage
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.LocalizedMessage
-
public class LocalizedMessage extends Object
Represents a message that can be localised. The translations come from message.properties files. The underlying implementation uses java.text.MessageFormat.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LocalizedMessage.Utf8Control
Custom ResourceBundle.Control implementation which allows explicitly read the properties files as UTF-8.
-
Field Summary
Fields Modifier and Type Field Description private Object[]
args
Arguments for java.text.MessageFormat, that is why type is Object[].private String
bundle
Name of the resource bundle to get messages from.private String
key
Key for the message format.private static Locale
sLocale
The locale to localise messages to.private Class<?>
sourceClass
Class of the source for this message.
-
Constructor Summary
Constructors Constructor Description LocalizedMessage(String bundle, Class<?> sourceClass, String key, Object... args)
Creates a newLocalizedMessage
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private ResourceBundle
getBundle()
Obtain the ResourceBundle.String
getMessage()
Gets the translated message.static void
setLocale(Locale locale)
Sets a locale to use for localization.
-
-
-
Field Detail
-
sourceClass
private final Class<?> sourceClass
Class of the source for this message.
-
-
Constructor Detail
-
LocalizedMessage
public LocalizedMessage(String bundle, Class<?> sourceClass, String key, Object... args)
Creates a newLocalizedMessage
instance.- Parameters:
bundle
- resource bundle namesourceClass
- the Class that is the source of the messagekey
- the key to locate the translation.args
- arguments for the translation.
-
-
Method Detail
-
setLocale
public static void setLocale(Locale locale)
Sets a locale to use for localization.- Parameters:
locale
- the locale to use for localization
-
getMessage
public String getMessage()
Gets the translated message.- Returns:
- the translated message.
-
getBundle
private ResourceBundle getBundle()
Obtain the ResourceBundle. Uses the classloader of the class emitting this message, to be sure to get the correct bundle.- Returns:
- a ResourceBundle.
-
-