If a website wants to pull a large number visitors then it is important to provide more localized content. This means that the site should show up in the local language of the visitors accessing the webite. For exam¬pie if a non-English reader wants to access your website and your website is not localized in his/her language, then you might end up losing that visitor.

But if your website is local¬ized, you might be able to retain that visitor. With the help of Web developer 2008 ASPNET AJAX, you can build such websites in minutes. But the only issue is that you should have a translator who knows and can translate dif¬ferent languages.

Earlier, developers used to develop such website, ie, localized websites with the help of ASP.NET. So what's different in using Web developer 2008 ASP.NET AJAX? Well the difference lies in the term AJAX. Earlier whole page had to be ren¬dered from the server and then the re¬quired language was shown to the user. And if the user asks for any other re¬sponse from the server then also the whole page had to be refreshed, The tech¬nique behind this is that there is a global resource residing on the server which consists of some keywords that do not change in any case, ie the name doesn't depend on the language setting of the user.

And there is local resource on the server which contains all the substitutes for the words that will be changed accord¬ing the language displayed. Now using the AJAX the resource gets downloaded on the client itself and whenever the user de¬mands for any language change then immediately the language is change after he/she presses re¬fresh button. But this time the text or labels are not rendered from the server but the local resource that is downloaded at the client side is used.
Now let us make a simple ASP.NET web site in which we will be implementing the localization option. For this open the web developer 2008 and create a new project named as 'websitelocal¬izaiton', Now go to 'Website' menu and click on 'Add new item', select the template as resource file, provide the resource file name as 'global' and then click on 'Add'.

Then it may ask you to place the resource file in the 'App_ GlobalResources' folder, ideally it should be done, hence click on 'Yes'. Once you have added the resource file you will see a screen similar to that of Access data table. Under the name field write 'Heading' and under the value field write'THIS ISA TEST WEBSITE', It can be understood as the 'Name' field which is the variable and the 'Value' field is the value associated with the Name. Now save the resource file and close it. Similarly add a new resource file and name it as 'de¬fault.aspx.resx' where we will keep Eng¬lish words and add another named default.aspx.fr.resx where we will keep some words of French language(for ex¬ample). Add some name and value associ¬ated with the 'Name' field, as shown in the image. Add local resource folder to your website, by clicking on 'App _Local Resources' option from web¬site> Add ASP.NET folder and move the default.aspx.resx and de¬fault.aspx.fr.resx to 'App_LocaIResources' folder. Now write the following code on to your website and then build the solution.

<%@ Page Language="VB" AutoEven¬tWireup="true" Code-
File=" Default.aspx. vb"
In herits="_Default" UICulture=" auto"
<title>Website to demonstrate Local¬ization</title>
</head>
<body>
<form id="forml" runat="server"> <div>
<br />
<asp:Label ID="Label" runat="server" Text="Default Label Text" meta:resourcekey="Label" />
</div>

Name:  Localize your Website.jpg
Views: 308
Size:  20.8 KB

</form> </body> </html>
To change your Web browser lan¬guage setting to French, for instance, go to Tools> Internet option and then click on 'Language button'. Click on Add but¬ton, select'fr' from the list and click on Ok. Now select the 'fr' from the list box and click on move up button and then click on Ok twice. View this website in the browser, the 2nd label will be 'This is x Language' and when you change the pri¬ority of language to English then the label will be'This is English'. How let's include AJAX in the picture. Below is a simple ex¬ample which displays date in localized format. We have a script manager in¬cluded and we have set the'Enablescript-Glooalization' attribute to true. Then we have an update panel which consists of a button and label. So whenever the button is clicked then current date and time is displayed in the label. Copy the following code inside the body tag.
<asp:Scri ptMa nager ID="ScriptManagerl" runat="server" En¬ableScriptGlobalization="true" />
<asp:UpdatePanel ID="UpdatePanell" runat="server" ChildrenAsTrig¬gers="False" Update¬Mode="Conditional">
<ContentTemplate> <asp:Panel ID="Panell"
<asp:Button ID-"Button" runat-"server" Text="Click Here" /> <br />
<asp:Label ID-"Label" ru nat-" server" ></ as p: La be l> </asp:Panel> </ContentTemplate> </asp:UpdatePanel>
Next we created an event handler, ie whenever the button is clicked a function named 'localizedate' is called. Each time the function is called, a new instance of
date object is created and is then for¬mated according to the local formate. Copy the following code in the head tag of your web page.
<script type="text/javascript">
Sys. U I. Do m Event. add Ha nd ler( $get(" B ut ton "), "click", localizedate);
function localizedateO {
var d = new DateO; $get('Label').innerHTML = d.localeFormat("dddd, dd MMMM yyyy HH:mm:ss");
}
The 'locale Format' method is intro¬duced with the new AJAX extension in¬side the date object. This helps in reading the current language setting of the browser and then formatting the date and time according to it. Open up this in your web browser and click on the button, it shows the date in English without refreshing the web page. Now change the language setting in your web browser and then refresh the page. Next click on the button and it shows you the date and time in French, and that too without re-
freshing the whole page.