如何在链接按钮单击的同时更改本地化,同时CSS文件将被更改 [英] How to change localtionzation on link button click at the same time CSS file will be change
本文介绍了如何在链接按钮单击的同时更改本地化,同时CSS文件将被更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for css: -
for css :-
style_components.Href = "assets/demos/default/css/components-ar.css";
style_bootstrap.Href = "assets/plugins/bootstrap/css/bootstrap-ar.min.css";
style_main.Href = "css/main-ar.css";
语言变更
For language change
if (SessionContext.Language == "ar-SA")
{
SessionContext.Language = "en-US";
}
else
{
SessionContext.Language = "ar-SA";
}
public void ChangeCulture()
{
//retrieve culture information from session
string culture = SessionContext.Language;
//check whether a culture is stored in the session
if (string.IsNullOrEmpty(culture) == false && culture.Length > 0)
{
Culture = culture;
//set culture to current thread
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
if (culture == "ar-SA")
Thread.CurrentThread.CurrentCulture.DateTimeFormat.Calendar = new HijriCalendar();
else
Thread.CurrentThread.CurrentCulture.DateTimeFormat.Calendar = new GregorianCalendar();
}
else //call base class
base.InitializeCulture();
}
我尝试过:
What I have tried:
for css :-
<pre>style_components.Href = "assets/demos/default/css/components-ar.css";
style_bootstrap.Href = "assets/plugins/bootstrap/css/bootstrap-ar.min.css";
style_main.Href = "css/main-ar.css";
语言变更
For language change
if (SessionContext.Language == "ar-SA")
{
SessionContext.Language = "en-US";
}
else
{
SessionContext.Language = "ar-SA";
}
public void ChangeCulture()
{
//retrieve culture information from session
string culture = SessionContext.Language;
//check whether a culture is stored in the session
if (string.IsNullOrEmpty(culture) == false && culture.Length > 0)
{
Culture = culture;
//set culture to current thread
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
if (culture == "ar-SA")
Thread.CurrentThread.CurrentCulture.DateTimeFormat.Calendar = new HijriCalendar();
else
Thread.CurrentThread.CurrentCulture.DateTimeFormat.Calendar = new GregorianCalendar();
}
else //call base class
base.InitializeCulture();
}
推荐答案
您需要的一种方法是需要维护2个不同的css文件,一个用于英语,另一个用于阿拉伯语,在if条件下用于切换动态设置相应css文件所需的语言。
添加如下链接标签
Hi,
One method for your requirement is that you need to maintain 2 different css files , one for English and another for Arabic and inside your if condition for switching the language you need to dynamically set the corresponding css file.
Add a link tag like this
<head runat="server">
<title>CSS Test</title>
<link id="lnkStyle" runat="server" rel="stylesheet" type="text/css" />
</head>
然后修改你的语言切换逻辑如下
and then modify you language switching logic as below
if (SessionContext.Language == "ar-SA")
{
SessionContext.Language = "en-US";
lnkStyle.Attributes["href"] = "~/CSS/Style-eng.css";
}
else
{
SessionContext.Language = "ar-SA";
lnkStyle.Attributes["href"] = "~/CSS/Style-ar.css";
}
这篇关于如何在链接按钮单击的同时更改本地化,同时CSS文件将被更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文