Skip to Content

SAP puts a very strong emphasis on multilingual applications. So if you ever wondered how to make your Web Dynpro application multilingual this is a small how-to Weblog for you. I explain how to make your application multilingual without the need to set up a translation infrastructure (which is still to come but will make everything simpler).

Basics

Generate  Language  Files

But at first you will not see any of these resource files because the resource file generator only runs when you right-click on the project and choose “Create Archive”. If I have a Web Dynpro component named

MyComponent

located in the package

com.sap.mycomp

and project language set to English, a resource file will be generated for everything inside the component with the name

ResourceMyComponent.properties

and

ResourceMyComponent_en.properties

in the Java package

com.sap.mycomp.wdp

. Open it and you will see some very simple key value pairs like this:



  1. —————————————————————————

  2. This file has been generated by the Web Dynpro Code Generator

  3. DON’T MODIFY!!! CHANGES WILL BE LOST WHENEVER THE FILE GETS GENERATED AGAIN

  4. —————————————————————————

  1. Resource bundle for FlightSearchComp

  1. view FlightSearchListView

view.FlightSearchListView.Table_14.Column.Table_14_Seatsmax.Header.text = Seatsmax

view.FlightSearchListView.Button_15.text = back

view.FlightSearchListView.Table_14.Column.Table_14_Airpto.Header.text = Airpto

view.FlightSearchListView.Table_14.Column.Table_14_Airpfrom.Header.text = Airpfrom


Translating

What would I need to do to translate this file into German?

I need to create a resource file with the same name but ending

_de.properties

in the same Java package. Then I would need to learn German and put the translated values with the same keys into that file. Let’s go through it step by step.

In the

src/packages

folder we create a Java package named

com.sap.mycomp.wdp

. Then we copy the ResourceMyComp_en.properties to that location. There we rename the file to

ResourceMyComp_de.properties

. Then we can open the file and translate the values into German.

The reason we don’t leave the properties file in the gen_wdp folder is because everything that stays there gets deleted next time code the project is rebuild. But in the

src/packages

folder everything is safe and will be included in the distributable archive.

Testing

That’s it! We’re ready to test. First we need to configure our browser for a different language. This browser language is transmitted through an  http header and Web Dynpro application chooses the correct language file according to the browser language,  or according to the specified language of the user if the application uses authentication. To configure the browser we open our Internet Explorer and choose in the menu item  Tools/Internet Options . There is a button 

languages

where we can add the desired language to our browser. You should put the desired language at the top of the list and close all browser windows to put the changes into effect. You can now “Deploy and Run” your application and it should show in German!

Summary

In general I would recommend not to translate your application until it is pretty much finished. Otherwise you always have to keep the resource bundle files in sync.

You learned how to add a different language to your Web Dynpro application by creating a new resource bundle file. You were able to test it by changing the language setting of your browser. We did not touch the issue of messages that are used in the program code. For this you should add messages in the message editor and call the defined keys in your code instead of hard coding the strings. How to do that is explained in detail in the

SAP Netweaver Studio help

and in the Java API documentation for

java.util.ResourceBundle

.

Final remark

This is a workaround for version SP2 of the Netweaver Studio. In SP3 and later versions you may copy and translate the

*.xlf

files in the

src/packages

directly because then the

.properties

files are generated for every

.xlf

file. But even this should not be necessary anymore once the translation infrastructure is in place.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Michael Barth
    Is there a limit to the number of languages you can add this way with SP2? I was told, that only two languages per application are possible?
    Regards
    Michael
    (0) 
    1. David Beisert
      No there is no limit on how many languages you can add this way.

      About the limitation of the 2 languages: In SP2 there is a project language and a generation language which can be configured independently. Maybe this is why you were under the impression only 2 languages are possible. At the moment the SP2 IDE only generates the default properties file and a properties file for a language that is configured under Menu/Window -> preference pages -> WebDynpro -> generation. Because this can be configured independently this can also have some interesting effects. If your project language differs from the generation language it can happen that no texts will appear in your views because there were no >language_abbreviation<.xlf files for that language. As far as I know from SP3 on the generation will generate language files for every language that is used in the project.

      (0) 

Leave a Reply