• No results found

Messages and Internationalization3.4

The internationalization (I18N) of Web Dynpro applications relates to the feature of displaying texts in a specific target language, generally the logon language of the user. Texts can be displayed for the user in many different ways, for example as Labels, as a selection option in a Drop-Down, or as messages.

Internationalization involves defining each language-relevant literal in the Web Dynpro application in such a way that it can be translated. The user logon defines the logon language used and therefore the language that will be used for displaying data.

We have not yet discussed defining translation-relevant texts, but we have already come across a few areas where they would have been rel-evant – table titles, for example. Different techniques are available for defining translatable texts:

Online Text Repository (OTR)

E E

Text symbols in ABAP classes

E E

Texts in the ABAP Dictionary

E E

These texts are displayed for the user in the UI or as messages. Even more options are available as message sources for outputting messages:

Messages from the

E

E T100 table

Assistance class

E

E for the Web Dynpro application

Messages from exception classes

E E

In this section, we will therefore look at options for internationalizing texts. We will begin with the ABAP Dictionary, then discuss OTR, and also look more closely at using the assistance class. Our second focus

Internationaliza-tion techniques

Issuing messages

Messages and Internationalization 3.4

aside from texts will be on outputting messages to the user and you will learn basic techniques and uses.

Texts from the ABAP Dictionary 3.4.1

You can defi ne texts for data elements in the ABAP Dictionary. They are called fi eld labels and have four different lengths: short, medium, long, and heading. Figure 3.70 shows the fi eld labels for the SEOCLSNAME data element.

Field Labels for a Data Element Figure 3.70

You can translate text symbols into the required target languages using Transaction SE63.

When you create view elements such as Label, Caption, and Table-Column, a reference to another view element is created that allows you to enter or display data. For example, through the labelFor property, the Label UI element can create a reference to an InputElement UI element.

Through data binding, this other view element has a reference to a con-text attribute. If this has been typed with an ABAP Dictionary data ele-ment, the Medium fi eld label is used as the label text. For this example, this means that the Medium fi eld label is used as the label value.

In addition to this (from the perspective of Label, Caption, and Table-Column) indirect use of data element texts, you can also reference data elements directly. Do this using the button in the Create Binding…

column, next to the property for a view element. You already know this

Field labels

Using fi eld labels in the UI

Explicitly defi ning a data element

button from defining data binding on context nodes or context attri-butes. When you click on the button, the context view opens. Instead of selecting a node or an attribute (as we did before), select the DDIC Bind-ing to/from button. This enables you to define the data element name explicitly and choose the relevant text length, thereby defining the text selection. You remove the definition by clicking on the DDIC Binding to/From button again.

Access classes on ABAP Dictionary definitions are another option for using texts from the ABAP Dictionary. For example, RTTI provides classes to determine texts for DDIC definitions. Another class you can use for reading DDIC texts is CL_TEXT_IDENTIFIER.

Texts from the Online Text Repository 3.4.2

The Online Text Repository (OTR) is a central storage area for texts that is independent of the Web Dynpro framework. To be able to use your own short texts (also called alias texts) in a Web Dynpro application, you must create them. To do this, you use the OTR browser.

Online Text Repository

The OTR is a central storage area for texts and provides services for editing and managing these texts.

It differentiates between short texts up to 255 characters long and texts of any length. Each text is stored only once per package. General, frequently occurring texts are included in the OTR basic vocabulary and can be used across all packages.

Internally, the texts are identified by unique numbers. A number indicates a concept that not only includes other spellings for the text (such as abbrevia-tions and length variaabbrevia-tions), but also its translaabbrevia-tions and possibly its localiza-tion-specific (specific to industry, country, or customer) instances.

If you are in the display or edit area of a controller, view, or window, you will find this browser in the menu under the Goto Online Text Repository Browser option. If you are in display mode, only the OTR contents are displayed, without the option to create new OTR alias texts.

RTTI classes and CL_TEXT_

