locked
Asp.net Web in English and Hindi Language which can be hosted in Campus LAN (without internet connecetion) RRS feed

  • Question

  • User810354248 posted

    I was looking to make a bilingual website (English and Hindi language). But my website will be hosted in a private LAN without any internet connection. There are many samples showing with globalization and localization but does it work without internet connection.

    Please suggest a practcal solution for me.

    Thursday, April 27, 2017 1:41 AM

Answers

  • User-1509636757 posted

    As far as I know, Localization would not require Internet connection, it is based on what CultureInfo you provide; it will fetch static resources from corresponding resource files. I suggest you follow below steps:

    Reference: https://gist.github.com/kaushalparik27/8477637

    In your master page design code I assume that there is one dropdown list with some culture as:
    
    <asp:DropDownList runat="server" ID="ddlLanguage" AutoPostBack="true" OnSelectedIndexChanged="ddlLanguage_SelectedIndexChanged">
                <asp:ListItem Text="English" Value="en-US"></asp:ListItem>
                <asp:ListItem Text="India" Value="hi-IN"></asp:ListItem>
            </asp:DropDownList>
    
    be sure that the AutoPostBack property of the dropdownlist is set to true and write below code in SelectedIndexChange event:
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                ddlLanguage.Items.FindByValue(string.IsNullOrEmpty(Convert.ToString(Session["appCultureSession"])) ? "en-US" : Convert.ToString(Session["appCultureSession"])).Selected = true;
        }
        protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            string appCultureSession = string.IsNullOrEmpty(Convert.ToString(Session["appCultureSession"])) ? "en-US" : Convert.ToString(Session["appCultureSession"]);
            appCultureSession = ddlLanguage.SelectedItem.Value;
            Session["appCultureSession"] = appCultureSession;
            Response.Redirect(Request.Url.ToString(), true);
        }
    
    You can see that we are only storing the changed culture in a session and redirecting the page to same url .. no culture specific code here. Next, In default.aspx; the important part is to set the culture as:
    
    public partial class _Default : System.Web.UI.Page
    {
        protected override void InitializeCulture()
        {
            if (Session["appCultureSession"] != null)
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Convert.ToString(Session["appCultureSession"]));
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Convert.ToString(Session["appCultureSession"]));
            }
            else
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    }
    
    for testing; you can have a label in content page as:
    
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:Label runat="server" ID="lblData" meta:resourcekey="lblData"></asp:Label>
    </asp:Content>
    
    and create resx file for the culture; here I will have to define two resx files Default.aspx.resx for en-US and Default.aspx.hi-IN.resx for hi-IN culture respectively. Simply we have to define the Text of the label in resx file as: lblData.Text as "Name" and "Value" you want to give for this resource entry.
    
    This should work enough. Obviously you might be having many content pages; at this time.. it is good to create a BasePage class in App_Code that inherits System.Web.Ui.Page and write the protected override void InitializeCulture() code in that class. Later, inherit all your content pages from this BasePage class so you dont have to write protected override void InitializeCulture() in every code..
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 27, 2017 4:31 AM