Designing culturesensitive forms

Up to this point, you've successfully built the English version of the sales force application so far—the menu bars, logos, captions, and messages are all displayed in English. Your next task is to change your application so that these items are displayed in Japanese instead.

Instinctively, you might think of storing each caption, logo, and message as strings in a resource file, with a separate resource file for each different language supported in your application. This is the correct approach, and Microsoft has even automated the creation of these resource files within their Integrated Development Environment (IDE).

Each form in your application comes with a property called Localizable. You must first set this property to true. This indicates that the form can support languages other than the system default. Let's take the Login.cs form as an example. As you need to design a Japanese version of the form, you will need to set its Localizable property to true. Next, change the current language of the form by setting the Language property to Japanese(Japan).

Once you have done this, Visual Studio will generate a new resource file under the Login form. The name of this resource file indicates ja-JP (short for Japanese (Japan)). You can now make changes directly on your form. Change all the captions to display Japanese. (You can either use an IME to type Japanese characters, or you could simply grab some dummy Japanese text off the Internet). You can even change the entire logo on the login page to a different one.

When you make these changes, you're probably wondering if you are overwriting the English version of your form. Don't worry, because it's still there. The Language property of the form allows you to switch back and forth between different language versions of the same form. To switch back to the English version of the form, you can just set the Language property back to Default. And to switch back to the Japanese version of the form, set the Language property back to Japanese(Japan). The following screenshot shows the extra resource file generated in Visual Studio when you set the Language and Localizable properties.

Similarly, you can create as many language versions of the form as you wish. Each new language you set will generate a new resource file. For example, the following screenshot shows that there are English (default), German, French, and Japanese versions of the Login form.

If you were to open any of the resource files in Visual Studio, you can see that Visual Studio has neatly organized the culture-specific captions, images, and messages in the resource file. These files are maintained by Visual Studio—you would almost never need to directly edit these files by hand.

CRMLive.SalesForce - Microsoft Visual Studio (Administrator) File Edit View Project Build Debug Data Tools Test Window Help

; m sift E? m - Ö 9 I A -J -j | it I ! 1 I *> T P TI ► □ JJ 3

H] FullTextSearchSumm; :§] Login,vb

Log i n. Design er. vb Login.ja-JP.resx Login.resx 0- ^ MainMenu.vb 0- PluginsSetup.vb 0- SearchAccounts.vb 5 rfr I i

Properties

Login.ja-JP.resx* Login.vb [Desicjn^Japanese (Japan]]* Start Pat iäk] Strings » _] Add Resource » J - A

H] FullTextSearchSumm; :§] Login,vb

Log i n. Design er. vb Login.ja-JP.resx Login.resx 0- ^ MainMenu.vb 0- PluginsSetup.vb 0- SearchAccounts.vb 5 rfr I i

Name Value

*

Ithi s.Text

Labell.Text

J-tf-SÜ

LabelZ.Text

ifJJ- F

IblFirstTimeMsg.Text

rnnuExrt.Text

tar

rnnuLogin.Text

Now that you've managed to create different language versions of the same form, how does the .NET Compact Framework know which version to display? The .NET Compact Framework automatically decides for you—it looks at the regional settings of the mobile device. For instance, if you were to change the regional settings of the device to the Japanese (Japan) culture, this would invoke the Japanese (Japan) version of the Login form you have created.

If you run the sales force application with the regional settings set to Japanese (Japan), you will see the following login page:

Now try changing your regional settings to English (US), you will find that the English (default) version of the Login form will be displayed instead. If you change the regional settings of the device to a language that you have not accounted for in your application, the default language version of your forms will be used.

Changing the device culture programmatically?

Take note that the .NET Compact Framework does not provide you with any facility to set the culture of a device programmatically. You can only change the device culture through the regional settings of the device.

Was this article helpful?

0 0

Post a comment