IDENTIFIER

OTR short texts

Messages and Internationalization 3.4

Alias texts are grouped by packages in the OTR browser (see Figure 3.71).

The standard package for texts is SOTR_VOCABULARY_BASIC (1) which con-tains commonly used texts provided by SAP. If you need your own texts, you must create your own OTR alias texts. The functions for this are avail-able in the application toolbar (4). When doing so, you must specify the Alias Name (3) for the OTR alias text. It consists of the package where the text is stored, and an identifi er. For example, the abstract text has been defi ned under the $TMP/ABSTRACT alias name in the $TMP package (2).

4

OTR Browser Figure 3.71

Other functions the OTR browser provides include searching for texts that have already been created, translating texts, and the where-used list of texts. You can use Transaction SOTR_EDIT as an alternative for creat-ing OTR alias texts.

If you are in a view element defi nition, you can also create OTR alias texts directly by forward navigating out of a view element property (see Figure 3.72).

The display text for a Label UI element is defi ned using the text prop-erty (1). Here, you can either access already defi ned OTR alias texts using the input help, or you can create new texts. To create an OTR alias text, enter a name for the text that must correspond to the generic

$OTR:<package>/<alias> name structure . The name in this example is

$OTR:$TMP/NAMECLASS. When you press the [Enter] key, an intermediate dialog box for confi rming whether you want to create the OTR alias text (2) opens. Click on Yes to confi rm that you do.

Setting up the browser

Forward navigation

Creating OTR alias texts by forward navigating

Creating an OTR Alias Text by Forward Navigating Figure 3.72

The window for creating the OTR alias text then opens. The alias text name has already been transferred from the properties. The text length is calculated from the entry in the text editor but you can also manu-ally change it; for example, it can be changed to have more characters available for translations. Because you have entered the text for the OTR alias text (3), click on Checkmark (4) to confi rm your entry. You have now completed the creation process, and can use the new OTR alias text anywhere in your Web Dynpro application.

You can also access OTR alias texts through an implementation. To do this, use the get_otr_text_by_alias( ) method from the CL_WD_UTILI-TIES ABAP class to access text according to language using the OTR alias.

An example of this is shown in Listing 3.19.

DATA: ld_otr_alias_text TYPE string.

ld_otr_alias_text = cl_wd_utilities=>get_otr_text_by_alias(

alias = ‘$TMP/NAMECLASS’

language = sy-langu ).

Implementing Read Access to an OTR Alias Text Listing 3.19

Maintaining an OTR alias text

Read access to Online Text Repository with the CL_WD_

UTILITIES ABAP class

Messages and Internationalization 3.4

OTR is a central medium to define reusable and translatable texts for Web Dynpro applications.

Texts from the Assistance Class 3.4.3

You know from programming executable programs and module pools that text symbols summarized in a text pool can be defined for these programs.

This technique is not immediately available for Web Dynpro components and Web Dynpro applications; however, a mechanism was created using an ABAP class (the assistance class that was already the subject of Chapter 2, Web Dynpro Architecture) to define text symbols and be able to use them in a Web Dynpro component. Let us look at an example of this:

1. Switch to the editing area of the ZWDC_03_CLASS_BROWSER Web Dyn-pro component and then change to the Dyn-properties of the Web DynDyn-pro component.

Create the assistance class, calling it

2. ZCL_03_A_CLASS_BROWSER.

Navigate to the assistance class. When you switch to the class meth-3.

ods, you see the inherited if_wd_component_assistance~get_text() method that will enable texts to be read.

4. You can now define texts by selecting the Goto Text Elements menu option. Assign a three-digit ID for a text and then the text that can be translated into a target language when you select the Goto Translation menu option.

Figure 3.73 shows an example of the text definition:

Assign a three-digit ID (

E

E 1) for the text. This ID must not contain

any spaces. You will use it later to determine the text symbol.

