@Override /* ConsoleCommand */ public String getInfo() { return mb.getString("info"); }
/** * Same as {@link #findFirstString(String...)}, but uses the specified locale. * * @param locale The locale of the resource bundle to retrieve message from. * @param keys The list of possible keys. * @return The resolved value, or <jk>null</jk> if no value is found or the resource bundle is missing. */ public String findFirstString(Locale locale, String...keys) { MessageBundle srb = getBundle(locale); return srb.findFirstString(keys); }
/** * Constructor. * * <p> * A shortcut for calling <code>new MessageBundle(forClass, bundlePath)</code>. * * @param forClass The class * @param bundlePath The location of the resource bundle. * @return A new message bundle belonging to the class. */ public static final MessageBundle create(Class<?> forClass, String bundlePath) { return new MessageBundle(forClass, bundlePath); }
/** * Looks for all the specified keys in the resource bundle and returns the first value that exists. * * @param keys The list of possible keys. * @return The resolved value, or <jk>null</jk> if no value is found or the resource bundle is missing. */ public String findFirstString(String...keys) { if (rb == null) return null; for (String k : keys) { if (containsKey(k)) return getString(k); } return null; }
/** * Same as {@link #getString(String, Object...)} but allows you to specify the locale. * * @param locale The locale of the resource bundle to retrieve message from. * @param key The resource bundle key. * @param args Optional {@link MessageFormat}-style arguments. * @return * The resolved value. Never <jk>null</jk>. * <js>"{!!key}"</js> if the bundle is missing. * <js>"{!key}"</js> if the key is missing. */ public String getString(Locale locale, String key, Object...args) { if (locale == null) return getString(key, args); return getBundle(locale).getString(key, args); }
private String getDescription(RestRequest req) { VarResolverSession vr = req.getVarResolverSession(); if (description != null) return vr.resolve(description); String description = msgs.findFirstString(req.getLocale(), method.getName() + ".description"); if (description != null) return vr.resolve(description); Operation o = getSwaggerOperationFromFile(req); if (o != null) return o.getDescription(); return null; }
/** * Returns the resource bundle for the specified locale. * * @param locale The client locale. * @return The resource bundle for the specified locale. Never <jk>null</jk>. */ public MessageBundle getBundle(Locale locale) { MessageBundle mb = localizedBundles.get(locale); if (mb != null) return mb; mb = new MessageBundle(forClass, bundlePath, locale); List<MessageBundle> l = new ArrayList<>(searchBundles.size()-1); for (int i = 1; i < searchBundles.size(); i++) { MessageBundle srb = searchBundles.get(i); srb = new MessageBundle(srb.forClass, srb.bundlePath, locale); l.add(srb); mb.allKeys.addAll(srb.keySet()); } mb.searchBundles.addAll(l); localizedBundles.putIfAbsent(locale, mb); return localizedBundles.get(locale); } }
/** * Returns the resource bundle identified by the {@link RestResource#messages() @RestResource.messages()} annotation for the specified locale. * * @param locale The resource bundle locale. * @return The resource bundle. Never <jk>null</jk>. */ public MessageBundle getMessages(Locale locale) { return msgs.getBundle(locale); }
/** * Constructor. * * <p> * When this method is used, the bundle path is determined by searching for the resource bundle * in the following locations: * <ul> * <li><code>[package].ForClass.properties</code> * <li><code>[package].nls.ForClass.properties</code> * <li><code>[package].i18n.ForClass.properties</code> * </ul> * * @param forClass The class * @return A new message bundle belonging to the class. */ public static final MessageBundle create(Class<?> forClass) { return create(forClass, findBundlePath(forClass)); }
if (! r.messages().isEmpty()) { if (msgs == null) msgs = new MessageBundle(c, r.messages()); else msgs.addSearchPath(c, r.messages()); msgs = new MessageBundle(this.getClass(), ""); if (clientVersionHeader.isEmpty()) clientVersionHeader = "X-Client-Version";
/** * Returns all keys in this resource bundle with the specified prefix. * * @param prefix The prefix. * @return The set of all keys in the resource bundle with the prefix. */ public Set<String> keySet(String prefix) { Set<String> set = new HashSet<>(); for (String s : keySet()) { if (s.equals(prefix) || (s.startsWith(prefix) && s.charAt(prefix.length()) == '.')) set.add(s); } return set; }
private String getSummary(RestRequest req) { VarResolverSession vr = req.getVarResolverSession(); if (summary != null) return vr.resolve(summary); String summary = msgs.findFirstString(req.getLocale(), method.getName() + ".summary"); if (summary != null) return vr.resolve(summary); Operation o = getSwaggerOperationFromFile(req); if (o != null) return o.getSummary(); return null; }
/** * Same as {@link #getString(String, Object...)} but allows you to specify the locale. * * @param locale The locale of the resource bundle to retrieve message from. * @param key The resource bundle key. * @param args Optional {@link MessageFormat}-style arguments. * @return * The resolved value. Never <jk>null</jk>. * <js>"{!!key}"</js> if the bundle is missing. * <js>"{!key}"</js> if the key is missing. */ public String getString(Locale locale, String key, Object...args) { if (locale == null) return getString(key, args); return getBundle(locale).getString(key, args); }
/** * Looks for all the specified keys in the resource bundle and returns the first value that exists. * * @param keys The list of possible keys. * @return The resolved value, or <jk>null</jk> if no value is found or the resource bundle is missing. */ public String findFirstString(String...keys) { if (rb == null) return null; for (String k : keys) { if (containsKey(k)) return getString(k); } return null; }
/** * Returns the resource bundle for the specified locale. * * @param locale The client locale. * @return The resource bundle for the specified locale. Never <jk>null</jk>. */ public MessageBundle getBundle(Locale locale) { MessageBundle mb = localizedBundles.get(locale); if (mb != null) return mb; mb = new MessageBundle(forClass, bundlePath, locale); List<MessageBundle> l = new ArrayList<>(searchBundles.size()-1); for (int i = 1; i < searchBundles.size(); i++) { MessageBundle srb = searchBundles.get(i); srb = new MessageBundle(srb.forClass, srb.bundlePath, locale); l.add(srb); mb.allKeys.addAll(srb.keySet()); } mb.searchBundles.addAll(l); localizedBundles.putIfAbsent(locale, mb); return localizedBundles.get(locale); } }
return context.getMessages().getBundle(getLocale());
/** * Constructor. * * <p> * When this method is used, the bundle path is determined by searching for the resource bundle * in the following locations: * <ul> * <li><code>[package].ForClass.properties</code> * <li><code>[package].nls.ForClass.properties</code> * <li><code>[package].i18n.ForClass.properties</code> * </ul> * * @param forClass The class * @return A new message bundle belonging to the class. */ public static final MessageBundle create(Class<?> forClass) { return create(forClass, findBundlePath(forClass)); }
/** * Returns all keys in this resource bundle with the specified prefix. * * @param prefix The prefix. * @return The set of all keys in the resource bundle with the prefix. */ public Set<String> keySet(String prefix) { Set<String> set = new HashSet<>(); for (String s : keySet()) { if (s.equals(prefix) || (s.startsWith(prefix) && s.charAt(prefix.length()) == '.')) set.add(s); } return set; }