Saturday, September 5, 2009

Monday, August 31, 2009

Building multilingual Web application

The following example demonstrates the localization of a Label control in a page called LabelLocalization.aspx.

%@ Page UICulture="auto" Culture="auto" %>
form runat="server">
asp:Label ID="Label1" runat="server" Text="<%$ Resources:Label1TextKey %>"
Font-Name="<%$ Resources:Label1FontNameKey %>"/>
/form>

*******
The page above using implicit expressions is still not completely translated - the currency names in the drop down and the exchange value list are still in English. Also the page is not yet translated to Arabic, and the German version should get a different background color for the title and date labels.

Arabic is a language that is written from right to left. To instruct the browser to display the page in the correct directionality, an additional resource called HTMLDirectionality was added. Using an explicit expression to this local resource, the dir attribute of the html element of the page is set.

Global Resource Files

You create a global resource file by putting it in the reserved folder App_GlobalResources at the root of the application. Any .resx file that is in the App_GlobalResources folder has global scope. Additionally, ASP.NET generates a strongly typed object that gives you a simple way to programmatically access global resources.

Implicit Localization with Local Resources

If you have created local resource files for a specific page, you can use implicit localization to fill the property values for a control from the resource file. In implicit localization, ASP.NET reads a resource file and matches resources to property values.

To use implicit localization, you must use a naming convention for resources in the local resource file that uses the following pattern:

Key.Property

asp:Button ID="Button1" runat="server" Text="DefaultText"
meta:resourcekey="Button1" />

Explicit Localization

Alternatively, you can use explicit localization, where you use a resource expression. Unlike implicit localization, you must use a resource expression for each property that you want to set.

A Button control that is configured to set the Text property from a global resource file might resemble the following:

asp:Button ID="Button1" runat="server"
Text="<%$ Resources:WebResources, Button1Caption %>" />

Windows Forms controls are the basic elements of a Windows Applications. You will find improvement in the Windows Forms right-to-left (rtl) features. In new controls, such as the TableLayoutPanel , FlowLayoutPanel  , SplitContainer , StatusStrip , ToolStrip and MaskedTextBox etc… there is support for rtl. Simply set RightToLeft =Yes and it would set the reading order, alignment and the layout of these controls. While in existing common controls, such as treeview , Listview , MonthCalendar etc... You have a new property to add the rtl layout. Simply set both  RightToLeftLayout =true and RightToLeft =yes and you get full rtl layout, there may be some limitations but the development experience is easier.


How to: Display Right-to-Left Text Using HTML Tags for Globalization

When writing ASP.NET Web pages, the best way to make text flow from right to left is to use the dir (direction) attribute. The dir attribute is usually placed in either the html or body tag, and then controls and HTML elements on the page inherit from the specified direction.

To set the dir attribute in an ASP.NET Web page

html dir="rtl">
!-- Or -->
body dir="rtl" >

table dir="ltr" >
asp:TextBox dir="ltr" >