Announcement Announcement Module
Collapse
No announcement yet.
Getting localized strings from code Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting localized strings from code

    Hi everybody,
    I need to reproduce the behaviour of spring:message tag in java classes.

    The scenario is:
    - User registers himself
    - I have to send an automatic email to a user upon registration
    - the user has chosen a preferred language
    - I must send a localized mail
    - different mail bodies are stored in the localization files (messages.properties, for exampe)
    - I need to get the localized mail body from the resources

    I've tried to start from LocalContextHolder, but I didn't find any method to read a localized string.

    Any hint?
    Stefano

  • #2
    Stefano,

    Spring has MessageSource interface that can be used to get localized strings with the getMessage() methods. ResourceBundleMessageSource can be used to read message from standard Java messages.properties files.

    When using Spring MVC, you should automatically get an implementation of this interface in your app context. Assuming you are using a current version of Spring, you can just @Autowired a MessageSource into your code.

    Comment


    • #3
      Many thanks scottyfred!
      Works perfectly.

      Bye,
      Stefano

      Comment

      Working...
      X