001package jmri.jmrix.tmcc.serialdriver; 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@ParametersAreNonnullByDefault 010@CheckReturnValue 011@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS",justification="Desired pattern is repeated class names with package-level access to members") 012 013@javax.annotation.concurrent.Immutable 014 015/** 016 * Provides standard access for resource bundles in a package. 017 * 018 * Convention is to provide a subclass of this name 019 * in each package, working off the local resource bundle name. 020 * 021 * @author Bob Jacobsen Copyright (C) 2012 022 * @since 3.7.2 023 */ 024public class Bundle extends jmri.jmrix.tmcc.Bundle { 025 026 @CheckForNull private static final String name = null; // No local resources 027 028 // 029 // below here is boilerplate to be copied exactly 030 // 031 032 /** 033 * Provides a translated string for a given 034 * key from the package resource bundle or 035 * parent. 036 * <p> 037 * Note that this is intentionally package-local 038 * access. 039 * 040 * @param key Bundle key to be translated 041 * @return Internationalized text 042 */ 043 static String getMessage(String key) { 044 return getBundle().handleGetMessage(key); 045 } 046 /** 047 * Merges user data with a translated string for a given 048 * key from the package resource bundle or 049 * parent. 050 * <p> 051 * Uses the transformation conventions of 052 * the Java MessageFormat utility. 053 * <p> 054 * Note that this is intentionally package-local 055 * 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 @Override @CheckForNull protected String bundleName() {return name; } 086 protected static jmri.Bundle getBundle() { return b; } 087 088 @Override 089 protected String retry(Locale locale,String key) { 090 return super.getBundle().handleGetMessage(locale,key); 091 } 092 093}