Skip to Content
We’re going to make a couple of portal components to allow for dynamic language selection of the portal language. Of course, this assumes you have translated your portal content into the appropriate languages! To keep it simple, this example will limit itself to French, English and German, but the logic can be extended.

Because it’s going to be graphic based, first find some suitable image files to display to the user. Using Google images and searching for flags gave me the ones I use here:

image

We need to put these into our developer studio project – I keep mine under dist/images/mimes.

Our first component, which I have called PickLanguage, is used to display the images as anchored links that will then invoke the second component.

Here’s the code:

The href string points to my portal component, so if I change the name of the PAR file or component, I need to change this to the appropriate value.

The second component, which I have called ChangeLanguage, sets the user’s language and then launches the portal again…

Make an iView that launches the first component and give it to a portal role, and you should be finished.

As a caveat, you must have an environment in which users can change their portal language. If they can’t do this, then you need to find another way to achieve the dynamic selection.

Good luck!

To report this post you need to login first.

21 Comments

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

    1. Michael Nicholls Post author
      Yep, you always need a portalapp.xml file for a portal component to work. NWDS will make one for you, and the default worked for me.

      The important bit is:

       
           

      Cheers

      (0) 
        1. Michael Nicholls Post author
          Unfortunately the Java standard set of locales does not include constants SPANISH or POLISH (or SWEDISH or…) You might be able to use something like:

          private static Locale POLISH = new Locale(“pl”, “PL”);

          etc

          (0) 
          1. Sonali M S
            Hi, Thanks Michael, your blog really helped me a lot…I am able to change the language of the portal. The only problem now remains is , the language changes for all the areas except fot the content area. There the contes are still displayed in English. Whereas teh same thing when done through the SAP personalize->language modify, after relogging into the portal, the content in the content area ia also changed to the newly selected language. Is there any workaround for this?

            Thanks in advance.

            (0) 
            1. vaishali dhayalan
              Hi Michael,Sonali,

              please can you tell me how you set the locale to spanish… I am unable to set the locale.

              I created a new locale as follows:

              private static Locale SPANISH = new Locale(“es”, “ES”);

              and then set this
              if (language.equalsIgnoreCase(“spanish”))
              modUser.setLocale(SPANISH);

              but its not setting the locale to spanish.
              Please can you let me know how to check this. I have a requirement to change the locale to spanish.

              Require help here.

              Regards,
              Vaishali

              (0) 
                1. vaishali dhayalan
                  Hi Micheal,

                  I have added the following code in PickLanguage.java

                  response.write(
                  “); and also added a es.gif in imagesmimes folder

                  when i click on the image in the url is

                  http://ud1sap01pd1.bhpb.internal:50000/irj/servlet/prt/portal/prtroot/dynamicrole.changelanguage?language=spanish

                  But still my user language remains english. The language changes only for the ones mentioned in the log.

                  Please can you let me know where i am going wrong.

                  Regards,
                  Vaishali

                  (0) 
                2. vaishali dhayalan
                  Hi Micheal,

                  I have added the following code in PickLanguage.java

                  response.write(
                  “); and also added a es.gif in imagesmimes folder

                  when i click on the image in the url is

                  http://ud1sap01pd1.bhpb.internal:50000/irj/servlet/prt/portal/prtroot/dynamicrole.changelanguage?language=spanish

                  But still my user language remains english. The language changes only for the ones mentioned in the blog.

                  Please can you let me know where i am going wrong.

                  Regards,
                  Vaishali

                  (0) 
                  1. Michael Nicholls Post author
                    I would suggest putting in some extra response.write statements to make sure you are really going through the correct logic path in ChangeLanguage…
                    (0) 
            2. vaishali dhayalan
              Hi Michael,Sonali,

              please can you tell me how you set the locale to spanish… I am unable to set the locale.

              I created a new locale as follows:

              private static Locale SPANISH = new Locale(“es”, “ES”);

              and then set this
              if (language.equalsIgnoreCase(“spanish”))
                  modUser.setLocale(SPANISH);

              But unfortunately the portal language is not set to Spanish.
              Please can you let me know how to check this. I have a requirement to change the locale to spanish.

              Require help here.

              Regards,
              Vaishali

              (0) 
  1. Jorge Dacev
    Hi, I’ve got this error when I click on a link to change the language:

    com.sapportals.portal.prt.runtime.PortalRuntimeException: iView not found: DynamicRole.ChangeLanguage

    this is the url:
    /irj/servlet/prt/portal/prtroot/DynamicRole.ChooseLanguage?language=english

    or

    /irj/servlet/prt/portal/prtroot/DynamicRole.ChooseLanguage?language=french

    or

    /irj/servlet/prt/portal/prtroot/DynamicRole.ChooseLanguage?language=spanish

    I’ve got the ChangeLanguage.java class in the .par file

    Thanks.

    (0) 
    1. Michael Nicholls Post author
      Hi Jorge

      I’m not sure why the component DynamicRole.ChooseLanguage is being invoked. It should be DynamicRole.ChangeLanguage, as this is the name of your Java file.

      Is it possible you mistyped the name of the href variable in Pick.java?

      Cheers

      (0) 
  2. Jorge Dacev
    Use:
    /irj/portal/prtroot/DynamicRole.ChangeLanguage?language=english

    Instead:
    “/irj/servlet/prt/portal/prtroot/DynamicRole.ChangeLanguage?language=english

    (0) 
  3. vaishali dhayalan
    Hi Micheal,

    I am getting the follwing error:

    com.sapportals.portal.prt.runtime.PortalRuntimeException: iView not found: DynamicRole.PickLanguage

    Please can you guide me regarding this.

    (0) 
    1. Michael Nicholls Post author
      What did you call your NWDS project? I called mine DynamicRole, which is why the URL is DynamicRole.PickLanguage. Replace DynamicRole with your project nsme and see what happens.
      (0) 

Leave a Reply