/** * @deprecated since 5.4.4. Use {@link #get(String)} instead. */ @Deprecated protected String get(String key, Messages messages) { return messages.get(key); }
/** * @deprecated since 5.4.4. Use {@link #get(String, java.util.List)} instead. */ @Deprecated protected String getWithDefault(String key, String defaultMsg, Messages messages) { return messages.getWithDefault(key, defaultMsg); }
/** * Adds Variables to a JS which can be used with the getMessage(key) method. * * @return Javascript-Construct of this text */ public static void generateJavaScript(Writer out, Messages messages) throws IOException { out.write("/* ###################################\n"); out.write("### Generated AbstractMessagesImpl\n"); out.write("################################### */\n\n"); for (Iterator iter = messages.keys(); iter.hasNext(); ) { String key = (String) iter.next(); if (key.endsWith(".js")) { String msg = javaScriptString(messages.get(key)); out.write(AbstractMessagesImpl.JS_OBJECTNAME + ".add('" + key + "','" + msg + "','" + messages.getBasename() + "');"); out.write("\n"); } } }
/** * Create a chain passing the wrapped head of the chain. */ public MessagesChain(Messages head) { super(head.getBasename(), head.getLocale()); chain.add(head); }
private LegacyMessage getLegacyMessage(Locale locale, String basename, String key) { final Messages messages = MessagesManager.getMessages(basename, locale); final String s = messages.get(key); return pairOrNull(messages.getBasename(), key, s); }
/** * Simply sets "errorString" in case of login exception. * Override this to pass more objects to the freemarker template. * * @return a map containing translated messages */ protected Map<String, Object> getTemplateContext() { LoginResult loginResult = LoginResult.getCurrentLoginResult(); LoginException exception = loginResult.getLoginException(); Map<String, Object> tplCtx = new HashMap<String, Object>(); if (null != exception) { final String exName = ClassUtils.getShortClassName(exception, null); final Messages mm = MessagesManager.getMessages(); final String defaultMessage = mm.get("login.defaultError"); tplCtx.put(ERROR_STRING, mm.getWithDefault("login." + exName, defaultMessage)); } tplCtx.put("loginError", Boolean.valueOf(loginResult.getStatus() == LoginResult.STATUS_FAILED)); String serviceContact = this.configurationProperties.getProperty("magnolia.service.contact"); if (serviceContact != null) { tplCtx.put(SERVICE_CONTACT, serviceContact); } WebContext ctx = webContextProvider.get(); tplCtx.put("ctx", ctx); tplCtx.put("contextPath", ctx.getContextPath()); // In case someone extended getMessages() final Map<String, Object> deprecatedMethodResult = getMessages(); tplCtx.putAll(deprecatedMethodResult); // TODO but what if they extended handle() and use getMessages there ? return tplCtx; }
/** * @deprecated since 5.4.4. Use {@link #get(String, java.util.List)} instead. */ @Deprecated protected String get(String key, List args, Messages messages) { Object[] argsArray = new Object[args.size()]; return messages.get(key, args.toArray(argsArray)); }
/** * @deprecated since 5.4.4. Use {@link #get(String, java.util.List)} instead. */ @Deprecated protected String getWithDefault(String key, List args, String defaultMsg, Messages messages) { Object[] argsArray = new Object[args.size()]; return messages.getWithDefault(key, args.toArray(argsArray), defaultMsg); }
/** * Get the string searching in the chain. */ @Override public String get(String key) { for (Iterator<Messages> messagesIterator = chain.iterator(); messagesIterator.hasNext(); ) { Messages messages = messagesIterator.next(); String str = messages.get(key); if (!str.startsWith("???")) { return str; } } return "???" + key + "???"; }
/** * Use a default string. * * @param key key to find * @param defaultMsg default message * @return the message */ public static String getWithDefault(String key, String defaultMsg) { return getMessages().getWithDefault(key, defaultMsg); }
/** * Get a message with parameters inside: the value {0} must be a number. * * @param key key to find * @param args replacement strings * @return the message */ public static String get(String key, Object[] args) { return getMessages().get(key, args); }
/** * Get a message with parameters inside: the value {0} must be a number. Use a default message. * * @param key key to find * @param args replacement strings * @param defaultMsg default message * @return the message */ public static String getWithDefault(String key, Object[] args, String defaultMsg) { return getMessages().getWithDefault(key, args, defaultMsg); }
/** * @return String , label for the new bar */ private String getNewLabel() { String defStr = MessagesManager.getMessages().get(DEFAULT_NEW_LABEL); return StringUtils.defaultString(this.newLabel, defStr); }
/** * Get the message. * @param key key * @return message */ public String getMessage(String key) { return this.getMessages().getWithDefault(key, key); }
public String getMessage(String key, String arg) { return super.getMsgs().get(key, new String[]{arg }); }
/** * Get the message from the renderer. Uses getMessages(). * @param key * @return the string found, or the key if not found */ public String getMessage(String key) { return getMessages().getWithDefault(key, key); }
public static String get(String key, String basename) { return MessagesManager.getMessages(basename).get(key); }
/** * @deprecated since 5.4.4. Use new i18n mechanism instead. */ @Deprecated protected String getInterfaceMessage(String key) { return MessagesUtil.chainWithDefault(DEFAULT_I18N_BASENAME).getWithDefault(key, key); }
public static String getChained(String key, String[] basenames, String[] args) { return chain(basenames).get(key, args); }
/** * Get the message with replacement strings. Use the {nr} syntax * @param key key * @param args replacement strings * @return message */ public String getMessage(String key, Object[] args) { return this.getMessages().getWithDefault(key, args, key); }