Start of Content Area

Procedure documentation Create dynamic texts and complete the application Locate the document in its SAP Library structure

 

ResultViewdisplays a picture and text that correspond to the vehicle type chosen by the user. You realize this dynamic screen change in the onPlugRentIn() method.

Do not define any dynamic interface texts for international applications in the source code. It is extremely difficult to extract these texts and make them non-language-specific.

Web Dynpro gives you the option of saving dynamic texts in the message pool. The text elements in the message pool are saved automatically to an This graphic is explained in the accompanying text xlf file. This isolates the texts in groups, which makes the translation process easier.

Note

You also have the (more difficult) option of extracting the implemented language-specific texts from the source code or saving them directly in a *.properties file. For more information, see Externalizing Strings or Internationalization Service.

 

In the following procedure, you save these language-specific texts in the message pool. In the controller code, you can access the texts of the message pool using the IWDTextAccessor.

The IWDTextAccessor enables you to access the texts of messages of the type IWDMessage (standard, error or warning) and the message type text:

·        //Returns a localized text for the given key
java.lang.String getText(java.lang.String key)

·        //Returns a formatted text whose localized text is determined by the
//given key, parameterized by the given parameters

java.lang.String getText(java.lang.String key, java.lang.Object[] parameters)

·        //Returns a localized text for the given message
java.lang.String getText(IWDMessage message)

·        //Returns a formatted text whose localized text is determined by the
//given message, parameterized by the given parameters

java.lang.String getText(IWDMessage message, java.lang.Object[] parameters)

 

Procedure

Defining Dynamic Language-Specific Texts in the Message Pool

...

       1.      Open the message pool for LanguagesComp.

       2.      Add new texts to the message pool by choosing This graphic is explained in the accompanying text for each new text. The table shows you the properties of each new text:

Message Key

Message Type

Message Text

text_E

text

You have chosen an economy class car.

text_F

text

You have chosen a first class car.

text_B

text

You have chosen a business class car.

text_C

text

You have chosen a cabriolet.

text_V

text

You have chosen a van.

 

Extracting New Texts from the Message Pool in the Program Code

You can now use the onPlugInResult() method to extract the new texts from the message pool.

...

       1.      Open ResultView and switch to the Implementation tab page.

       2.      Add the following source code to the method onPlugInResult():

onPlugInResult()

public void onPlugInResult(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String vehicleType ) {

  //@@begin onPlugInResult(ServerEvent)

String text, image;

  

   //provides access to translatable texts from Message Pool

    IWDTextAccessor textAccessor = wdComponentAPI.getTextAccessor();

 

    if (vehicleType.equals("E")) {

      //text = "You have chosen an economy class car.";

      text = textAccessor.getText("text_E");

      image = "Economy.jpg";

    }

    else if (vehicleType.equals("F")) {

      //text = "You have chosen a first class car.";

      text = textAccessor.getText("text_F");

      image = "Firstclass.jpg";

    }

    else if (vehicleType.equals("B")) {

      //text = "You have chosen a business class car ";

      text = textAccessor.getText("text_B");

      image = "Business.jpg";

    }

    else if (vehicleType.equals("C")) {

      //text = "You have chosen a cabriolet.";

      text = textAccessor.getText("text_C");

      image = "Cabrio.jpg";

    }

    else { //Van

      //text = "You have chosen a van.";

      text = textAccessor.getText("text_V");

      image = "Van.jpg";

    }

 

    wdContext.currentContextElement().setText(text);

    wdContext.currentContextElement().setImage(image);  //@@end

}

Note

The pictures are included in the TutWD_Languages_Init project. You can access them in the Package Explorer by choosing TutWD_Languages_Init à src à mimes à Components à com.sap.tut.wd.languages.LanguagesComp.

       3.      Save the current status of the metadata.

 

Result

You have created a complete example application from the TutWD_Languages_Init project. You can now start and run the application.

 

Next step:

Translating Text Resources into Other Languages  

 

End of Content Area