Reputation: 343
How can I change the page direction based on the local setting of the user? from left to right to right-to-left? Should this be done using JS only, or there is a better way? please note that I need to Change to value, not check the current culture settings.
Using ASP.NET MVC5
Thanks
Upvotes: 5
Views: 9469
Reputation: 5905
To set the text direction of the whole page in HTML 5, you can set the dir
attribute on the html
or body
element. (In HTML 5 the dir
attribute can be used on any element).
For instance if you're setting the CurrentThread CurrentCulture in the request, you can use the following in your view:
<html
dir="@(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft? "rtl" : "ltr")">
Based on http://afana.me/post/aspnet-mvc-internationalization.aspx
Note that if you're using a CSS library such as bootstrap, you'll also need to get an rtl-modified version of the CSS, because the page direction won't affect css rules.
Upvotes: 8