Create the text (

E

E 2). It can contain placeholders that can be replaced when you call the get_text( ) method. You can specify a maxi-mum of four placeholders called &PARA1& to &PARA4& that are writ-ten in uppercase spelling and limited by &.

The defined length

corre-spond to the defined length and can contain a maximum of 132 characters. You will generally change the maximum length;

other-Assistance class

Creating a text element

wise, as a result of the defi ned length, too few characters may be available for translating into a target language.

Creating a Text Symbol Figure 3.73

5. Use the Back button ([F3] key) to switch to the assistance class defi -nition. On the Attributes tab, you can defi ne constants that have the text symbol ID as a value. By creating constants, you can create descriptive IDs for text symbols that, as a result of the name, are more meaningful than the three-digit IDs (see Figure 3.74):

Give the constant for the text symbol (

E

E 1) a meaningful name.

The reference type to be used for this type of constant is

E

E WDR_TEXT_

KEY (2).

The

E

E Initial value for the constant (3) corresponds to the three-digit ID for the text symbol from the defi nition.

Defi ning Constants for Text Symbols in an Assistance Class Figure 3.74

6. All of the relevant defi nitions have now been confi gured for the text in the assistance class. After you activate the assistance class and all dependent objects, you can use it in the Web Dynpro component.

Creating constants for a text element

Activating

Messages and Internationalization 3.4

Due to the assistance class being assigned to the Web Dynpro compo-nent, the Web Dynpro framework automatically creates the wd_assist attribute for accessing the assistance class in all controllers of the Web Dynpro component.

We will now discuss accessing the previously defined text element in the assistance class. In the Web Dynpro component example, the user can enter a text for an ABAP class for which he can then determine the ABAP class methods by clicking on the use BTN_CLASS_SEARCH button.

The onactionsearch_methods( ) method in the V_CLASS_SELECTION view was defined as an action handler. If an ABAP class is not found, a text is issued for the user in the TV_DESCR_CLASS UI element for TextView. List-ing 3.20 shows an extract of the current implementation.

* Selection data from context

DATA: lv_rs_value TYPE zst_03_wd_class_sel_crit.

* Handling, info text for users

lv_rs_value-descr_class = ‘Class does not exist’.

* Set values back into description

wd_comp_controller->setctx_class_sel_crit(

is_value = lv_rs_value ).

Extract of Action Handling for ABAP Class Search Listing 3.20

The following statement sets the information text for the user – in German:

lv_rs_value-beschr_klasse = ‘Klasse existiert nicht’.

If the user is logged on in English and cannot speak German, this will present a problem when using the Web Dynpro application.

To overcome this shortcoming, you use the assistance class to determine the texts for a specific target language and then make the assignment.

We have already discussed how to define the text you want to be output.

Now, we will look at reading the text. The Web Dynpro Code Wizard provides support for determining defined texts from the assistance class (see Figure 3.75).

Example of improvement

Neglecting of language

Web Dynpro Code Wizard

Reading a Text Symbol from the Assistance Class Using Figure 3.75

the Web Dynpro Code Wizard

After you have placed the cursor in the appropriate place in the 1.

source text, call the Web Dynpro Code Wizard ([Ctrl] + [F7] key combination).

2. Switch to the General tab and select the Text Symbol Access option.

The get_text( ) method from the assistance class returns a string value as the result. You can save this value in an already defi ned meth-od variable or create a new variable. In this example, use the already defi ned ld_text_assistance (1) variable. In the Text Symbol input fi eld (2), you defi ne the text symbol you want to read. Input help is available for the text symbols defi ned in the assistance class.

3. After you have made your entries, confi rm them to generate the source code. Listing 3.21 shows the produced source text.

METHOD onactionsearch_methods .

* Selection data from context

DATA: lv_rs_value TYPE zst_03_wd_class_sel_crit,

* Texts from assistance class

ld_text_assistance TYPE string.

** Variant 1 **

* Created by Web Dynpro Code Wizard and left unchanged

