Switching a language in C # .NET does not affect the site

I implemented Multi Language support in my ASP.NET C # and then 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 files: de.language.resx and en.language.resx

My mls.cs file (in a guide called 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 someone can help.

+5
source share
2 answers

Your file name is incorrect. you have de.lanuage.rex , but according to your article, this requires anyname.language.de.resx format.

+2
source

When you try to localize your site, the resource file name is too many. your resource file name must match the following format
FileNameYouWant.language-culture.resx

if you do not specify the language culture, if your file name looks like this FileNameyouWant.resx , then the default language will be English (language-culture = 'en').

example: resource file name in German = file_nameYouWant.de.resx
French Resource File Name = FileNameYouWant.fr.resx

0
source

All Articles