c# - 添加语言 (LTR/RTL) 机制来 bundle MVC 4

标签 c# css asp.net-mvc bundle

背景

  • 我正在构建一个多语言系统
  • 我正在使用 MVC 4 bundle 功能
  • 我有从右到左 (RTL) 和从左到右 (LTR) 语言的不同 JavascriptsStyles 文件

目前我处理这种情况如下:

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/

相关文章:

asp.net-mvc - ServiceStack 如何在 MyController<T> 上 Autowiring 自定义 IRepository<T> 属性

c# - 我可以应用 DebuggerHidden 之类的属性来跳过函数及其调用的所有函数吗?

asp.net-mvc - KnockoutJS : ko. mapping.fromJS问题

c# - DeflateStream/GZipStream 到 CryptoStream,反之亦然

css - 3d 元素在 Firefox 中不起作用

html - 我怎样才能使这个 Wordpress 导航居中?

css - 通过媒体查询缩小图像不起作用

c# - 在 ASP.NET MVC 中返回相同 Controller 的不同 View

c# - Entity Framework TDD,如何对所需字段进行单元测试模型

c# - ASP.NET Core 中的数据表类