Localization Sample

The FlexGridLocalization sample shows how you can localize the FlexGrid filter to different languages.

The ComponentOne Studio for Silverlight product ships with satellite .dlls that provide control localization to several languages. In addition to English, the ComponentOne controls support Arabic, Danish, German, Spanish, Finnish, French, Hebrew, Italian, Japanese, Dutch, Norwegian, Portuguese, Russian, and Swedish.

This sample shows how you can configure your Silverlight application to use the strings in any of these languages or to define your own in case the language you want to use is not on the above list or in case you want to customize the strings.

To localize your Silverlight application, follow these steps:

1.   Choose the language(s) you want to support and find the corresponding two-letter CultureInfo code. For example, German is "de", Spanish is "es", and French is "fr".

2.   Edit your project file and add all the two-letter codes to the "SupportedCultures" section of the file. For example, this sample's project file (FlexGridLocalization.csproj) contains the following line:

<pre>

    <SupportedCultures>de,es,fr,it,tr</SupportedCultures>

</pre>

This line instructs Visual Studio to add to the application's "xap" file the satellite .dlls that contain resources for German, Spanish, French, Italian, and Turkish.

3.   If your list includes any languages not on the above list, then you have to create those satellite .dlls yourself. In our example, we specified that the Turkish language will be supported, so we have to add those resources. To do this, follow these steps:

      Add a new folder called "Resources" to your application.

      Add a new item to the of type "Resources File" to the Resources folder.

      Name the new file C1.Silverlight.FlexGridFilter.tr.resx. Notice that the name of the file specifies the item that will be localized and also the language that it will contain.

      Double-click the new file and enter the names and values for all the resources. This sample contains the names of the resources used by the FlexGridFilter. Since I don't speak Turkish, I edited the file content so all content strings have a "tr" prefix.

4.   Rebuild the application and check that the "xap" file contains all the resources you specified. You can do this by copying the "xap" file with a "zip" extension and checking that the file contains folders with the two-letter codes for the cultures specified.

5.   At this point, the application contains all the resources required, and the only item left is for you to specify the language that you want to use. This can be done in the Application_Startup method (in the App.xaml.cs file) or on the page itself. This sample specifies the culture to use in the MainPage.xaml.cs file:

<code>

    public MainPage()

    {

        // select the culture (de, it, fr, tr are supported)

        var ci = new System.Globalization.CultureInfo("tr-TR"); // de-DE etc.

 

        // this controls the UI strings

        System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

 

        // this controls number and date formatting (optional in this sample)

        //System.Threading.Thread.CurrentThread.CurrentCulture = ci;

 

        // initialize the component

        InitializeComponent();

    }

</code>


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.