001 002package jmri.jmrix.loconet.locobuffer; 003 004import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 005import java.util.Locale; 006import javax.annotation.CheckReturnValue; 007import javax.annotation.CheckForNull; 008import javax.annotation.ParametersAreNonnullByDefault; 009 010@ParametersAreNonnullByDefault 011@CheckReturnValue 012@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS",justification="Desired pattern is repeated class names with package-level access to members") 013 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 020 * in each package, working off the local resource bundle name. 021 * 022 * @author Bob Jacobsen Copyright (C) 2012 023 * @since 3.7.2 024 */ 025public class Bundle extends jmri.jmrix.loconet.Bundle { 026 027 @CheckForNull 028 private static final String name = null; // No local resources 029 030 // 031 // below here is boilerplate to be copied exactly 032 // 033 034 /** 035 * Provides a translated string for a given 036 * key from the package resource bundle or 037 * parent. 038 * <p> 039 * Note that this is intentionally package-local 040 * 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 * Merges user data with a translated string for a given 050 * key from the package resource bundle or 051 * parent. 052 * <p> 053 * Uses the transformation conventions of 054 * the Java MessageFormat utility. 055 * <p> 056 * Note that this is intentionally package-local 057 * access. 058 * 059 * @see java.text.MessageFormat 060 * @param key Bundle key to be translated 061 * @param subs One or more objects to be inserted into the message 062 * @return Internationalized text 063 */ 064 static String getMessage(String key, Object ... subs) { 065 return getBundle().handleGetMessage(key, subs); 066 } 067 068 /** 069 * Merges user data with a translated string for a given key in a given 070 * locale from the package resource bundle or parent. 071 * <p> 072 * Uses the transformation conventions of the Java MessageFormat utility. 073 * <p> 074 * Note that this is intentionally package-local access. 075 * 076 * @see java.text.MessageFormat 077 * @param locale The locale to be used 078 * @param key Bundle key to be translated 079 * @param subs One or more objects to be inserted into the message 080 * @return Internationalized text 081 */ 082 static String getMessage(Locale locale, String key, Object... subs) { 083 return getBundle().handleGetMessage(locale, key, subs); 084 } 085 086 private final static Bundle b = new Bundle(); 087 @Override @CheckForNull protected String bundleName() {return name; } 088 protected static jmri.Bundle getBundle() { return b; } 089 090 @Override 091 protected String retry(Locale locale,String key) { 092 return super.getBundle().handleGetMessage(locale,key); 093 } 094 095}