Creating a Multi-Lingual Application

Iron Speed Designer applications support multiple language translation files (RESX).  If you selected this option in the Application Wizard, you must still provide a means for your application users to select which language (culture) they wish to use at run-time.

Iron Speed Designer provides a variety of mechanisms for setting the application culture.  Before describing them, it is useful to understand how your application culture is set in your application.

How your application sets the culture

The application’s BasePage class sets application culture based on session variables and URL parameters.  Either can be used depending on your programming requirements and style.

Function

Session Parameter

URL Parameter

Set the UI culture of the application

AppCultureUI

culutreui

Set the application formatting

AppCulture

culture

The values assigned to these parameters must be valid culture names, such as “en-US”, “en-UK”.  A list of culture names is available at this Microsoft website:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csvr2002/htm/cs_rp_catalogmanager_list_c.asp

The BasePage class sets the application culture for the application thread by setting these variables:

System.Threading.Thread.CurrentThread.CurrentUICulture

System.Threading.Thread.CurrentThread.CurrentCulture

The GetValueFromResourceFile method in the MiscUtils class of the BaseClasses reads the specific language resource file (RESX) based on value of System.Threading.Thread.CurrentThread.CurrentUICulture.

The SetPageCulture method in the BasePage class sets the cultures of the thread and is called in the Page_Init method of the BasePage class.  This method can be overridden to implement a custom method of setting user culture.

Once the culture is set, it is applicable for the duration of the session.  Note that the culture is set per application thread, so if a user has two separate browser windows, they could potentially have different cultures set.

If the user chooses a culture for which there is no language translation, then the default (English) translation is added and you must provide the language translation yourself.  The default culture is always added to the application, and even if you remove it via the Application Wizard, it will be added to the application.

Both the Upper Tool Bar and the code customization read the names of available cultures from the “App_GlobalResources” folder.

Using the Upper Tool Bar to set Application Culture

Your application displays the languages you have chosen to include in a dropdown list box in the Upper Tool Bar.  Application users can choose which language they want, and your application will set the application language accordingly.  After selecting a language, your application automatically stores the last selected language in cookie so that next time you open application it will be set to this language.

The language dropdown list is located in Header.ascx.cs (.vb) and has a Text property configured according to the English name of the language, e.g., “German”, “Spanish”, etc.  At run-time, your application attempts to retrieve the localized language name from the resource file (RESX) using the key:

Txt:<English Language Name>               (i.e. Txt:French, Txt:German, etc.)

If the resource value is present, it is used in the dropdown list in the Upper Tool Bar, allowing your application to show language-specific names, e.g., “Deutsch”, “Espanol”, etc.

Please note that selecting a language will not change your application’s culture.  The application’s culture determines the currency symbol used, which cannot change because database values are presumed to be in a fixed currency.  Moreover, since the culture does not change, the application will continue to format dates as specified in the default culture.

Using URL Parameters to set Application Culture

You can also use the URL parameter to add a “Language” hyperlink to the page and set the link to redirect back to the same page with the URL parameters “culutreui” and “culture” set.  Use the Property Sheet to set the redirection.

 

Here, the Redirect URL properties have been set for the three hyperlinks as follows:

Language

Redirect URL

English

ShowCategoriesTable.aspx?cultureui=EN-US

German

ShowCategoriesTable.aspx?cultureui=de-DE

Italian

ShowCategoriesTable.aspx?cultureui=it-IT

The browser in the above image shows how the culture was set to German by clicking on the German link.

Using a Code Customization to set Application Culture

There is a code customization that adds a drop down list to any page to set the user’s culture called “Add Dropdown List To Choose Language Of Application” in the “Multi-lingual Application” section of the Code Customization Wizard.

Reading Browser Language Settings to set Application Culture

The GetBrowserLanguages method in the BasePage class returns all the languages set for the client-side web browser.  Override the SetPageCulture method in your page and call GetBrowserLanguages to retrieve the browser languages.  Then, set the values of:

System.Threading.Thread.CurrentThread.CurrentUICulture

System.Threading.Thread.CurrentThread.CurrentCulture

using the first value in list of browser languages.  GetBrowserLanguages returns languages in the order in which they are set in the browser.

The disadvantage of this approach is that application users in an uncontrolled environment like a web café may have web browsers set to languages not of their choosing, and there may be no way for the user to set the application culture of their choice.

Reading the User Language Preference from Database to set Application Culture

This method can be used with the Sign-In page.   During sign–in, the user’s language preference can be read from the database, and both the “AppCultureUI” and “AppCulture” session variables can be set or the thread cultures could be set directly.  In this case, the code customization “Store Extra Information at Sign-In Time” can be used to set these values.

Custom Coding Approaches for Setting Application Culture

You may implement custom approaches to choose the language preference and then override the SetPageCulture function in your page to set the culture by setting values for:

System.Threading.Thread.CurrentThread.CurrentUICulture

System.Threading.Thread.CurrentThread.CurrentCulture

This override needs to be in just one page of your application (default page recommended) and it will be set for the application thread.

See Also

Localizing (Internationalizing) Your Application

Resource File Format

Editing Resource Files

Enabling Language Support in Microsoft Windows

Customizing Error and Validation Message Strings