Localization in COBOL .NET

Overview

Do you create applications for use in multiple locations and languages? This article will show you how to use the power of LOCALIZATION within Visual Studio .NET to create one screen and have it display different languages. The source code was created with Microsoft Visual Studio.NET 2003 and Fujitsu NetCOBOL for .NET V2.0.

Background

With many companies being multi-national, developers are having to create applications not only in their native language, but also in languages for the countries in which their company has offices. And many times these additional languages present unique challenges due to the presence of local variants to the base language. In the past developers created the application in their language and copied the application to a new name and changed the presentation to the language where the application was going to be deployed. This resulted in having the same program exist for different languages, same core logic, but different presentation layer.

Through the use LOCALIZATION in Visual Studio.NET you can now create one code-base and have multiple presentation layers in different languages use the same code-base. Our example will use a simple WinForm that will enable you to view a screen in either English or German. Please remember though, the intent of the article is to show you how to enable multiple languages, and not present you with a completed application.

Our application has two screens. An Introductory screen:

intoscn.jpg

and a presentation screen:

engscn.jpg

It is the presentation screen that we will enhance to display in German. We will not go into the specifics how to create a WinForm application using NetCOBOL for .NET. Please refer to the online documentation for assistance.

Multi-Language Capabilities

Microsoft has enabled multi-language capabilities within Visual Studio.NET via a combination of the LOCALIZABLE and LANGUAGE settings for the Form you are working on. By default your language setting is set to the the local area where you are. By changing these variables you can create language targeted screens.

Within Visual Studio.NET 2003 there are two ways to create a foreign language representation of your screens. One way is to use the utility "WINRES" and the other is to use the Designer. I chose to use the Designer so I can visually see what the changes will be to my screen and if any additional enhancements to the form will be required by changing the text being displayed. You begin by selecting your Form and reviewing the properties, looking under the Misc area for the LOCALIZABLE and LANGUAGE settings as such:

formprop.jpg

Notice the LANGUAGE and LOCALIZABLE settings are set to English(United States) and True respectively.  I want to create a form in German though so we need to change the LANGUAGE to Germany (Germany) by using the drop-down list. Notice the different versions of German available to you? You can target the specific dialect of a language by first reviewing the options available to you and then selecting the closest version of that language.

For further information on what language settings are available see the CultureInfo Class in the .NET Framework help.

 When you select a new language you will notice the creation of several new files in the Solution Explorer. These files are XML based project files that will contain the language specific items for the screen.  The following image shows the files:

solexplr.jpg

The red box is highlighting the two new files that were created when we selected the German language from the drop-down list in the form properties. If you were to look at these files in VS.NET you will see they appear as spreadsheets with the name, value and other pieces of information necessary for VS.NET to display the new values. Take a moment and review the files in the solution provided. You will see the values for the labels already present.

What VS.NET did was create a copy of the original screen, with all the objects on it, and provide you with a formatted way in which to change the language to German. You have the original screen to use as a guide so you know what it is you are changing and where, instead of trying to change something in a spreadsheet styled display. Using the Designer to create the foreign language version of your screen enables you to see what it looks like as you are changing it. This permits you to see right away if changes to the text will require the size of the labels to change, which you can do right away since you are already in the Designer!

Select the Form and change the LANGUAGE back to English(United States). Notice the Designer does not load a new form, but merely updates the existing form with the new language settings from the RESX file for English(United States).

The Driver Program

Since I do not want to change the code page my computer is using I created the driver program to demonstrate the use of the multi-language capabilities. The driver program, FORM1.COB, has two methods (one for each click event of the command buttons) that set a variable, create a new Globalization instantiation and finally show the form using the new Globalization instance. Since both methods are relatively the same I will show the German method:

DEclick.jpg

CLASS-DEMO was established in the REPOSITORY as a reference to the DEMO form. We instantiate the form, passing it a flag telling it which language we want to use and then show the form. The real secret is in the "NEW"  method of the DEMO class.

Enablement

An overloaded "NEW" method was created in the DEMO program.

newmthd.jpg

The original "NEW" method is shown for comparison. Two variables were added, an object reference to the CULTUREINFO class (objGlobalization) and a LINKAGE parameter to accept the value being passed from the driver program (LNK-LANG-IND).

The language indicator being passed in is evaluated. The values used for the instantiation of the CultureInfo class were determined from the documentation and from the value created for the RESX files. The properties for the CURRENTCULTURE and CURRENTUICULTURE must be set to the new culture info we established prior to invoking the InitializeComponent method. When the form is displayed, depending on which language was selected will determine which form is displayed. Windows will now display the proper information for the correct language.

Wrap-Up

That's it. Once you see how it is done the process is so simple, yet very, very efficient and effective! Unzip the source file, rebuild the solution and execute the process without debugging the first time so you see what is displayed. Next step into the code and visually see what is occurring. Finally, and this should put everything into perspective for you, select the English language in the LANGUAGE property, then select a new language, say Italian. Notice the files that are created and then modify the screen in the Designer to say 'Italian' instead of 'German'. Then add a button to the driver program to call your new Italian screen. Finally update the overloaded "NEW" method to create an Italian instantiation of the CultureInfo class, recompile the solution and see what happens.

Maintenance Note: Once you have created the new screens you can provide a translator or someone familiar with the local language, the spreadsheet representation of your screen and they can 'tweak and tune' the language to be more accurate. You can maintain the specific language items in either the spreadsheet format or the Designer.

I hope you find this article interesting and useful! Happy Coding!

Up Next
    Ebook Download
    View all
    Learn
    View all