Translation extension for Pebble template engine, which use Spring messages interface
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
pom.xml

README.md

pebble-spring-translate

Translation extension for Pebble template engine, which use Spring messages interface

Overview

Provide the t function for Pebble template engine, which retrive message from Spring MessageSource.

{{ t('users.show.title') }}

"Lazy" Lookup

Function support "layzy" lookup, so you can look up users.show.title message inside users/show.html like:

{{ t('.title') }}

"Lazy" Lookup without template name

You can look up users.my_message message inside users/show.html like:

{{ t('..my_message') }}

Arguments:

{{ t('.title', 'arg1', 'arg2', 'arg3') }}

Setup

You need add extension to Pabble engine and provide Spring MessageSource:

@Autowired
private ServletContext context;

@Bean  
public MessageSource messageSource() {  
    ResourceBundleMessageSource ms = new ResourceBundleMessageSource();  
    ms.setBasename("i18n/messages");
    return ms;  
}  

@Bean
public PebbleEngine pebbleEngine() {
    PebbleEngine pe = new PebbleEngine(new ServletLoader(context));
    pe.addExtension(new TranslateExtension(messageSource()));
    return pe;
}