allegro / handlebars-spring-boot-starter

Spring Boot auto-configuration for Handlebars
Apache License 2.0
108 stars 27 forks source link

Bundle Resolution for i18n fails #9

Closed dadepo closed 9 years ago

dadepo commented 9 years ago

Not sure yet if this is a bug in handlebars-spring-boot-starter, or in jknack.handlebars. But it seems when using handlebars-spring-boot-starter, and the locale is set to something else apart from English, the loading of the other language bundle fails.

Steps to reproduce:

  1. Follow this tutorial http://justinrodenbostel.com/2014/05/13/part-4-internationalization-in-spring-boot/ on i18n with Spring boot
  2. Set the locale to es (either via LocalRseolver or via the browser), rename the message bundle for English to say french
  3. Access a URL.

Expected: Since the locale is es, the message bundle for Spanish should be loaded.

Current Behaviour. Exception: 20:40:11.993 [http-nio-8081-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.github.jknack.handlebars.HandlebarsException: classpath:website/website.hbs:12:31: java.util.MissingResourceException: Can't find bundle for base name messages, locale en_US classpath:website/website.hbs:12:31] with root cause java.util.MissingResourceException: Can't find bundle for base name messages, locale en_US at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564) ~[na:1.8.0_45] at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387) ~[na:1.8.0_45] at java.util.ResourceBundle.getBundle(ResourceBundle.java:1082) ~[na:1.8.0_45] at com.github.jknack.handlebars.helper.DefI18nSource.(I18nHelper.java:347)

Seems bundle for English is always loaded.

Tried this with spring-boot-starter-freemarker and everything works fine.

patrykpacewicz commented 9 years ago

I note that you are using I18nHelper to change the language. In case of handlebars.java + Spring Framework should be used a special helper MessageSourceHelper for it.

Replace i18n to message in .hbs file

example

dadepo commented 9 years ago

Yes indeed. That was the omission I made. Thanks for pointing this out!!!

patrykpacewicz commented 9 years ago

I'm glad I could help :-)