Announcement Announcement Module
Collapse
No announcement yet.
Transfering internationalization between web layer and service layer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transfering internationalization between web layer and service layer

    Hello
    I am using Spring MVC in my web application.

    The architecture for the application is quite straight forward with the following layers:
    • web front (Web MVC)
    • Service layer
    • Repository

    The application is going to have support for different languages which the mvc helps me with in the web front.

    In the service layer i need to send out some emails for instance to verify email addresses and such.

    The problem is to know which locale to use when creating the emails.

    What is the best way to make the service methods aware of which locale to use?

    I'm using SimpleFormController and AbstractController as base for my controllers?

    Thankful for any help i can get

    Best regards
    Per-Jarle

  • #2
    Why do your service methods need to know this. If you would let a MessageSource determine the content of your email you will get automatic translation.

    Comment


    • #3
      For instance when signing up for the application...

      The user register himself at the signup page:
      1. User register itself at the signup page (SimpleFormController)
      2. The SignUpController creates the UserProfile domain object and send it to the service method
      3. The service let the repository persist the user
      4. The service send an email to the user and ask him to verify it's email. This email shall be written in the users language. Therefore i need localization information here
      5. The controller forward the user to the "Just registered" page

      Best regards
      Per-Jarle

      Comment


      • #4
        As I stated in my previous response..

        Originally posted by mdeinum
        If you would let a MessageSource determine the content of your email you will get automatic translation.
        Like with your messages on screen.

        Comment


        • #5
          I'm not sure if i understand what you mean

          Can you give me a short example?

          Best regards
          Per-Jarle

          Comment


          • #6
            My mistake I was mixing up somethings. You still need the locale.

            You can use the LocalEContextHolder to get the Locale.

            Code:
            Locale locale = LocaleContextHolder.getLocale();

            Comment


            • #7
              Can i use that method directly from the onSubmit method and then pass the locale as parameter to the service method?

              Since it's a static method, how can i be sure that the locale it return is the right one for the current request?

              Best regards
              Per-Jarle

              Comment


              • #8
                You don't want to pass it into your service method you want to call that method in your service method. The Locale is thread bound, each request is handled by a separate Thread.

                Comment


                • #9
                  Excellent

                  Thank you very much for your help

                  Best regards
                  Per-Jarle

                  Comment

                  Working...
                  X