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