locked
Localization and globalization RRS feed

  • Question

  • User1664382952 posted

    Hello all,
    I made this project and I had a problem I do not know where it is..
    The project has already asked for help here in this site
    But the problem now is that the  return value of the web.config
    Gives null
    ... I mean that the value of ddlLanguage still null when I debug the program
    but the value of the appsetting appears in the ddlLanguage
    but when I asked to used it through my work gave me that is null ...
    what is the expected problem here ?

    this is the master page
    Site.Master.cs :
     public partial class Site : System.Web.UI.MasterPage
        {

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string ddlstr = ConfigurationManager.AppSettings["Language"];
                    var list = ddlstr.Split(',');
                    for (int i = 0; i < list.Count(); i++)
                    {
                        var list01 = list[i].Split(':');
                        ListItem item = new ListItem(list01[1], list01[0]);
                        this.ddlLanguage.Items.Add(item);
                    }
                    this.ddlLanguage.SelectedValue = "en-US";
                    
                }
            }

            protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
            {
                HttpCookie cookie = new HttpCookie("language", ddlLanguage.SelectedValue);
                Response.Cookies.Add(cookie);

            }
           
        }

    this is the LoginPage.aspx which used Master Page :
     public partial class LoginPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
         
            }
            protected override void InitializeCulture()
            {
                if(Request.Form["ddlLanguage"]!=null)
                {
                    String selectedLanguage = Request.Form["ddlLanguage"];
                    UICulture = selectedLanguage;
                    Culture = selectedLanguage;
                    Thread.CurrentThread.CurrentCulture =
                        CultureInfo.CreateSpecificCulture(selectedLanguage);
                    Thread.CurrentThread.CurrentUICulture = new
                        CultureInfo(selectedLanguage);
                }
                base.InitializeCulture();
            }
        }
    }

    ( I have Resources File for arabic,English and Espanish )
    and I did this in web.config
      <appSettings>
        <add key="Language" value="ar:Arabic,en-US:English,es:espanish"/>
      </appSettings>


    Please help me....
    thank you ....

    Thursday, May 28, 2015 8:09 AM

Answers

  • User-1622469483 posted

    Hello Hanady,

    Just use your cookie from ddlLanguage_SelectedIndexChanged.

    The following is the code to replace in LogInPage.

    protected override void InitializeCulture()
            {
                string lan = Request.Cookies["language"].Value;
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lan);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lan);
                base.InitializeCulture();
            }

    The following is the items of ddlLanguage in site.Master.

       <asp:DropDownList ID="ddlLanguage" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlLanguage_SelectedIndexChanged">
                                  <asp:ListItem Value="en-US">English</asp:ListItem>
                                  <asp:ListItem Value="th-TH">Thailand</asp:ListItem>
                                  <asp:ListItem Value="fr-FR">Franch</asp:ListItem>
                              </asp:DropDownList>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2015 7:30 AM

All replies

  • User-1622469483 posted

    Hello Hanady,

    Just use your cookie from ddlLanguage_SelectedIndexChanged.

    The following is the code to replace in LogInPage.

    protected override void InitializeCulture()
            {
                string lan = Request.Cookies["language"].Value;
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lan);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lan);
                base.InitializeCulture();
            }

    The following is the items of ddlLanguage in site.Master.

       <asp:DropDownList ID="ddlLanguage" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlLanguage_SelectedIndexChanged">
                                  <asp:ListItem Value="en-US">English</asp:ListItem>
                                  <asp:ListItem Value="th-TH">Thailand</asp:ListItem>
                                  <asp:ListItem Value="fr-FR">Franch</asp:ListItem>
                              </asp:DropDownList>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2015 7:30 AM
  • User1664382952 posted

    Thank u Nyi Nyi .
    Truely your answer is correct ..and I did that befor and successed
    thanks alot ^_^

    Sunday, June 7, 2015 3:04 AM
  • User-1622469483 posted

    You are welcome ! Hanady.Best,

    Nyi Nyi Aung

    Sunday, June 7, 2015 3:21 AM