Google+ Facebook Twitter MySpace SC

Friday, August 24, 2012

Writing Multilanguage Applications

Writing Multilanguage Applications

This chapter mainly focuses on the creation of Multilanguage applications.So,
the applications we realize are going to be easilyinternationalized without being necessary to recode them,butonlyto translate some centralized strings.For this,we haveto respect some rules,as follows: using the tools offered by the ABAP Workbench,establishing an initial language for our project,and avoiding to enter language specific texts in the codification of the business logic.
Internationalization(I18N)is a need for the global business software.In this chapter,we will see some of the tools offered by the ABAP Workbench to create Multilanguage User Interface and the tools we can use to make Multilanguage records in the database.
When the user logs onto the SAP System,he should enter a log-on language.If he doesn’t enter a language,then it is used the default log-on language from the user account.


Transaction SU01
Log-on language

This is the language in which the Web Dynpro application(and all others development objects)is originally written and the language that the System uses after logging-on.
A list with all the languages installed in the system we can find by using the transaction SMLT–Language Management.
Transaction language management

In our case,we can use English,German or Russian as original log-on language,and we can translate our application from the original language into another one.

ABAP Workbench offers many tools that simplify the process of creating internationalized applications.So,we create WD applications that support multiple languages without re-designing or modifying.
As mentioned above,an internationalized application doesn’t contain languagespecific text elements in the source text.As language-specific texts,we can mention:
  • Texts used,for example,to label UI elements or required for the dynamic programming,etc.
  • Texts defined when creating development objects in the ABAP Dictionary
  • Messages
Creating Multilanguage User Interfaces
We create a simple WD component,where we use some of the above-mentioned tools to offer support for English and German without making any code changes.All we have to do is to translate certain centralised strings and,after changing the log-on language(in our case,from“en”to“de”),the data will be automatically shown in the respective language.The WD component structure is presented.
WD component structure

In the context view,we create a context node named PERSON, Cardinality 1...1,Singleton,dictionary structure YPERSON and a context attribute named TEXT_I18N of STRING type.The context view and the view layout are presented.
Context node and view layout

We didnt insert any static strings for the“text”property of the UI elements Label and Button,or for the Caption view element.The strings shown as labels for the InputField UI elements represent the texts from the label field of the elementary data elements created in the ABAP Dictionary.For example,the label with the ID “FIRSTNAME_LBL” represents the label for the InputField bound to the attribute FIRSTNAME.The data element for this attribute is YPERSON-FIRSTNAME.If we look in our table definition,we can see that the elementary data type is YFIRSTNAME.. it can be seenthat“text”property of the label FIRSTNAME_LBL doesn’t contain anystatic values.To establish this string, we use the text with thelength Medium,defined in the YFIRSTNAME data element,i.e.“First Name”.
Text property and elementary data elements

Internationalization of Data Elements Defined in ABAP Dictionary
To internationalized data element defined in ABAP Dictionary, we have to translate the corresponding texts.The way we can perform this translations.
Translating the texts from a data element

After this,a pop-up window asks the language in which we want to translate the texts.We choose German and we enter the texts to be translated,for the strings.We repeat the same steps,until all the strings for the corresponding elementary data elements are translated.
Translating the strings

Internationalization of Domains Defined in ABAP Dictionary
Similarly,we translate the texts stored in our Domain Y_COUNTRY_DOMAIN.
English–German translation for a domain

Translating the domain fixed values

Internationalization of Text from OTR
In our example,we have to enter a value in the text property of the UI element Button.To do this,we choose the OTR text that exists in the SOTR_VOCABULARY_BASIC package.
The OTR text from the SOTR_VOCABULARY_BASIC package

To create our own OTR text,we can use the menu Goto Online Text Repository Browser or the transaction SOTR_EDIT Editor for OTR texts. Figure shows how we can create an OTR text by using the Online Text Repository Browser.
Creating OTR texts

The basic vocabulary stored in the SOTR_VOCABULARY_BASIC package can be used for all the packages,but the created OTR textsare stored only once per each package.
Our own-defined OTR text

 To translate an OTR text,we can use the transaction SE63 Translation: Original Screen.After translating it,we can use our own defined OTR text in the same way as the OTR texts defined by SAP in the SOTR_VOCABULARY_BASIC package.Then,we have to create a Multilanguage text for the text property of the Caption element.
Internationalization of Text from Assistance Class
In the previous chapter,we have seen how we can use an Assistant Class to work with messages. In this case,we use the texts stored in the text pool of the assistance class to make Multilanguage our text required by the Caption view element. We create an assistance class named YCL_I18N.We define here the text to be made Multilanguage.
Texts from assistance class

In the field mLen,we have to specify the maximum length of the text string of a text symbol.As we have already seen,this value should be greater than or equal to the defined length(dLen).It is better to use a higher value,because,at design time,we don’t knowfor how many languages we offer support.In English,forexample,the length is 36,but when we translate this string in another language,it might be greater.In this case,we could not be able to enter the entire translation text.This length is saved in the text pool. To translate this text from English into German,we use the menu Goto->Translation.
Translating texts from the assistance class

