Thursday, 15 March 2012

c# - Add language (LTR/RTL) mechanism to bundles MVC 4 -



c# - Add language (LTR/RTL) mechanism to bundles MVC 4 -

background

i building multilingual system i using mvc 4 bundles feature i have different javascripts , styles files right-to-left (rtl) , left-to-right (ltr) languages

currently handle scenario follow:

bundleconfig file

//styles ltr bundles.add(new stylebundle("~/content/bootstarp").include( "~/content/bootstrap.css", "~/content/customstyles.css")); // styles rtl bundles.add(new stylebundle("~/content/bootstraprtl").include( "~/content/bootstrap-rtl.css", "~/content/customstyles.css")); //scripts ltr bundles.add(new scriptbundle("~/scripts/bootstrap").include( "~/scripts/bootstrap.js", "~/scripts/cmscommon.js" )); //scripts 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") }

the question:

i wondering if there improve way implement it, hoping for:

handle logic of detecting civilization , pull right file in bundles (code behind) not in views.

so in views have calling 1 file.

if leaving logic in views means have handle in each view. want avoid it.

try custom html helper:

public static class culturehelper { public static ihtmlstring renderculture(this htmlhelper helper, string culture) { string path = getpath(culture); homecoming styles.render(path); } private static string getpath(string culture) { switch (culture) { case "he-il": homecoming "~/content/bootstarprtl"; default: homecoming "~/content/bootstarp"; } } }

c# css asp.net-mvc bundle

No comments:

Post a Comment