PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

Sybase PowerBuilder - DataWindow.NET with Multi-Language Support

Overcoming Sybase's limitations

Microsoft Visual Studio has excellent multi-language support both at design time and runtime, while Sybase DataWindow.NET doesn't have that. In this article we'll consider how to implement multi-language data presentation using DataWindow.NET.

DataWindow.NET has two integral parts. One of them is intended to work in WinForms, the other in WebForms. In this article we'll use WinForms; however, our solutions are suitable for WebForms too.

One of the most significant features of .NET technology is its ability to create applications for an international audience. The Microsoft .NET Framework has a rich set of classes set for globalization and localization. Microsoft Visual Studio WinForm Designer is tightly connected to the Resource Manager, allowing localized forms to be saved as resources. Unfortunately, the Sybase DataWindow.NET Designer can't save local information.

There are two ways of providing different presentations based on a specific culture. One solution is to use the DataWindow control Modify() function and the other is to use different DataWindows for different cultures. Both solutions have their peculiar pros and cons.

Globalization and Localization in Visual Studio and DataWindow.NET
Microsoft Visual Studio has built-in support for both globalization and localization. Globalization means applying culture-based formatting to existing data. Localization means presenting previously saved information dependent on the culture selected. Culture is cultural information that specifies language and region.

All cultures in the .NET Framework are identified by special culture codes. For example,

  • en: Specifies the English language, no region,
  • en-CA: Specifies the English language, Canada.
The specific culture can be changed using the CultureInfo class. The following code example demonstrates how to set current culture to French-Canadian:

// Set new Current Culture
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");

For globalization purposes, the .NET Framework supports formats for numbers, currencies, dates, and times for each culture. The following example sets the currency format:

// Set currency format
label1.Text = (500).ToString("C");

For localization, Visual Studio saves a resource file for each form that contains the alternative form data for the given culture. The following code example demonstrates how to set a user interface current culture to French-France.

// Set new User Interface Current Culture
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

Unfortunately the DataWindow.NET engine doesn't use the .NET Framework globalization and localization capabilities. For globalization purposes the DataWindow engine has several of its own special formats like "[currency]," "[general]," "[shortdate]," etc., but they're related to the local computer regional settings, not to the current culture. DataWindow.NET can't save localized data. The purpose of this article is to explain how to overcome this limitation.

Multi-Language Demo
We'll consider two possible approaches to implementing multi-language support in DataWindow.NET. The first solution is to dynamically change all culture-specific properties for the DataWindow objects. These properties include, for example, text, size, position, and color. The second solution is to have a separate DataWindowObject for each culture at design time and switch the DataWindowObject in use at runtime.

Let's create a simple application to demonstrate both approaches. In Figures 1-3 we can see a form with a combo-box to switch current culture, two buttons for the two different multi-language support methods, and a DataWindow where the results are shown. The figures show the form displayed for the English, French, and Russian cultures.

First Solution: Modify() Function
Modify() and SetProperty() functions are powerful tools to change the DataWindow presentation. It's possible to change the DataWindow objects' text, color, size, and position. For example, if we want to change the text to French we can call:




Unfortunately, this approach has several limitations. First, there's no design-time support for creating localized information. Instead, we have to save all such information manually. Second, there's a layout problem. For example, English words are usually shorter than French or Russian. So we need to include extra spaces between DataWindow objects and increase their size.

Third, it's not obvious where to save localized information. There are several places where the localized information could be saved. Among them are the database, registry, resources, and DataStore with saved data. The decision is up to the developer, but we recommend the database as the best solution because it's easier to maintain. Nevertheless, for purposes of this example we'll use localized resource files. We can add several resource files for each culture and put culture-specific information in them. For example, we put the data shown in Table 1 in the dwModify.fr-FR.resx file.

The following code fragment reads resource information from the file:

// Try to read resources
    // Combined name for resource search
    name = DataWindowObject + "." + DWObject + "." + ObjectProperty;

    // Read resources from dwModify resource file
    value = dwModify.ResourceManager.GetString(name);
catch(SomeException e)
    value = "";
    errmsg = e.Message;

To simplify error handling we can create a Modify() style function. It's more familiar to PowerBuilder developers because it returns the error string (see Listing 1).

Listing 2 contains a Modify() function that sets the resource-specific value for a given property.

Second Solution: DataWindow Replacing
The DataWindow .NET engine searches for the DataWindowObject using the specified LibraryList property. The main idea is to have one library (pbl-file) for the default culture and one additional pbl-file for each supported alternate culture. This additional pbl-file can contain the culture code in its filename or it could be put in a subdirectory with that name. For example, we can create the folder pbl and subfolders named en-GB and fr-FR. In the pbl folder we'll put the default library file demo.pbl and put demo.en-GB.pbl in the en-GB subfolder. The culture-specific library should appear before the default library in the library list:

Dw.LibraryList = "pbl\\fr-FR\\demo.fr-FR.pbl;pbl\\demo.pbl;"

You can see the directory structure in the Figure 4.

More Stories By Mikhail Klygin

Mikhail Klygin is a senior developer and has been using PowerBuilder since version 5.0.

Comments (3)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.