You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the Pebble documentation, i18n is handled via the evaluate() method: Every PebbleTemplate is assigned a default locale from the PebbleEngine. At the point of evaluation, this locale can be changed with an argument to the evaluate(...) method of the individual template.
However, currently the Jooby Pebble module does not pass any locale information to this method:
public String render(Context ctx, ModelAndView modelAndView) throws Exception {
PebbleTemplate template = engine.getTemplate(modelAndView.getView());
Writer writer = new StringWriter();
Map<String, Object> model = new HashMap<>(ctx.getAttributes());
model.putAll(modelAndView.getModel());
template.evaluate(writer, model);
return writer.toString();
}```
It would be nice to have built-in support for this, e.g. via a setLocale() method on the request context or similar.
I was thinking on a dedicated property in ModelAndView (getLocale() + setLocale(...)), it would make it more obvious to the user how to specify the locale.
What do you think, should it be a new property or should PebbleTemplateEngine (and FreemarkerTemplateEngine) fetch it from the map like in ThymeleafTemplateEngine?
your suggestion is lot better: getter/setter on ModelAndView.
In 1.x there was some crazy (but think useful) locale parsing using language tags from Accept-Language header. We could probably add that back? Still would like to be more clean and simply than it was in 1.x
If we add that to Context. Then a template engine should get the first non-null locale in order: modelandview, context, fallback to application default
Activity
imeszaros commentedon Sep 22, 2020
Could this be useful for other template engines too? Freemarker has a similar setting. In that case a
Localeproperty could be added toModelAndView.Otherwise maybe a
Function<Context, Locale>toPebbleModule.jknack commentedon Sep 23, 2020
The best is to add a locale to
ModelAndViewimeszaros commentedon Sep 23, 2020
ThymeleafTemplateEnginealready does it similarly:jooby/modules/jooby-thymeleaf/src/main/java/io/jooby/internal/thymeleaf/ThymeleafTemplateEngine.java
Line 38 in bbe2daa
I was thinking on a dedicated property in
ModelAndView(getLocale() + setLocale(...)), it would make it more obvious to the user how to specify the locale.What do you think, should it be a new property or should
PebbleTemplateEngine(andFreemarkerTemplateEngine) fetch it from the map like inThymeleafTemplateEngine?jknack commentedon Sep 23, 2020
your suggestion is lot better: getter/setter on ModelAndView.
In 1.x there was some crazy (but think useful) locale parsing using language tags from Accept-Language header. We could probably add that back? Still would like to be more clean and simply than it was in 1.x
If we add that to Context. Then a template engine should get the first non-null locale in order: modelandview, context, fallback to application default
too much?