Package com.puppycrawl.tools.checkstyle
Class LocalizedMessage
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.LocalizedMessage
-
public class LocalizedMessage extends java.lang.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 java.lang.Object[]
args
Arguments for java.text.MessageFormat, that is why type is Object[].private java.lang.String
bundle
Name of the resource bundle to get messages from.private java.lang.String
key
Key for the message format.private static java.util.Locale
sLocale
The locale to localise messages to.private java.lang.Class<?>
sourceClass
Class of the source for this message.
-
Constructor Summary
Constructors Constructor Description LocalizedMessage(java.lang.String bundle, java.lang.Class<?> sourceClass, java.lang.String key, java.lang.Object... args)
Creates a newLocalizedMessage
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.ResourceBundle
getBundle()
Obtain the ResourceBundle.java.lang.String
getMessage()
Gets the translated message.static void
setLocale(java.util.Locale locale)
Sets a locale to use for localization.
-
-
-
Field Detail
-
sLocale
private static java.util.Locale sLocale
The locale to localise messages to.
-
bundle
private final java.lang.String bundle
Name of the resource bundle to get messages from.
-
sourceClass
private final java.lang.Class<?> sourceClass
Class of the source for this message.
-
key
private final java.lang.String key
Key for the message format.
-
args
private final java.lang.Object[] 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 Detail
-
LocalizedMessage
public LocalizedMessage(java.lang.String bundle, java.lang.Class<?> sourceClass, java.lang.String key, java.lang.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(java.util.Locale locale)
Sets a locale to use for localization.- Parameters:
locale
- the locale to use for localization
-
getMessage
public java.lang.String getMessage()
Gets the translated message.- Returns:
- the translated message.
-
getBundle
private java.util.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.
-
-