我已經實現了多語言支持了我的ASP.NET C#,然後this教程,並設置英語我的默認語言沒有影響,因爲在這裏可以看到:切換語言已經到了現場
3210
當切換到德國沒有任何反應:
在我App_GlobalResource文件夾我有文件: de.language.resx
和en.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 -->
希望有人可以提供幫助。
你能展現ASPX標記? –
@brainlesscoder發佈更新 – Hack4Life
我認爲你的文件名稱錯誤。你有'de.lanuage.rex',但根據文章,它需要格式'anyname.language.de.resx' –