Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing page direction (Right-to-Left/ Left-To-Left) based on Localization settings in MVC 5

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

like image 553
Hamed Salameh Avatar asked Feb 06 '23 21:02

Hamed Salameh


1 Answers

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.

like image 134
kristianp Avatar answered Feb 12 '23 10:02

kristianp