locked
which is the best way to create multi-language page? RRS feed

  • Question

  • User-1933799866 posted

    Hello,

    I'm creating a multi-language website, in starting i will use three languages English, Hindi & French.

    well i want to know that, do i use "Globalization" or i create a MasterPage & share it in all three language page...???

    becuz im using CSS, and English words & other language words length is very differnt....... im thinking, by use Globalization, it will not effect on the Webpage layout....

    so what will i use Globalization or Masterpage share pages in three languages??

    Thursday, February 3, 2011 2:32 AM

Answers

  • User-1561814533 posted

    If you don't want to base the language on the browser settings you could use, say, buttons on an 'options' page in the application to select the langauge, then you could store this in a cookie so the user always gets the language they selected when they returned to the site. 

    Based on the setting the user chooses you load text from the relevant resource files at run time.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 3, 2011 8:11 AM
  • User705563967 posted

    You can create one dropdown list here user can choose the language when he select the language save the culture in session variable and according to this variable on each page you write this code

    protected override void OnPreInit(EventArgs e)
            {
                try
                {
                    //string culture = System.Globalization.CultureInfo.CurrentCulture.Parent.DisplayName;
    
                    if (HttpContext.Current.Session["CustCulture"] == null) // Set the default culture of the page
                    {
                        HttpContext.Current.Session["MasterPage"] = "~/DMS_en.Master";
                        //HttpContext.Current.Session["PageTheme"] = "Ice";
                        HttpContext.Current.Session["CustCulture"] = "en-us";
    
    
                    }
                    if (HttpContext.Current.Session["CustCulture"] != null)
                    {
                        Page.Culture = HttpContext.Current.Session["CustCulture"].ToString();
                        Page.UICulture = HttpContext.Current.Session["CustCulture"].ToString();
                    }
                    Page.MasterPageFile = HttpContext.Current.Session["MasterPage"].ToString();
                     Page.Theme = HttpContext.Current.Session["PageTheme"].ToString();
    
                }
                catch (Exception ex)
                {
                    if (ExceptionPolicy.HandleException(ex, "General"))
                        throw;
                }
            }
    


     Write this code on behid dropdownlist index change event

    if (Convert.ToString(Request.QueryString["CultureName"]) == "English")
                            {
                                HttpContext.Current.Session["MasterPage"] = "~/DMS_en.Master";
                                HttpContext.Current.Session["PageTheme"] = "Ice";
                                HttpContext.Current.Session["CustCulture"] = "en-us";
                                //Response.Write( Request.UrlReferrer.PathAndQuery);
                                Response.Redirect( Request.UrlReferrer.PathAndQuery, false);                            
                            }
                            else
                            {
                                HttpContext.Current.Session["MasterPage"] = "~/DMS_Ar.Master";
                                HttpContext.Current.Session["PageTheme"] = "Ice-ar";
                                HttpContext.Current.Session["CustCulture"] = "ar-KW";
                                //Response.Write("~" + Request.UrlReferrer.PathAndQuery);
                                Response.Redirect( Request.UrlReferrer.PathAndQuery, false);                            
                            }
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 10, 2011 12:10 AM

All replies

  • User877341716 posted

    Hi,

    Globalization is the best way to go. Also I would suggest you use Satellite Assemblies so that your code is shipped as dll and is tamper-proof. 

    Thursday, February 3, 2011 3:01 AM
  • User1002811380 posted

    Hey Anish 

    The best and recommended way is use the globalization.  

    Thursday, February 3, 2011 3:18 AM
  • User-1933799866 posted

    okk, are we can switch languages...through this?? for eg. if i create buttons of languages to switch the page....it is possible?

    Thursday, February 3, 2011 7:38 AM
  • User-1561814533 posted

    Yes that is possible or you could switch languages depending on the language the user has selected in their browser options. Have a search for articles on Globalisation, Localisation and using Resource Files in asp.net.

     

    Thursday, February 3, 2011 7:56 AM
  • User-1933799866 posted

    what about, if i swch language without touching my browser settings...??

    Thursday, February 3, 2011 8:03 AM
  • User-1561814533 posted

    If you don't want to base the language on the browser settings you could use, say, buttons on an 'options' page in the application to select the langauge, then you could store this in a cookie so the user always gets the language they selected when they returned to the site. 

    Based on the setting the user chooses you load text from the relevant resource files at run time.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 3, 2011 8:11 AM
  • User705563967 posted

    You can create one dropdown list here user can choose the language when he select the language save the culture in session variable and according to this variable on each page you write this code

    protected override void OnPreInit(EventArgs e)
            {
                try
                {
                    //string culture = System.Globalization.CultureInfo.CurrentCulture.Parent.DisplayName;
    
                    if (HttpContext.Current.Session["CustCulture"] == null) // Set the default culture of the page
                    {
                        HttpContext.Current.Session["MasterPage"] = "~/DMS_en.Master";
                        //HttpContext.Current.Session["PageTheme"] = "Ice";
                        HttpContext.Current.Session["CustCulture"] = "en-us";
    
    
                    }
                    if (HttpContext.Current.Session["CustCulture"] != null)
                    {
                        Page.Culture = HttpContext.Current.Session["CustCulture"].ToString();
                        Page.UICulture = HttpContext.Current.Session["CustCulture"].ToString();
                    }
                    Page.MasterPageFile = HttpContext.Current.Session["MasterPage"].ToString();
                     Page.Theme = HttpContext.Current.Session["PageTheme"].ToString();
    
                }
                catch (Exception ex)
                {
                    if (ExceptionPolicy.HandleException(ex, "General"))
                        throw;
                }
            }
    


     Write this code on behid dropdownlist index change event

    if (Convert.ToString(Request.QueryString["CultureName"]) == "English")
                            {
                                HttpContext.Current.Session["MasterPage"] = "~/DMS_en.Master";
                                HttpContext.Current.Session["PageTheme"] = "Ice";
                                HttpContext.Current.Session["CustCulture"] = "en-us";
                                //Response.Write( Request.UrlReferrer.PathAndQuery);
                                Response.Redirect( Request.UrlReferrer.PathAndQuery, false);                            
                            }
                            else
                            {
                                HttpContext.Current.Session["MasterPage"] = "~/DMS_Ar.Master";
                                HttpContext.Current.Session["PageTheme"] = "Ice-ar";
                                HttpContext.Current.Session["CustCulture"] = "ar-KW";
                                //Response.Write("~" + Request.UrlReferrer.PathAndQuery);
                                Response.Redirect( Request.UrlReferrer.PathAndQuery, false);                            
                            }
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 10, 2011 12:10 AM
  • User-519136805 posted

    Read this articles for some understanding of it..

    so that idea will be clear in your mind ..

    • http://www.codeproject.com/KB/aspnet/localization_websites.aspx
    • http://www.codeproject.com/KB/aspnet/LocalizedSamplePart2.aspx


    Hope this will help !!!

    Saturday, February 12, 2011 1:47 AM