/** * @see Languages#getLocaleOrDefault(String) */ protected final Locale getLocaleOrDefault(String language) { return languages.getLocaleOrDefault(language); }
/** * @see Languages#getLocaleOrDefault(RouteContext) */ protected final Locale getLocaleOrDefault(RouteContext routeContext) { return languages.getLocaleOrDefault(routeContext); }
/** * Optionally formats a message for the requested language with * {@link java.text.MessageFormat}. * * @param message * @param language * @param args * @return the message */ private String formatMessage(String message, String language, Object... args) { if (args != null && args.length > 0) { // only format a message if we have arguments Locale locale = languages.getLocaleOrDefault(language); MessageFormat messageFormat = new MessageFormat(message, locale); return messageFormat.format(args); } return message; }
private VelocityContext createVelocityContext(Map<String, Object> model) { // prepare the locale-aware i18n method String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } // prepare the locale-aware prettyTime method Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } VelocityContext context = new VelocityContext(model); context.put("pippo", new PippoHelper(messages, language, locale, router)); context.put("contextPath", router.getContextPath()); context.put("appPath", router.getApplicationPath()); return context; }
@SuppressWarnings("unchecked") public void setup(Languages languages, Messages messages, Router router) { this.languages = languages; this.messages = messages; this.router = router; // set global template variables getModel().put("contextPath", router.getContextPath()); getModel().put("appPath", router.getApplicationPath()); String language = (String) getModel().get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } this.language = language; // prepare the locale Locale locale = (Locale) getModel().get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } this.locale = locale; }
@Override public void handle(RouteContext routeContext) { String language = enableQueryParameter ? routeContext.getParameter(PippoConstants.REQUEST_PARAMETER_LANG).toString() : null; if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(routeContext); } Locale locale = languages.getLocaleOrDefault(language); routeContext.setLocal(PippoConstants.REQUEST_PARAMETER_LANG, language); routeContext.setLocal(PippoConstants.REQUEST_PARAMETER_LOCALE, locale); if (setCookie) { if (routeContext.getResponse().isCommitted()) { log.debug("LANG cookie NOT set, Response already committed!"); } else { languages.setLanguageCookie(language, routeContext); } } routeContext.next(); }
private VelocityContext createVelocityContext(Map<String, Object> model) { // prepare the locale-aware i18n method String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } // prepare the locale-aware prettyTime method Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } VelocityContext context = new VelocityContext(model); context.put("pippo", new PippoHelper(messages, language, locale, router)); context.put("contextPath", router.getContextPath()); context.put("appPath", router.getApplicationPath()); return context; }
@SuppressWarnings("unchecked") public void setup(Languages languages, Messages messages, Router router) { this.languages = languages; this.messages = messages; this.router = router; // set global template variables getModel().put("contextPath", router.getContextPath()); getModel().put("appPath", router.getApplicationPath()); String language = (String) getModel().get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } this.language = language; // prepare the locale Locale locale = (Locale) getModel().get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } this.locale = locale; }
@Override public void handle(Context context) { String language = enableQueryParameter ? context.getParameter(Parameter.LANG).toString() : null; if (Strings.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(context); } Locale locale = languages.getLocaleOrDefault(language); context.setLocal(Parameter.LANG, language); context.setLocal(Parameter.LOCALE, locale); context.setLocal(Parameter.LANGUAGES, languages.getRegisteredLanguages()); if (setCookie) { if (context.getResponse().isCommitted()) { log.debug("LANG cookie NOT set, Response already committed!"); } else { languages.setLanguageCookie(language, context); } } context.next(); }
@Override public void handle(Context context) { String language = enableQueryParameter ? context.getParameter(Parameter.LANG).toString() : null; if (Strings.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(context); } Locale locale = languages.getLocaleOrDefault(language); context.setLocal(Parameter.LANG, language); context.setLocal(Parameter.LOCALE, locale); context.setLocal(Parameter.LANGUAGES, languages.getRegisteredLanguages()); if (setCookie) { if (context.getResponse().isCommitted()) { log.debug("LANG cookie NOT set, Response already committed!"); } else { languages.setLanguageCookie(language, context); } } context.next(); }