001package jmri.jmrix.loconet.lnsvf2;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004import java.util.Locale;
005import javax.annotation.CheckReturnValue;
006import javax.annotation.CheckForNull;
007import javax.annotation.ParametersAreNonnullByDefault;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
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.loconet.Bundle {
027
028    @CheckForNull
029    private final static String name = "jmri.jmrix.loconet.lnsvf2.LnSvF2Bundle"; // 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        log.debug("interpreting key {} without parameters", key);
045        return getBundle().handleGetMessage(key);
046    }
047
048    /**
049     * Merges user data with a translated string for a given key from the
050     * package resource bundle or parent.
051     * <p>
052     * Uses the transformation conventions of the Java MessageFormat utility.
053     * <p>
054     * Note that this is intentionally package-local access.
055     *
056     * @see java.text.MessageFormat
057     * @param key  Bundle key to be translated
058     * @param subs One or more objects to be inserted into the message
059     * @return Internationalized text
060     */
061    static String getMessage(String key, Object... subs) {
062        log.debug("interpreting key {} with {} parameters", key, subs.length);
063        return getBundle().handleGetMessage(key, subs);
064    }
065    private final static Bundle b = new Bundle();
066
067    @Override
068    @CheckForNull
069    protected String bundleName() {
070        return name;
071    }
072
073    protected static jmri.Bundle getBundle() {
074        return b;
075    }
076
077    @Override
078    protected String retry(Locale locale, String key) {
079        return super.getBundle().handleGetMessage(locale,key);
080    }
081    // initialize logging
082    private final static Logger log = LoggerFactory.getLogger(Bundle.class);
083
084    /**
085     * Merges user data with a translated string for a given key in a given
086     * locale from the package resource bundle or parent.
087     * <p>
088     * Uses the transformation conventions of the Java MessageFormat utility.
089     * <p>
090     * Note that this is intentionally package-local access.
091     *
092     * @see java.text.MessageFormat
093     * @param locale The locale to be used
094     * @param key    Bundle key to be translated
095     * @param subs   One or more objects to be inserted into the message
096     * @return Internationalized text
097     */
098    static String getMessage(Locale locale, String key, Object... subs) {
099        return getBundle().handleGetMessage(locale, key, subs);
100    }
101
102}