Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching Language in C#.NET has no impact to site

Tags:

c#

asp.net

I have implemented Multi Language Support into my ASP.NET C# followed by this tutorial and set english to my Default language as can be seen here:

?lang=en is Default setting

When switching to german nothing happens: switched to german has no impact

In my App_GlobalResource Folder I have to files: de.language.resx and en.language.resx

My mls.cs file (In the tutorial named BasePage.cs) contains the following code:

public class mls : System.Web.UI.Page
{
    public void setLang() {
        InitializeCulture();
    }
    protected override void InitializeCulture()
    {
        if (!string.IsNullOrEmpty(Request["lang"]))
        {
            Session["lang"] = Request["lang"];
        }
        string lang = Convert.ToString(Session["lang"]);
        string culture = string.Empty;
         // In case, if you want to set vietnamese as default language, then removing this comment
        if (lang.ToLower().CompareTo("en") == 0 || string.IsNullOrEmpty(culture))
        {
            culture = "en-US";
        }
        if (lang.ToLower().CompareTo("en") == 0 || string.IsNullOrEmpty(culture))
        {
            culture = "en-US";
        }
        if (lang.ToLower().CompareTo("de") == 0)
        {
            culture = "de-AT";
        }
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

        base.InitializeCulture();
    }
}

And here is my Login.aspx page:

public partial class WebForm3 : mls 
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!string.IsNullOrEmpty(Convert.ToString(Session["lang"])))
        {
            if (Convert.ToString(Session["lang"]) == "en")
            {
                lbl_Debug.Text = "lang=en";
                Session["lang"] = null;
                Session["lang"] = "en";
            }
            else if(Convert.ToString(Session["lang"]) == "de")
            {
                lbl_Debug.Text = "lang=de";
                Session["lang"] = null;
                Session["lang"] = "de";
            }
        }
        else
        {
            lbl_Debug.Text = "nothing";
        }

    }
}

Here is my aspx code:

<asp:Content ID="Content2" ContentPlaceHolderID="ph_RowMain" runat="server">
<div class="login-box">
    <div class="login-logo">
        <a href="Start.aspx"><b>
            <asp:Literal ID="lt_adminInterfaceHeader" runat="server" Text="<%$Resources:en.language, lt_adminHeader%>"></asp:Literal></b></a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">
            <asp:Literal ID="lt_adminInterfaceBox" runat="server" Text="<%$Resources:en.language, lt_adminBox%>"></asp:Literal>
        </p>

        <div class="form-group has-feedback">
            <asp:TextBox ID="tb_email" runat="server" type="email" class="form-control" placeholder="<%$Resources:en.language,tb_email%>"></asp:TextBox>
            <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <asp:TextBox ID="tb_password" runat="server" type="password" class="form-control" placeholder="<%$Resources:en.language, tb_password%>"></asp:TextBox>
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <asp:Button ID="btn_signIn" runat="server" Text="<%$Resources:en.language, btn_signIn%>" type="submit" class="btn btn-primary btn-block btn-flat" />
            </div>
            <!-- /.col -->
        </div>
    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

Hope somebody can help.

like image 704
Hack4Life Avatar asked Oct 30 '22 23:10

Hack4Life


1 Answers

You have the name of the files wrong. you have de.lanuage.rex but, according to the article you referred, it requires format anyname.language.de.resx.

like image 72
brainless coder Avatar answered Nov 15 '22 03:11

brainless coder