Testing Localized Applications

Finally, you are ready to test the localized application. The most common method for localization testing requires a computer that is running a localized version of the operating system for each culture to be tested. Obviously, this can require a lot of computers, depending on the scope of distribution for the application. Another method involves installing the Multilingual User Interface (MUI) version of Windows 2000, which provides built-in support for multiple languages and allows reconfiguring a computer without installing a new operating system. Though this approach might work for some development scenarios, the MUI version of Windows 2000 is not widely distributed.

Most developers will choose to simulate a different culture by changing the currently executing thread's CurrentThread.CurrentUICulture property. Several examples were shown early on in this tutorial where command-line arguments affected which resources were loaded. The code to do this is straightforward. First, it is necessary to pass in the required culture tag, which can be done with code like the following Visual C# code from the WorldCalc.cs file.

public static void Main(string[] args) {
   string strCulture = "";
   if (args.Length == 1) {
         strCulture = args[0];
   }
   Application.Run(new VersioningDemo(strCulture));
} 

The class constructor then creates a CultureInfo using the culture tag, and assigns it to the currently executing thread, as shown in the following code.

public VersioningDemo(string culture) {
  if (culture != "") 
      try {
          Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
      }
      catch (ArgumentException e){
          MessageBox.Show(this, e.Message, "Bad command-line argument");
      }
  InitializeComponent();
}

The equivalent Visual Basic code, which is from the file WorldCalc.vb, is slightly different. Visual Basic does not allow passing parameters to Main, so it is necessary instead to use the GetCommandLineArgs method, as shown in the following code.

<System.STAThreadAttribute()> _
Public Shared Sub Main()
   Dim args() As String = System.Environment.GetCommandLineArgs()
   Dim strCulture As String = ""
   If args.Length = 2 Then
      strCulture = args(1)
   End If
   Application.Run(New VersioningDemo(strCulture))
End Sub 'Main

The following code shows that the corresponding Visual Basic class constructor New is much closer to the Visual C# equivalent.

Public Sub New(culture As String)
   If culture <> "" Then
      try 
         Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture)
      catch e as ArgumentException
         MessageBox.Show(Me, e.Message, "Bad command-line argument")
      end try
   End If 
   InitializeComponent()
End Sub 'New

This approach allows developers to test most resources for localization without going to the expense of setting up multiple computers.