Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
The SAP Community wiki will be closed to new content submissions from December 7 6:00 p.m. CET to December 11 6:00 p.m. CET.
All content created during this period will not be available/restorable after December 11.
We apologize for the inconvenience, but we need to take this action to improve and maintain the SAP Community wiki performance.
Please plan your tasks accordingly.
Skip to end of metadata
Go to start of metadata

Introduction:

One of our clients came up with a requirement wherein they want a webdynpro application which should have a drop-down to select a language. On selection of language, only that WD Application should be running in that language without affecting the portal logon/personalized language.So thought of sharing the solution.

 Requirement:


 

Solution:

One would think this can be achieved using SAP Standard mechanism of Internationalization.

But wait...

Here the client doesn't want to change the portal logon language. The user will select language only for that application and not for all the application. Hence internationalization would not work.So here is the alternative.

Step1:

Add all the texts in all the languages you want to maintain in Message Pool. For e.g. we will maintain 2 languages: English and Chinese
Strictly follow the convention of the key: <language key from portal>_title<number>





Step2:

Create a Simple type: language. This is for Language dropdown box.
Here also follow strictly the naming convention where Value = Portal Language Key




Step3:

Open the View of Webdynpro Component and create Context elements for holding texts from message pool depanding upon language selected.

Also create the required Layout.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Associate and action with Dropdownbox event onSelect. 

Step4:
Now comes the most important part... coding...
 

//@@begin wdDoInit()
 IUserFactory userFactory = UMFactory.getUserFactory();
 try {
  IWDClientUser user = WDClientUser.getCurrentUser();
  IUserMaint user1 = userFactory.getMutableUser(user.getSAPUser()
                               .getUniqueID());
  
  String lang = wdContext.getNodeInfo().getAttribute("language")
                          .getModifiableSimpleType().getSVServices()
                          .getModifiableSimpleValueSet()
                          .getText(user1.getLocale().toString());
  
  if( lang.equals(user1.getLocale().toString())){
   wdContext.currentContextElement().setLanguage("en");
  }else{
   wdContext.currentContextElement()
                  .setLanguage(user1.getLocale().toString());
  }
 } catch (WDUMException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (UMException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 IPrivateLangtestView.ITranslateNode nodetrans = wdContext.nodeTranslate();
 IPrivateLangtestView.ITranslateElement tele = nodetrans.createTranslateElement();
 nodetrans.bind(tele);
 
 
   String title1 = "_title1";
   String title2 = "_title2";
   String title3 = "_title3";
   String title4 = "_title4";
   String title5 = "_title5";
   String title6 = "_title6";
   String title7 = "_title7";
   String temp;
   IWDTextAccessor textAccessor = wdComponentAPI.getTextAccessor();
  
   temp = wdContext.currentContextElement().getLanguage() + title1;
   tele.setTitle1(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title2;
   tele.setTitle2(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title3;
   tele.setTitle3(textAccessor.getText(temp)); 
   temp = wdContext.currentContextElement().getLanguage() + title4;
   tele.setTitle4(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title5;
   tele.setTitle5(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title6;
   tele.setTitle6(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title6;
   tele.setTitle7(textAccessor.getText(temp)); 
    //@@end
   //@@begin onActiononSelect(ServerEvent)
   String title1 = "_title1";
   String title2 = "_title2";
   String title3 = "_title3";
   String title4 = "_title4";
   String title5 = "_title5";
   String title6 = "_title6";
   String title7 = "_title7";
   String temp;
   IWDTextAccessor textAccessor = wdComponentAPI.getTextAccessor();
   temp = wdContext.currentContextElement().getLanguage() + title1;
   wdContext.currentTranslateElement().setTitle1(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title2;
   wdContext.currentTranslateElement().setTitle2(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title3;
   wdContext.currentTranslateElement().setTitle3(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title4;
   wdContext.currentTranslateElement().setTitle4(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title5;
   wdContext.currentTranslateElement().setTitle5(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title6;
   wdContext.currentTranslateElement().setTitle6(textAccessor.getText(temp));
   temp = wdContext.currentContextElement().getLanguage() + title7;
   wdContext.currentTranslateElement().setTitle7(textAccessor.getText(temp));
  
    //@@end





Final Step:

Deploy new Archive and Run.
Create Portal View for this WD Application and assign it to a page, then page to a workset and finally workset to a Role.
Give a user this role.
Login to portal with the user having this role.
Default it will display the application in language as of personalized in portal if its maintained in message pool, otherwise by default it will pick English.
Select Chinese from drop down, application will run in Chinese without affecting portal language.

Tips: 

  1. Now in future you want to add support to one more language then you need to add the required language in Simple type Enumeration, add all the title text in that language in message pool.  Deploy new Archive and Run.
  2. Another solution approach is to use properties file which is easier to maintain if more languages needs to be added in future (Thats the part II- Comming Soon)