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.
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.
Open the web dynpro component's View and select menu path Goto > Online Text Repository Browser. Click Create to create a new OTR text.
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.
Upon save, the OTR text alias is automatically prefixed with the selected package-- in this example $TMP-- and a forward slash.
Repeat this procedure to create OTR texts with default language English for each day of the week as follows:
Open transaction SOTR_EDIT. Enter the alias for the "Today is" text, and select default language English.
Select menu path Edit > Context > Change. In the Context dialog that opens, enter nothing and simply hit Enter.
In the Concept block, select target language German. In the Text block, enter text Heute ist as the translation for Today is. Click Save.
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 |
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.
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.
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.
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.
URL with sap-language Parameter | Logon Language | Result |
---|---|---|
http://host:port/sap/bc/webdynpro/sap/zapplication?sap-language=EN | English | |
http://host:port/sap/bc/webdynpro/sap/zapplication?sap-language=DE | German |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |