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