001package jmri.jmrit.revhistory.swing;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004
005import javax.annotation.CheckForNull;
006import javax.annotation.CheckReturnValue;
007import javax.annotation.ParametersAreNonnullByDefault;
008import java.util.Locale;
009
010@ParametersAreNonnullByDefault
011@CheckReturnValue
012@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Desired pattern is repeated class names with package-level access to members")
013
014@javax.annotation.concurrent.Immutable
015
016/**
017 * Provides standard access for resource bundles in a package.
018 *
019 * Convention is to provide a subclass of this name in each package, working off
020 * the local resource bundle name.
021 *
022 * @author Bob Jacobsen Copyright (C) 2012
023 * @since 3.3.1
024 */
025public class Bundle extends jmri.jmrit.Bundle {
026
027    @CheckForNull
028    private static final String name = null; // No local resources
029
030    //
031    // below here is boilerplate to be copied exactly
032    //
033    /**
034     * Provides a translated string for a given key from the package resource
035     * bundle or parent.
036     * <p>
037     * Note that this is intentionally package-local access.
038     *
039     * @param key Bundle key to be translated
040     * @return Internationalized text
041     */
042    static String getMessage(String key) {
043        return getBundle().handleGetMessage(key);
044    }
045
046    /**
047     * Merges user data with a translated string for a given key from the
048     * package resource bundle or parent.
049     * <p>
050     * Uses the transformation conventions of the Java MessageFormat utility.
051     * <p>
052     * Note that this is intentionally package-local access.
053     *
054     * @see java.text.MessageFormat
055     * @param key  Bundle key to be translated
056     * @param subs One or more objects to be inserted into the message
057     * @return Internationalized text
058     */
059    static String getMessage(String key, Object... subs) {
060        return getBundle().handleGetMessage(key, subs);
061    }
062
063    /**
064     * Merges user data with a translated string for a given key in a given
065     * locale from the package resource bundle or parent.
066     * <p>
067     * Uses the transformation conventions of the Java MessageFormat utility.
068     * <p>
069     * Note that this is intentionally package-local access.
070     *
071     * @see java.text.MessageFormat
072     * @param locale The locale to be used
073     * @param key    Bundle key to be translated
074     * @param subs   One or more objects to be inserted into the message
075     * @return Internationalized text
076     */
077    static String getMessage(Locale locale, String key, Object... subs) {
078        return getBundle().handleGetMessage(locale, key, subs);
079    }
080
081    private final static Bundle b = new Bundle();
082
083    @Override
084    @CheckForNull
085    protected String bundleName() {
086        return name;
087    }
088
089    protected static jmri.Bundle getBundle() {
090        return b;
091    }
092
093    @Override
094    protected String retry(Locale locale, String key) {
095        return super.getBundle().handleGetMessage(locale,key);
096    }
097
098}