java.lang.Object
com.github.jknack.handlebars.springmvc.MessageSourceHelper
All Implemented Interfaces:
com.github.jknack.handlebars.Helper<String>

public class MessageSourceHelper extends Object implements com.github.jknack.handlebars.Helper<String>
A helper that delegates to a MessageSource instance. Usage:
  {{message "code" args* [default="default message"] }}
 
Where:
  • code: String literal. Required.
  • args: Object. Optional
  • default: A default message. Optional.
This helper have a strong dependency to local-thread-bound variable for accessing to the current user locale.
Since:
0.5.5
Author:
edgar.espina
See Also:
  • LocaleContextHolder.getLocale()
  • Constructor Details

    • MessageSourceHelper

      public MessageSourceHelper(org.springframework.context.MessageSource messageSource)
      Creates a new MessageSourceHelper.
      Parameters:
      messageSource - The message source. Required.
  • Method Details

    • apply

      public Object apply(String code, com.github.jknack.handlebars.Options options) throws IOException
      Specified by:
      apply in interface com.github.jknack.handlebars.Helper<String>
      Throws:
      IOException
    • currentLocale

      protected Locale currentLocale()
      Resolve the current user locale.
      Returns:
      The current user locale.