Background
Javascripts
and Styles
files for Right-To-Left (RTL) and Left-To-Right (LTR) languagesCurrently i handle this scenario as follow:
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 the views:
@if (this.Culture == "he-IL")
{
@Styles.Render("~/Content/bootstrapRTL")
}
else
{
@Styles.Render("~/Content/bootstrap")
}
The question:
I was wondering if there is a better way to implement it, i was hoping for:
Handle the logic of detecting which culture and pull the right file in the bundles (Code behind) not in the Views.
So in the views all i will have to do is calling to one file.
If i am leaving the logic in the views its means that i will have to handle it in each view. I want to avoid it.
You don't need to use a switch and magic strings. You can check if a Culture is RTL with this property:
Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With