Skip to Content

This is one in a series on new features in the latest portal releases — 2004 SP Stack 20 and 7.0 (formerly 2004s) SP Stack 12. The features were listed in the blog What’s New in the Portal for 2004 SP20 / 7.0 SP12.

A very big request from customers was to easily allow anonymous users to change the language of the portal. Up until now, you had to have some sort of work around, like creating named anonymous users for each language you wanted to expose and provide links that specified a different anonymous user for each language.

In the latest release, you barely have to do anything. The masthead, when accessed by an anonymous user, now can include a dropdown list of languages so that the user can pick his language.
 

image
The anonymous user can pick a language, and the portal’s language immediately changes.

image

How to Set It Up

It’s easy to add the dropdown list, just set the Show Dropdown List in Masthead: Language Personalization for Anonymous Users property of the masthead iView to Yes (yes, that’s one long property name).

image

image

Modifying the Masthead

A common layout for websites is to show a set of flags for changing the language. You can customize the masthead, and use a simple API to change the language. Modify the UI, and then when you need to set the language, use the following code:

HttpSession session = request.getServletRequest().getSession(); session.setAttribute(“sessionLocale”, newLocale); newLocale is a string that equals the locale code.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Bhavik Devisha
    This is a really nice weblog.

    I have one question here.
    Can we use this functionality for authenticated users by modifying masthead iView?

    How can we set language value for authenticated users?

    (0) 
    1. Daniel Wroblewski Post author
      Authenticated users need to go to the personalize link and change the language from there.

      There is no option to change the language only for the session, the feature works only for anonymous users.

      The idea was that for authenticated users, there was a way to set the language, but not for anonymous users (unless they used a custom URL for each language). So this mechanism was for anonymous users to be able to set the language.

      (0) 
      1. Bhavik Devisha
        I do understand why ths dropdown is available for anonymous users only.

        But, i am on my way to costomize masthead iView to display language dropdown to change the language for authenticated users.

        This is one of the requirement i have from client.

        It seems above code you have given to set session value doesn’t work to set the language for authenticated users. Do you know how can I set the user locale for authenticated users? There must be some code to override user locale through code.

        Thanks for your help.
        Bhavik

        (0) 
        1. Daniel Wroblewski Post author
          I need to understand your requirement. Because, essentially, you seem to be able to do what you want by going to the personalization and changing the language and then changing back. Is this not good enough? Do you really need to make the language per session?
          (0) 
          1. Bhavik Devisha
            You are right. We are able to change language from personalize link.

            But what cleint want is, a dropdown list on masthead iview to change the language preference as they found that was the easy way to change language instead of going to personalize link.
            They want language for per session.

            If you want I can share the peice of code which I have changed to visible dropdown field on masthead iView and written some code to set the langauge value in session locale.

            But, that code is not working.

            (0) 

Leave a Reply