001package jmri.jmrit.logixng.util; 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", "HSM_HIDING_METHOD"}, 014 justification = "Desired pattern is repeated class names with package-level access to members") 015 016@javax.annotation.concurrent.Immutable 017 018/** 019 * Provides standard access for resource bundles in a package. 020 * 021 * Convention is to provide a subclass of this name in each package, working off 022 * the local resource bundle name. 023 * 024 * @author Bob Jacobsen Copyright (C) 2012 025 * @since 3.3.1 026 */ 027public class Bundle extends jmri.jmrit.logixng.Bundle { 028 029 @CheckForNull 030 private static final String name = "jmri.jmrit.logixng.util.UtilBundle"; 031 032 // 033 // below here is boilerplate to be copied exactly 034 // 035 /** 036 * Provides a translated string for a given key from the package resource 037 * bundle or parent. 038 * <p> 039 * Note that this is intentionally package-local access. 040 * 041 * @param key Bundle key to be translated 042 * @return Internationalized text 043 */ 044 static String getMessage(String key) { 045 return getBundle().handleGetMessage(key); 046 } 047 048 /** 049 * Provides a translated string for a given key in a given locale from the 050 * package resource bundle or parent. 051 * <p> 052 * Note that this is intentionally package-local access. 053 * 054 * @param locale The locale to be used 055 * @param key Bundle key to be translated 056 * @return Internationalized text 057 */ 058 static String getMessage(Locale locale, String key) { 059 return getBundle().handleGetMessage(locale, key); 060 } 061 062 /** 063 * Merges user data with a translated string for a given key from the 064 * package resource bundle or parent. 065 * <p> 066 * Uses the transformation conventions of the Java MessageFormat utility. 067 * <p> 068 * Note that this is intentionally package-local access. 069 * 070 * @see java.text.MessageFormat 071 * @param key Bundle key to be translated 072 * @param subs One or more objects to be inserted into the message 073 * @return Internationalized text 074 */ 075 static String getMessage(String key, Object... subs) { 076 return getBundle().handleGetMessage(key, subs); 077 } 078 079 /** 080 * Merges user data with a translated string for a given key in a given 081 * locale from the package resource bundle or parent. 082 * <p> 083 * Uses the transformation conventions of the Java MessageFormat utility. 084 * <p> 085 * Note that this is intentionally package-local access. 086 * 087 * @see java.text.MessageFormat 088 * @param locale The locale to be used 089 * @param key Bundle key to be translated 090 * @param subs One or more objects to be inserted into the message 091 * @return Internationalized text 092 */ 093 static String getMessage(Locale locale, String key, Object... subs) { 094 return getBundle().handleGetMessage(locale, key, subs); 095 } 096 097 private final static Bundle b = new Bundle(); 098 099 @Override 100 @CheckForNull 101 protected String bundleName() { 102 return name; 103 } 104 105 protected static jmri.Bundle getBundle() { 106 return b; 107 } 108 109 @Override 110 protected String retry(Locale locale, String key) { 111 return super.getBundle().handleGetMessage(locale, key); 112 } 113 114}