Add Language (LTR / RTL) to Combine MVC 4

Background

  • I am creating a multilingual system.
  • I use the MVC 4 packages feature
  • I have a different files Javascriptsand Stylesfor languages Right-To-Left (RTL) and Left-To-Right (LTR)

I am currently processing this script as follows:

BundleConfig File

 //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"
            ));

Implementation in views:

@if (this.Culture == "he-IL")
{
    @Styles.Render("~/Content/bootstrapRTL")
}
else
{
    @Styles.Render("~/Content/bootstrap")
}

Question:

I was wondering if there is a better way to implement it, I was hoping:

Process the culture detection logic and pull out the desired file in bundles (code behind), not in views.

So, in the views that I need to do, I need to call one file.

If I leave the logic in the views, it means that I have to process it in each view. I want to avoid this.

+5
source share
2

HTML-:

public static class CultureHelper
{
    public static IHtmlString RenderCulture(this HtmlHelper helper, string culture)
    {
        string path = GetPath(culture);
        return Styles.Render(path);
    }

    private static string GetPath(string culture)
    {
        switch (culture)
        {
            case "he-IL": return "~/Content/bootstarpRTL";
            default: return "~/Content/bootstarp";
        }
    }
}
+3

. , RTL :

Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft
+5

All Articles