Class Bundle
- java.lang.Object
-
- jmri.Bundle
-
- Direct Known Subclasses:
Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
,Bundle
@ParametersAreNonnullByDefault @CheckReturnValue @Immutable public class Bundle extends java.lang.Object
Provides standard access for resource bundles in a package.Convention is to provide a subclass of this same name in each package, working off the local resource bundle name, usually 'package.Bundle' stored in a Bundle.properties file.
This is the root of a tree of classes that are chained through class-static members so that they each do a search as a request works up the inheritance tree.
Only package-scope methods exposed are from the class, forcing all requests for strings to be a the package level.
To add this to a new package, copy exactly a subclass file such as jmri.jmrit.Bundle, and change three places:
- The import statement at the top
- The extends clause in the class definition statement
- The resource pathname assigned to the name variable, which must be set to null if there are no local resources.
This file is part of JMRI.JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- Since:
- 3.3.1
-
-
Constructor Summary
Constructors Constructor Description Bundle()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
bundleName()
static java.lang.String
formatMessage(java.lang.String message, java.lang.Object... subs)
Formats a message string with parameters.protected static Bundle
getBundle()
(package private) static java.lang.String
getMessage(java.lang.String key)
Provides a translated string for a given key from the package resource bundle or parent.(package private) static java.lang.String
getMessage(java.lang.String key, java.lang.Object... subs)
Merges user data with a translated string for a given key from the package resource bundle or parent.(package private) static java.lang.String
getMessage(java.util.Locale locale, java.lang.String key)
Provides a translated string for a given key in a given locale from the package resource bundle or parent.(package private) static java.lang.String
getMessage(java.util.Locale locale, java.lang.String key, java.lang.Object... subs)
Merges user data with a translated string for a given key in a given locale from the package resource bundle or parent.java.lang.String
handleGetMessage(java.lang.String key)
This method handles the inheritance tree.java.lang.String
handleGetMessage(java.lang.String key, java.lang.Object[] subs)
Merges user data with a translated string for a given key from the package resource bundle or parent.java.lang.String
handleGetMessage(java.util.Locale locale, java.lang.String key)
This method handles the inheritance tree.java.lang.String
handleGetMessage(java.util.Locale locale, java.lang.String key, java.lang.Object[] subs)
Merges user data with a translated string for a given key in a given locale from the package resource bundle or parent.protected java.lang.String
retry(java.util.Locale locale, java.lang.String key)
-
-
-
Constructor Detail
-
Bundle
public Bundle()
-
-
Method Detail
-
getMessage
static java.lang.String getMessage(java.lang.String key)
Provides a translated string for a given key from the package resource bundle or parent.Note that this is intentionally package-local access.
- Parameters:
key
- Bundle key to be translated- Returns:
- Internationalized text
-
getMessage
static java.lang.String getMessage(java.util.Locale locale, java.lang.String key)
Provides a translated string for a given key in a given locale from the package resource bundle or parent.Note that this is intentionally package-local access.
- Parameters:
locale
- The locale to be usedkey
- Bundle key to be translated- Returns:
- Internationalized text
-
getMessage
static java.lang.String getMessage(java.lang.String key, java.lang.Object... subs)
Merges user data with a translated string for a given key from the package resource bundle or parent.Uses the transformation conventions of the Java MessageFormat utility.
Note that this is intentionally package-local access.
- Parameters:
key
- Bundle key to be translatedsubs
- One or more objects to be inserted into the message- Returns:
- Internationalized text
- See Also:
MessageFormat
-
getMessage
static java.lang.String getMessage(java.util.Locale locale, java.lang.String key, java.lang.Object... subs)
Merges user data with a translated string for a given key in a given locale from the package resource bundle or parent.Uses the transformation conventions of the Java MessageFormat utility.
Note that this is intentionally package-local access.
- Parameters:
locale
- The locale to be usedkey
- Bundle key to be translatedsubs
- One or more objects to be inserted into the message- Returns:
- Internationalized text
- See Also:
MessageFormat
-
handleGetMessage
public java.lang.String handleGetMessage(java.lang.String key)
This method handles the inheritance tree. At lower levels, it reflects upwards on failure. Once it reaches this root class, it will throw a MissingResourceException in the key can't be found via the local definition of retry().- Parameters:
key
- Bundle key to be translated- Returns:
- Internationalized text
- Throws:
java.util.MissingResourceException
- if message cannot be found
-
handleGetMessage
public java.lang.String handleGetMessage(java.util.Locale locale, java.lang.String key)
This method handles the inheritance tree. At lower levels, it reflects upwards on failure. Once it reaches this root class, it will throw a MissingResourceException in the key can't be found via the local definition of retry().- Parameters:
locale
- The locale to be usedkey
- Bundle key to be translated- Returns:
- Internationalized text
- Throws:
java.util.MissingResourceException
- if message cannot be found
-
handleGetMessage
public java.lang.String handleGetMessage(java.lang.String key, java.lang.Object[] subs)
Merges user data with a translated string for a given key from the package resource bundle or parent.Uses the transformation conventions of the Java MessageFormat utility.
- Parameters:
key
- Bundle key to be translatedsubs
- Array of objects to be inserted into the message- Returns:
- Internationalized text
- See Also:
MessageFormat
-
handleGetMessage
public java.lang.String handleGetMessage(java.util.Locale locale, java.lang.String key, java.lang.Object[] subs)
Merges user data with a translated string for a given key in a given locale from the package resource bundle or parent.Uses the transformation conventions of the Java MessageFormat utility.
- Parameters:
locale
- The locale to be usedkey
- Bundle key to be translatedsubs
- Array of objects to be inserted into the message- Returns:
- Internationalized text
- See Also:
MessageFormat
-
formatMessage
public static java.lang.String formatMessage(java.lang.String message, java.lang.Object... subs)
Formats a message string with parameters.It's used when a message is fetched from a foreign bundle.
- Parameters:
message
- The message to be formattedsubs
- Array of objects to be inserted into the message- Returns:
- The formatted message
-
retry
protected java.lang.String retry(java.util.Locale locale, java.lang.String key) throws java.util.MissingResourceException
- Throws:
java.util.MissingResourceException
-
bundleName
@CheckForNull protected java.lang.String bundleName()
-
-