Package com.puppycrawl.tools.checkstyle
Class LocalizedMessage
java.lang.Object
com.puppycrawl.tools.checkstyle.LocalizedMessage
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 ClassesModifier and TypeClassDescriptionstatic class
Custom ResourceBundle.Control implementation which allows explicitly read the properties files as UTF-8. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]
Arguments for java.text.MessageFormat, that is why type is Object[].private final String
Name of the resource bundle to get messages from.private final String
Key for the message format.private static Locale
The locale to localise messages to.private final Class<?>
Class of the source for this message. -
Constructor Summary
ConstructorsConstructorDescriptionLocalizedMessage
(String bundle, Class<?> sourceClass, String key, Object... args) Creates a newLocalizedMessage
instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate ResourceBundle
Obtain the ResourceBundle.Gets the translated message.static void
Sets a locale to use for localization.
-
Field Details
-
sLocale
The locale to localise messages to. -
bundle
Name of the resource bundle to get messages from. -
sourceClass
Class of the source for this message. -
key
Key for the message format. -
args
Arguments for java.text.MessageFormat, that is why type is Object[].Note: Changing types from Object[] will be huge breaking compatibility, as Module messages use some type formatting already, so better to keep it as Object[].
-
-
Constructor Details
-
LocalizedMessage
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 Details
-
setLocale
Sets a locale to use for localization.- Parameters:
locale
- the locale to use for localization
-
getMessage
Gets the translated message.- Returns:
- the translated message.
-
getBundle
Obtain the ResourceBundle. Uses the classloader of the class emitting this message, to be sure to get the correct bundle.- Returns:
- a ResourceBundle.
-