Sunday, 10 March 2013

Globalization................

 Website for Multi Language Support

How to make website for multiple languages?

A website which can support Multiple Languages and change according to the culture of a specific geographical location is not a new topic. Websites to support multiple languages can be a challenging and time-consuming process. You find many artilce related on internet and well explained, But i still see that many of them are complicated for "Beginners". I tried to make this article to approach a more dynamic way to manage languages regarding Globalization/ Localization/ Culture concepts.

With standard HTML pages, you may have to create and maintain duplicate versions of each page for each supported language as well as having the language content embedded into the HTML, where content can’t easily be edited.  For those of you who have to develop multi-lingual interfaces and applications, you’ll be glad to know that ASP.NET makes things easier.
ASP.NET and the .NET framework ship with support for multilingual applications, namely in the form of Resource Files, the CultureInfo class, and the System.Globalization and System.Resources.ResourceManager namespaces.

However, we need to understand what is meant by "globalization", "localization" and "culture" in this context.
Globalization:
Globalization is a process of identifying all the parts of your application that need to be different for respective languages and separate them from the core application.

Localization:

Localization is process of creating and configuring your application for a specific language.

Cultures:

A culture is combination of the language that you speak and the geographical location you belong to. It also includes the way you represent dates, times and currencies. It's important to have a good understanding of Cultures since our new code will make use of them - specifically the System.Globalization.CultureInfo class, and the culture name value which follows the RFC 1766 naming standard. Basically, you create a new CultureInfo instance by specifying the culture name in the constructor:
CultureInfo c = new CultureInfo("en-US");

Follow the step to create website for multiple languages:
Step 1:
Create new website -> Solution Explorer -> Select sln right click and Add Asp.Net Folder - App_GlobalResources
Now under App_globalization add resources file (.resx  file), i add three resx file deafult for english, fr for french, de for german haivin key pair values;
Structure look like as in below image:
Step 2:
Add Global.asax file:
Code: write this piece of code
void Application_BeginRequest(Object sender, EventArgs e) 
{     
 // Code that runs on application startup                                                            
 HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
 if (cookie != null && cookie.Value != null) 
 {
  System.Threading.Thread.CurrentThread.CurrentUICulture =
 new System.Globalization.CultureInfo(cookie.Value);
  System.Threading.Thread.CurrentThread.CurrentCulture = 
new System.Globalization.CultureInfo(cookie.Value);
 }
 else
 {
  System.Threading.Thread.CurrentThread.CurrentUICulture =
 new System.Globalization.CultureInfo("en");
  System.Threading.Thread.CurrentThread.CurrentCulture =
 new System.Globalization.CultureInfo("en");
 }
}


Step 3:
Add masterPage having a dropdownlist control;
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
 if (!Page.IsPostBack){
  if (Session["ddindex"] != null) {
   ddlanguage.SelectedValue = Session["ddindex"].ToString();
   ddlanguage.SelectedIndex = Convert.ToInt32(Session["ddindex"].ToString());
  }
  else{
    ddlanguage.SelectedValue = Thread.CurrentThread.CurrentCulture.Name;
  }
 }
}
protected void ddlanguage_SelectedIndexChanged(object sender, EventArgs e)
{
 Session["language"] = ddlanguage.SelectedValue;
 //Sets the cookie that is to be used by Global.asax
 HttpCookie cookie = new HttpCookie("CultureInfo");
 cookie.Value = ddlanguage.SelectedValue;
 Response.Cookies.Add(cookie);
 //Set the culture and reload for immediate effect.
 //Future effects are handled by Global.asax
 Thread.CurrentThread.CurrentCulture = 
new CultureInfo(ddlanguage.SelectedValue);
 Thread.CurrentThread.CurrentUICulture = 
new CultureInfo(ddlanguage.SelectedValue);

 if (cookie.Value == "en"){
  Session["ddindex"] = 0;
 }
 else if (cookie.Value == "fr"){
    Session["ddindex"] = 1;
 }
 else if (cookie.Value == "de"){
    Session["ddindex"] = 2;
 }
 Server.Transfer(Request.Path);
}
}








Add childPage with controls and on dropdownlist selected index it will display respective language content

My sample Childpage desin code :
set text as resoures key;
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

OutPut shown in below images
1) For English



2) For French

Tuesday, 31 July 2012

SMART WAY TO HANDLING IIS-While Deploy the Website

Here i am  going to explain -- how to deploy the website in IIS smartly , Before you proceed don't  forgot to check whether the IIS is  installed in our local machine or not, Make sure that That  process is success we should have IIS

Step 1: You can open the Visual studio whatever the application we need to deploy.

Step 2: Go to solution explorer and right click and choose Build ,check having any error or not , after  that you can find the publish menu which is in solution explorer right click

stepp3:after click the publish then open a one wizard in that it will ask the location where  you saved your published websites Ex:   create a folder in anywhere in your Local  Machines give that path by using browse button beside of that textbox

Step 4: Click on Publish The Website will Published on the target folder

Step 5: Right Click On the Website was published in the target folder and copy the path of a folder  and paste the path inside the wwwroot folder that is C:\inetbub/wwwroot

Step 6:Now Open the ISS such click Start->run->type    inetmgr  click open IIS will open right now.

Step 7: Open the local computer in that open the  websites  after that open the Default Website  in that you will find our website because you have already placed our published website in to WWWROOT folder.WWWROOT folder is the default path for IIS if we place any websites into wwwroot folder it will automatically displays under DEFAULT WEBSITE

Step 8: Click on the your website right side it will display all of your published pages select whatever the page first you need to run right click on that and click browse it will display your published website.


Step 9: At that time if you get any error please right click on website in Default Website goes to PROPERTIES and click on CREATE BUTTON and click OK  button. Now browse your default page.
                           
                                          Thank you!