001package apps.jmrit; 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@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 */ 025// NOTE: Does not extend apps.Bundle, but extends jmri.jmrit.Bundle, since 026// apps.jmrit is the extension of jmri.jmrit for classes that cannot be under 027// jmri.jmrit due to other architectural rules violations 028public class Bundle extends jmri.jmrit.Bundle { 029 030 @CheckForNull 031 private static final String name = null; // no local bundle 032 033 // 034 // below here is boilerplate to be copied exactly 035 // 036 /** 037 * Provides a translated string for a given key from the package resource 038 * bundle or parent. 039 * <p> 040 * Note that this is intentionally package-local access. 041 * 042 * @param key Bundle key to be translated 043 * @return Internationalized text 044 */ 045 static String getMessage(String key) { 046 return getBundle().handleGetMessage(key); 047 } 048 049 /** 050 * Merges user data with a translated string for a given key from the 051 * package resource bundle or parent. 052 * <p> 053 * Uses the transformation conventions of the Java MessageFormat utility. 054 * <p> 055 * Note that this is intentionally package-local access. 056 * 057 * @see java.text.MessageFormat 058 * @param key Bundle key to be translated 059 * @param subs One or more objects to be inserted into the message 060 * @return Internationalized text 061 */ 062 static String getMessage(String key, Object... subs) { 063 return getBundle().handleGetMessage(key, subs); 064 } 065 066 /** 067 * Merges user data with a translated string for a given key in a given 068 * locale from the package resource bundle or parent. 069 * <p> 070 * Uses the transformation conventions of the Java MessageFormat utility. 071 * <p> 072 * Note that this is intentionally package-local access. 073 * 074 * @see java.text.MessageFormat 075 * @param locale The locale to be used 076 * @param key Bundle key to be translated 077 * @param subs One or more objects to be inserted into the message 078 * @return Internationalized text 079 */ 080 static String getMessage(Locale locale, String key, Object... subs) { 081 return getBundle().handleGetMessage(locale, key, subs); 082 } 083 084 private final static Bundle b = new Bundle(); 085 086 @Override 087 @CheckForNull 088 protected String bundleName() { 089 return name; 090 } 091 092 protected static jmri.Bundle getBundle() { 093 return b; 094 } 095 096 @Override 097 protected String retry(Locale locale, String key) { 098 return super.getBundle().handleGetMessage(locale,key); 099 } 100 101} 102