I am creating multi-language (En and Ar) website in Asp.Net. I am wondering how can I link RTL CSS on switching culture from English to Arabic. I have successfully created the multi-language website just stuck in linking CSS. I know how to do in MVC using bundles, but not sure about a simple ASP.Net application. Following is my code:
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();
}
}
Aspx Page:
<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>
Try this:
<% if (System.Globalization.CultureInfo.CurrentCulture.DisplayName == "English (United States)")
{ %>
<link href="LTR.css" rel="stylesheet" />
<% }
else
{ %>
<link href="RTL.css" rel="stylesheet" />
<% } %>