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