gpt4 book ai didi

c# - 在 C#.NET 中切换语言对站点没有影响

转载 作者:太空狗 更新时间:2023-10-29 23:38:04 26 4
gpt4 key购买 nike

我已经在我的 ASP.NET C# 中实现了多语言支持,然后是 this教程并将英语设置为我的默认语言,如下所示:

?lang=en is Default setting

切换到德语时没有任何反应: switched to german has no impact

在我的 App_GlobalResource 文件夹中,我必须归档:de.language.resxen.language.resx

我的 mls.cs 文件(在名为 BasePage.cs 的教程中)包含以下代码:

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();
}
}

这是我的 Login.aspx 页面:

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";
}

}
}

这是我的 aspx 代码:

<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 -->

希望有人能帮忙。

最佳答案

您的文件名有误。你有 de.lanuage.rex 但是,根据你提到的文章,它需要格式 anyname.language.de.resx

关于c# - 在 C#.NET 中切换语言对站点没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com