1 Reply Latest reply on Mar 2, 2010 7:30 PM by Lincoln Baxter III

    Seam Internationalization

    Bernard Chan Newbie

      It happens that I am asked to create an internationalized Web application. Apart from i18n messages, I have an additional requirement: localized views based on locale.


      So, as an example, I may have a view for /home.seam that shows the main page similar to that of a Yahoo! home page. Then, depending on the locale of the user, a localized home page will be shown with layout and content that is customized based on the locale, and they can be entirely different. However, say for more standard views such as login, as well as views that belong more to the Web application, I can use a localized message approach for those views. So I would like to have both approaches available to me.


      Except setting separate views such as /home_en.seam and /home_zh.seam and so on, is there any other ways I can try? Because I would like to provide users with a language switcher that they can switch the language version on all the views, without first redirecting back to home.


      What I am thinking about is something along the lines of content negotiation in Apache. How can I best implement this on a seam-based platform? Thank you for sharing any insights.

        • 1. Re: Seam Internationalization
          Lincoln Baxter III Master
          I'm going to be looking in to this for Seam 3. In the mean time, you can do it yourself by taking a few steps;

          Decorate the view-handler (Create a new class that extends and wraps the existing ViewHandler.) This ViewHandler will need to be registered in faces-config.xml under: <application><view-handler>com.your.ViewHandlerDecorater

          Your viewHandler must accept a ViewHandler in the constructor as an argument; you must ensure that your ViewHandler delegates all methods to the parent viewHandler that was received in the constructor (keep it as a local variable.)

          In the restore/createView() methods, intercept the viewId, determine if there are localizations available (/home_en.seam, etc...) replace the viewId with the appropriate locale viewId, then pass that viewId to the parent viewHandler. Faces will continue rendering normally, however, be careful here because the output of links and forms may display the localized view path (you might want this anyway.)

          It's pretty clean and easy to tie in to the existing locale settings since you're in a faces context already.