Skip to Content
Author's profile photo Amy King

Internationalization in Web Dynpro ABAP

Overview

Internationalization, often abbreviated as I18N, provides the ability to translate application labels, captions, messages and other texts into multiple languages so that users of a WDA application will see these application texts presented automatically in their particular logon language.

Scenario

You work at a company with offices in New York and Germany and need your WDA application to present its user interface textual elements translated according to the user’s logon language– either English or German. For the purposes of this demonstration, we will provide translations for two TextView UI elements, one which reads, “Today is” and another which outputs the current day of the week.

demo_otr21.JPG

demo_otr26b.JPG

Procedure

1.0 Create the OTR Texts with Default Language

Open the web dynpro component’s View and select menu path Goto > Online Text Repository Browser. Click Create to create a new OTR text.

demo_otr1.PNG

demo_otr2.PNG

Create an alias to use for the “Today is” TextView as shown below with default text in English. Click Save. When prompted, select US (United States) as the default context country and select a package in which to save the OTR text. This step creates a default language for the OTR text. Later, if a user logs into the application under a logon language for which translations do not exist, e.g., Spanish or Hindi, the default language OTR text will be used.

demo_otr3.PNG

demo_otr3a.PNG

Upon save, the OTR text alias is automatically prefixed with the selected package– in this example $TMP– and a forward slash.

demo_otr3b.PNG

Repeat this procedure to create OTR texts with default language English for each day of the week as follows:

demo_otr4.PNG

2.0 Provide the German Translations

Open transaction SOTR_EDIT. Enter the alias for the “Today is” text, and select default language English.

demo_otr7.PNG

Select menu path Edit > Context > Change. In the Context dialog that opens, enter nothing and simply hit Enter.

demo_otr24.JPG

In the Concept block, select target language German. In the Text block, enter text Heute ist as the translation for Today is. Click Save.

demo_otr25.JPG

Repeat this procedure to translate the OTR texts for each day of the week as follows.

OTR Alias English (US) German (DE)
$TMP/DAYOFWEEK_1 Sunday Sonntag
$TMP/DAYOFWEEK_2 Monday Montag
$TMP/DAYOFWEEK_3 Tuesday Dienstag
$TMP/DAYOFWEEK_4 Wednesday Mittwoch
$TMP/DAYOFWEEK_5 Thursday Donnerstag
$TMP/DAYOFWEEK_6 Friday Freitag
$TMP/DAYOFWEEK_7 Saturday Samstag

3.0 Bind TextView TODAY_IS to its OTR Text

On the View Layout tab, highlight TextView element TODAY_IS and assign OTR alias $TMP/TODAY_IS to its text property using the property value field’s search help.

demo_otr5.PNG

4.0 Bind TextView DAY_OF_WEEK to its OTR Text

Since the day of week is variable, we bind the text property of TextView element DAY_OF_WEEK to a context attribute and programmatically assign the appropriate OTR text to the context attribute. On the View’s Context tab, create a 1..1 node with string attribute DAY_OF_WEEK and bind this context attribute to the the TextView element DAY_OF_WEEK text property.

demo_otr27.JPG

Create a supply function for the context node as follows.

METHOD supply_node.

   DATA lv_day_number TYPE p.
   DATA ls_node TYPE wd_this->element_node.

 * Determine current day of week
   CALL FUNCTION 'DAY_IN_WEEK'
     EXPORTING
       datum = sy-datum
     IMPORTING
       wotnr = lv_day_number.

 * Assign the corresponding OTR textCASE lv_day_number.
     WHEN 1. " Monday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_2').
     WHEN 2. " Tuesday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_3').
     WHEN 3. " Wednesday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_4').
     WHEN 4. " Thursday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_5').
     WHEN 5. " Friday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_6').
     WHEN 6. " Saturday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_7').
     WHEN 7. " Sunday
       ls_node-day_of_week = cl_wd_utilities=>get_otr_text_by_alias('$TMP/DAYOFWEEK_1').
   ENDCASE.

   node->bind_structure(
     new_item             = ls_node
     set_initial_elements = abap_true ).

 ENDMETHOD.


Result

Save, activate and run the web dynpro application. To change the logon language, you may either select a language directly on the logon screen or you may append URL parameter sap-language to the WDA application URL with an appropriate language value.

demo_otr23.JPG

URL with sap-language Parameter Logon Language Result
http://host:port/sap/bc/webdynpro/sap/zapplication?sap-language=EN English demo_otr26b.JPG
http://host:port/sap/bc/webdynpro/sap/zapplication?sap-language=DE German demo_otr26a.JPG

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Dear Amy,

                       Thanks for such a nice explanatory document. I tried this in my system, but I didn't get the text converted to German.

      Please suggest, if there are any pre-requisites.

      Cheers!!!

      Umang

      Author's profile photo Ravi Grover
      Ravi Grover

      Dear Amy,

      You explained Internationalization so well. Keep posting.

      R@vi Gr0v3r