public String i18n(String messageKey) { return messages.get(messageKey, language); }
public String i18n(String messageKey) throws IOException { return messages.get(messageKey, language); }
public String i18n(String messageKey) { return messages.get(messageKey, language); }
public String i18n(String messageKey, Object... args) throws IOException { return messages.get(messageKey, language, args); }
public String i18n(String messageKey, Object... args) { return messages.get(messageKey, language, args); }
public String i18n(String messageKey, Object... args) { return messages.get(messageKey, language, args); }
@Override public String getMessage(String key, String language, Object... args) { return application.getMessages().get(key, language, args); }
@Override public String getMessage(String key, Object... args) { return application.getMessages().get(key, this, args); }
@Override public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) { String messageKey = (String) args.get("key"); Locale locale = context.getLocale(); String requestLang = locale.toLanguageTag(); List<Object> messageArgs = new ArrayList<>(); for (int i = 1; i <= 5; i++) { if (args.containsKey("arg" + i)) { Object object = args.get("arg" + i); messageArgs.add(object); } } String messageValue = messages.get(messageKey, requestLang, messageArgs.toArray()); return new SafeString(messageValue); }
/** * Gets the requested localized message. * <p/> * <p> * The current Request and Response are used to help determine the messages * resource to use. * <ol> * <li>Exact locale match, return the registered locale message * <li>Language match, but not a locale match, return the registered * language message * <li>Return supplied default message * </ol> * <p> * The message can be formatted with optional arguments using the * {@link java.text.MessageFormat} syntax. * </p> * * @param key * @param defaultMessage * @param args * @return the message or the key if the key does not exist */ public String getWithDefault(String key, String defaultMessage, String language, Object... args) { String value = get(key, language, args); if (value.equals(key)) { // key does not exist, format default message value = formatMessage(defaultMessage, language, args); } return value; }
/** * Gets the requested localized message. * <p/> * <p> * The current Request and Response are used to help determine the messages * resource to use. * <ol> * <li>Exact locale match, return the registered locale message * <li>Language match, but not a locale match, return the registered * language message * <li>Return the default resource message * </ol> * <p> * The message can be formatted with optional arguments using the * {@link java.text.MessageFormat} syntax. * </p> * <p> * If the key does not exist in the messages resource, then the key name is * returned. * </p> * * @param key * @param routeContext * @param args * @return the message or the key if the key does not exist */ public String get(String key, RouteContext routeContext, Object... args) { String language = languages.getLanguageOrDefault(routeContext); return get(key, language, args); }
@Override public void execute(Options options) { Locale locale = getCurrentLocale(); String requestLang = locale.toLanguageTag(); String messageKey = options.getParameters().get(0).toString(); List<Object> args = new ArrayList<>(); for (int i = 1; i < options.getParameters().size(); i++) { args.add(options.getParameters().get(i)); } String messageValue = messages.get(messageKey, requestLang, args.toArray()); append(options, messageValue); }
@Override public TemplateModel exec(List args) throws TemplateModelException { if (args.size() == 1) { String messageKey = ((SimpleScalar) args.get(0)).getAsString(); String messageValue = messages.get(messageKey, language); return new SimpleScalar(messageValue); } else if (args.size() > 1) { List<Object> objects = new ArrayList<>(); for (Object o : args) { if (o instanceof SimpleScalar) { objects.add(((SimpleScalar) o).getAsString()); } else if (o instanceof SimpleNumber) { objects.add(o.toString()); } else if (o instanceof StringModel) { objects.add(((StringModel) o).getWrappedObject()); } } String messageKey = objects.get(0).toString(); String messageValue = messages.get(messageKey, language, objects.subList(1, objects.size()).toArray()); return new SimpleScalar(messageValue); } else { throw new TemplateModelException("Please specify a message key for the i18n() method!"); } }
public String i18n(String messageKey, Object... args) throws IOException { return messages.get(messageKey, language, args); }
public String i18n(String messageKey, Object... args) { return messages.get(messageKey, language, args); }
public String i18n(String messageKey) throws IOException { return messages.get(messageKey, language); }
public class MyComponent { @Inject private Messages messages; @Property private String messageToDisplay; @SetupRender final void init() { // ... messageToDisplay = messages.get("some-key").format(valueForParam0, valueForParam1, ...); // ... } }
log.error("Unexpected error generating '{}' as '{}'", Error.class.getName(), contentType, e); routeContext.status(HttpConstants.StatusCode.INTERNAL_ERROR); routeContext.send(application.getMessages().get("pippo.statusCode500", routeContext));
/** * Prepares an Error instance for the error response. * * @param statusCode * @param routeContext * @return an Error */ protected Error prepareError(int statusCode, RouteContext routeContext) { String messageKey = "pippo.statusCode" + statusCode; Error error = new Error(); error.setStatusCode(statusCode); error.setStatusMessage(application.getMessages().get(messageKey, routeContext)); error.setRequestMethod(routeContext.getRequestMethod()); error.setRequestUri(routeContext.getRequestUri()); error.setStacktrace(routeContext.getLocal(STACKTRACE)); error.setMessage(routeContext.getLocal(MESSAGE)); return error; }
@Override public void execute(Options options) { Locale locale = getCurrentLocale(); String requestLang = locale.toLanguageTag(); String messageKey = options.getParameters().get(0).toString(); List<Object> args = new ArrayList<>(); for (int i = 1; i < options.getParameters().size(); i++) { args.add(options.getParameters().get(i)); } String messageValue = messages.get(messageKey, requestLang, args.toArray()); append(options, messageValue); }