我正在 Asp.Net 中创建多语言(En 和 Ar)网站。我想知道如何将 RTL CSS 链接到将文化从英语切换到阿拉伯语。我已经成功创建了只停留在链接 CSS 的多语言网站。我知道如何在 MVC 中使用包,但不确定一个简单的 ASP.Net 应用程序。以下是我的代码:
public class BasePage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
if (!string.IsNullOrEmpty(Request["lang"]))
{
Session["lang"] = Request["lang"];
}
string lang = Convert.ToString(Session["lang"]);
string culture = string.Empty;
if (lang.ToLower().CompareTo("en") == 0 || string.IsNullOrEmpty(culture))
{
culture = "en-US";
}
if (lang.ToLower().CompareTo("ar") == 0)
{
culture = "ar-SA";
}
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
base.InitializeCulture();
}
}
页面:
<head runat="server">
<link href="RTL.css" rel="stylesheet" />
<!-- AR, Use this CSS if culture is Arabic -->
<link href="LTR.css" rel="stylesheet" />
<!-- EN, Use this CSS if culture is English-->
</head>
<body>
<a href="?lang=en" runat="server" id="enLang">
<asp:Literal ID="Literal1" runat="server" Text="<%$Resources:myWeb.language, langEnglish%>" /></a>
<a href="?lang=ar" runat="server" id="arLang">
<asp:Literal ID="Literal2" runat="server" Text="<%$Resources:myWeb.language, langArabic%>" /></a>
</body>