After this,we realise a data binding between the attribute TEXT_I18N and the property text of the Caption element.We dynamically access the string we have just defined and translated.
wdDoInit( )Hook method
 METHOD wddoinit.
 DATA:lv_text TYPE string.
 lv_text = wd_assist->if_wd_component_assistance~get_text('001').
 wd_context->set_attribute(name ='TEXT_I18N'
 value=lv_text).
 ENDMETHOD
As we have mentioned above,to be able to have access to the text symbols of the assistance class by using the instance attribute WD_ASSIST,we have to assign the assistance class to our component.After this,we run our application.
Runtime. Default language: English

Internationalization of Messages
We create a Message class named YCL_I18N_MSG,where we define a message with the ID“000”and the short text “First Name is nrequired!”We want to show this message when the user presses the Update button.
Runtime – German

To translate this message,we choose from MENU Goto -->translation.
Translating a short text in the message class

When the user presses the Upload button,the Framework triggers the even handler method onactionsave. We run our application in the original language English and in German.
The onactionsave event handler method
 METHOD onactionsave.
 DATA: lr_api_controller TYPE REF TO if_wd_controller,
 lr_message_manager TYPE REF TO if_wd_message_manager.
 lr_api_controller?=wd_this->wd_get_api( ).
 lr_message_manager=lr_api_controller->get_message_manager( ).
 lr_message_manager-report_t100_message(msgid ='YCL_I18N_MSG'
 msgno='000'msgty ='E'.
 ENDMETHOD.
Multilanguage messages



Multilanguage Records in the Database In this case,we make Multilanguage the records we store in a database table.We create a very simple example to show how we can store data in a database table,not only in the log-on language,and then we create the User Interface in Web Dynpro to see how we can process these data.
We copy the table YEU_COUNTRIES and rename it YEU_I18N. Our target is to be able to store the political system for each EU Country not only in English,but in German,too.
Study an Example Created in the System
Before creating our own example,we shall briefly explain the table structure we are going to build.In this respect,we study a simple example presented in the system,starting with the search of a text table.A text table usually has the suffix T and contains an explanatory text in several languages,for each key. With the transaction SE11 ,we display all the tables that end in “_T”.
Searching to find a text table

From the list that appears,we choose to see the structure of the text table for Text Table for Release/Lock object Handling. As we can see,we have a Field named SPRAS of SPRAS type that represents the Language Key and two fields BEZ(description)and KURZBEZ(short description) that contain an explanatory text in several languages,for each FSOBJANL key.In this case,we have support for German and English, so we have the translation in two languages(E – English,D –German) for each key. Let’s look at the foreign key relationship:As we can see, this table is a text table for the table /BEV3/CHCTFSOS The structure of this table is presented. The table /BEV3/CHCFSOS_T is a text table for /BEV3/CHCTFSOS.If we study both tables,we see that the text table additionally contains a language key.
Text table structure

The content of a text table

Foreign key relationship

Table /BEV3/CHCFSOS

field and two extra Fields that contain an explanatory text in English and in German,for each key entry of /BEV3/CHCTFSOS.Let’s look at the structure of the table /BEV3/CHCFSOBJS.
Structure of the table /BEV3/CHCFSOBJS

For our purpose,in this case it is interesting the Field FSOBJANL.As we can see,this field has an foreign key defined to /BEV3/CHCTFSOS.
Creating Table Structures and Internationalization of the Records
For our example,we create the same structure as the one presented above,but with only one explanatory text for the political system per each EU Country. The table YEU_I18N has the structure presented.
YEU_I18N table

The Field POLITICALSYSTEM has defined an foreign key to the table YKEY that holds only the ID of the politicalsystem.
Key table

Text table

To link the politicalsystem key with the descriptions included in the text table, we have to link the table YKEY_T with the tableYKEY by using a foreign key.
Foreign key

Now,we have to maintain the data that refer to an object and are technically distributed between the tables YKEY and YKEY_T.
Maintaining data in the tables YKEY and YKEY_T

To realize this,we create a Maintenance View.Call transaction SE11,enter the name of the new maintenance view in the field VIEW and press CREATE.At the next popup window choose the kind of view we want to create.In our case “Maintenance View”. Enter the tablenames as shown below and pres button“Relationships”.In our case we can accept the suggestion. The View Fields are presented. After this,we choose from the menu Utilities --> Table Maintenance Generator ,to generate table maintenance.
Maintenance view

View fields

Generating maintenance view

We go back to the Maintenance View and we choose from the menu Utilities --> Contents.
Insert content

New entries

We insert three political systems and then we translate them in German.To do this,we select the entry we want to translate and we choose from the menu Goto --> Translation.
Translating records

Using the Internationalized Records in WebDynpro
Through a Web Dynpro application,we create a mini-administration User Interface for our table YEU_I18N.The view layout and the context node are presented.

View layout and context node

The context node has the dictionary structure YEU_I18N. The runtime result is presented.
Internationalization – database records

To select the values from the database according to the log-on language,we create a database view in the ABAP Dictionary and perform a selection,where spras sy-langu: SELECT * FROM y_i18nv INTO TABLE lt_i18nv WHERE spras = sy-langu.
We create a context node named I18NSELECT that has,as dictionary structure the view “Y_I18NV”that we have created in the ABAP Dictionary.
Database view and context node

Runtime

No comments:

Post a Comment