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