Package jmri

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

@ParametersAreNonnullByDefault
@CheckReturnValue
@Immutable
public class Bundle
extends 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:

  1. The import statement at the top
  2. The extends clause in the class definition statement
  3. 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 Details

  • Method Details

    • getMessage

      static String getMessage​(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 String getMessage​(Locale locale, 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 used
      key - Bundle key to be translated
      Returns:
      Internationalized text
    • getMessage

      static String getMessage​(String key, 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 translated
      subs - One or more objects to be inserted into the message
      Returns:
      Internationalized text
      See Also:
      MessageFormat
    • getMessage

      static String getMessage​(Locale locale, String key, 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 used
      key - Bundle key to be translated
      subs - One or more objects to be inserted into the message
      Returns:
      Internationalized text
      See Also:
      MessageFormat
    • handleGetMessage

      public String handleGetMessage​(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:
      MissingResourceException - if message cannot be found
    • handleGetMessage

      public String handleGetMessage​(Locale locale, 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 used
      key - Bundle key to be translated
      Returns:
      Internationalized text
      Throws:
      MissingResourceException - if message cannot be found
    • handleGetMessage

      public String handleGetMessage​(String key, 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 translated
      subs - Array of objects to be inserted into the message
      Returns:
      Internationalized text
      See Also:
      MessageFormat
    • handleGetMessage

      public String handleGetMessage​(Locale locale, String key, 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 used
      key - Bundle key to be translated
      subs - Array of objects to be inserted into the message
      Returns:
      Internationalized text
      See Also:
      MessageFormat
    • formatMessage

      public static String formatMessage​(String message, 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 formatted
      subs - Array of objects to be inserted into the message
      Returns:
      The formatted message
    • retry

      protected String retry​(Locale locale, String key) throws MissingResourceException
      Throws:
      MissingResourceException
    • bundleName

    • getBundle

      protected static Bundle getBundle()