背景
- 我正在构建一个多语言系统
- 我正在使用 MVC 4 bundle 功能
- 我有从右到左 (RTL) 和从左到右 (LTR) 语言的不同
Javascripts
和Styles
文件
目前我处理这种情况如下:
bundle 配置文件
//Styles for LTR
bundles.Add(new StyleBundle("~/Content/bootstarp").Include(
"~/Content/bootstrap.css",
"~/Content/CustomStyles.css"));
// Styles for RTL
bundles.Add(new StyleBundle("~/Content/bootstrapRTL").Include(
"~/Content/bootstrap-rtl.css",
"~/Content/CustomStyles.css"));
//Scripts for LTR
bundles.Add(new ScriptBundle("~/scripts/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/CmsCommon.js"
));
//Scripts for RTL
bundles.Add(new ScriptBundle("~/scripts/bootstrapRTL").Include(
"~/Scripts/bootstrap-rtl.js",
"~/Scripts/CmsCommon.js"
));
View 中的实现:
@if (this.Culture == "he-IL")
{
@Styles.Render("~/Content/bootstrapRTL")
}
else
{
@Styles.Render("~/Content/bootstrap")
}
问题:
我想知道是否有更好的方法来实现它,我希望:
处理检测哪种文化的逻辑,并将正确的文件拉到包中(代码隐藏)而不是 View 中。
所以在 View 中我所要做的就是调用一个文件。
如果我将逻辑留在 View 中,这意味着我必须在每个 View 中处理它。我想避免它。
最佳答案
您不需要使用开关和魔法字符串。您可以使用此属性检查 Culture 是否为 RTL:
Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft
关于c# - 添加语言 (LTR/RTL) 机制来 bundle MVC 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14908855/