*ld_text_assistance =

*wd_assist->if_wd_component_assistance~get_text( ‘T01’ ).

** Variant 2 **

* Created by Web Dynpro Code Wizard and enhanced manually ld_text_assistance =

wd_assist->if_wd_component_assistance~get_text(

key = wd_assist->c_no_class Text symbol access

Generating source text

Messages and Internationalization 3.4

para1 = lv_rs_value-name_class ).

* Assign text from assistance class

lv_rs_value-descr_class = ld_text_assistance.

ENDMETHOD.

Determining Text Using the Assistance Class Listing 3.21

In the Variant 1 section in Listing 3.21 you see the get_text( ) method call as it was created by the Web Dynpro Code Wizard. The ld_text_

assistance variable was specified to transfer the return value of the method. The T01 text literal transfers the ID for the text to the method.

The placeholder is not replaced in the text because no value for the placeholder is transferred to the method. You would have to use alter-native options to do this when using this call variant; for example, by sending a message to the user.

Variant 2 contains a second call variant that has resulted from manual changes to the created source text. The literal text was replaced by the descriptive wd_assist->c_no_class constant. The replacement value for the placeholder in the text element was also transferred to the para1 importing parameter. This replaces the placeholder with the value of the actual parameter, lv_rs_value-name_class.

Messages 3.4.4

Using the MESSAGE statement to notify users in ABAP programs should be nothing new to you:

MESSAGE E041(OO) WITH `CX_ROOT`.

* Could not repair class pool for class &1

You should be familiar with the call syntax; however, we will neverthe-less repeat it in an example to discuss using messages in Web Dynpro components.

Message type

E E

A message is initiated by the MESSAGE statement. One addition is the message type, whose functions include specifying how, where, and when the message is displayed, and the effect the message will have on the runtime behavior of the program. Values available for the mes-sage type include E for error or I for information.

Automatically generated source code

Manually adjusted source code

ABAP MESSAGE statement

Message number and message class

E E

The three-digit message number specifi es which message should be read from the T100 table. For this, you still have to specify the message class from which the message texts are determined. The message num-ber within a message class is unique. Preferably use Transaction SE91 (message maintenance) to determine a list of all messages in a mes-sage class.

Placeholder

E E

If the message text has placeholders of which a maximum of four can be defi ned in the short text and four in the long text, you must specify the replacement values for the MESSAGE statement with the WITH addi-tion.

After this brief discussion, we will look at how to map the described aspects of the MESSAGE statement in Web Dynpro components.

Message Area

You need a message area to be able to display messages. Two options are available for this in Web Dynpro development.

The fi rst option involves using a predefi ned message area. This is known as the standard message area and can be used as shown in Figure 3.76.

The standard message area is shown in the page header, and the message text is displayed (1).

Standard Message Area Figure 3.76

You can determine whether you want the message area to always be shown or to only be shown as required. To implement this setting, you must switch to the Properties of the corresponding Web Dynpro appli-cation , as you can see in Figure 3.77.

Message area

Standard message area

Display

Messages and Internationalization 3.4

Message Area Display Figure 3.77

In the Handling of Messages property group, you can specify whether you want the message area to only be shown as required or to always be displayed. If you choose the Show Message Component on Demand option, when a message is issued, the displayed view elements move downward by the amount of space required for this. If there is no mes-sage to issue, the mesmes-sage area is not displayed and the view elements will be displayed according to the layout defi nition.

A second option for displaying the message area is to use the MessageArea UI element. Using it means you can issue the messages anywhere in the layout. If you use this UI element, you must ensure (particularly when reusing Web Dynpro components) that you only use it once per win-dow in the entire Web Dynpro application; otherwise, runtime errors will occur.

Regardless of whether you use the fi rst or second option for displaying the message area, you can infl uence the appearance of the message area.

To do this, you must customize the message area in a suitable place – for

To do this, you must customize the message area in a suitable place – for

Related documents