bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Bootstrap 3.1 RTL Support

Open hero-m opened this issue 13 years ago • 8 comments

I have built this issue to discuss the approach for supporting RTL in the upcoming 3.1 version. Although it's too early for implementation code and pull requests, choosing the right approach now helps in the planning, and directing the efforts towards a specific goal (as many people have already volunteered for the task).

I think the biggest issue is the lack of a standard, or best practices for adding RTL support for themes and pages. First, I want to review some of the current practices for RTL support in different parts of the web.

  • WordPress: uses RTL overrides, in a single seperate file named rtl.css, auto-loaded by WordPress in right-to-left pages. explained here
  • Drupal 7: uses RTL overrides, in a separate file with -rtl.css prefix for every css file loaded by themes, etc. again, auto-loaded in right-to-left pages. explained here
  • Drupal 8: favors RTL overrides prefixed by [dir="rtl"], alongside the base css (no separate files). explained here; also, see the related discussion
  • RTL-This (a website dedicated to turning everything RTL): Has an article comparing different ways to add RTL to css here.
  • Another article by a css-expert (Jens O. Meiert): ... Indicate directionality by the dir attribute on the html element ... Avoid a separate RTL style sheet; find all declarations that specify anything specific to the left or right ... customize those declarations, and use some hook to apply them—like e.g. setting id="rtl" on the body element (well, you really want to use html[dir="rtl"]). article here.
  • Another popular approach is to prefix all RTL rules with a .rtl class (and possibly .ltr for base rules, to prevent overrides). per #3133, #6423, and the less-bidi model.

I'd suggest using an approach than could satisfy these different requirements by simple customizations.

  1. I suggest keeping the RTL rules in a separate css file. Clearly, merging them into a single stylesheet (when required) would be a single copy-paste at the end of the base css.
  2. I suggest using overrides (vs mixins, or automated tools) in a separate .less file. Then, adding any combination of prefixes, or [dir= rules is as easy as a few lines of .less code. example:
[dir="rtl"] {
  @include "bootstrap-rtl.less"
}

or

.ltr {
  @include "bootstrap.less";
}

.rtl {
  @include "bootstrap-rtl.less";
}

hero-m avatar Aug 20 '13 09:08 hero-m

:+1:

kobykorman avatar Aug 20 '13 11:08 kobykorman

You might have a look to R2 nodejs module

fdaugan avatar Sep 02 '13 22:09 fdaugan

Using R2 on the whole css is not the best choice I guess. Becuase stuff like ".pull-left" and ".navbar-left" will end up on the right side, but others like a left popover or tooltip will remain on the left.

We could either:

  1. use R2 on the css, but duplicate the js file and flip the js directions manually (match the js to the css behaviour).
  2. do not flip "_-left/right" classes using R2. (match the css to the js behaviour)
  3. introduce new classes (-front/back) that flip in the rtl css, while the (-left/right) classes are not modified. Also, the js code would use a hint (like a parent "[dir='rtl']" selector) to choose the correct direction (for popovers, etc) on (_-front/back) elements.

Comparing the solutions:

  1. visually correct (matches with ltr page), but semantically incorrect (-left moves content to the right, etc). issue: manual override is still required (now in the js code).
  2. visually incorrect, semantically correct. Issue: the theme or page designer should inject the correct class (-left or -right) based on the page direction (rtl / ltr). (needs extra logic)
  3. visually and semantically correct (if using *-front/back classes).

hero-m avatar Sep 02 '13 23:09 hero-m

Closing out since we'll track as part of #9397 (already noted there per another issue).

mdo avatar Sep 05 '13 02:09 mdo

There are some works done for making BootStrap RTL version: https://github.com/jnaqsh/bootstrap/ or http://rbootstrap.ir/

afattahi54 avatar Sep 08 '13 06:09 afattahi54

I suggest to change names of LTR specific classes to something more general. For example change pull-left and pull-right classes to pull-direct and pull-reverse (or something like this). These names make confusions when working in RTL.

alisabzevari avatar Oct 30 '13 07:10 alisabzevari

when you use RTL, the big problem is, when your site is bidirectional on LTR version, pull-left class must float element to left, but when you change it to RTL version, all pull-lefts must float right. and vice-versa so i suggest instead pull-left and pull-right classes you rename them to pull-far and pull-near. on LTR version pull-near means float left and pull-far means float right on RTL version pull-near means float right and pull-far means float left i always use this Technic

surnay avatar Nov 21 '13 09:11 surnay

actually the term I use is *-start and *-end (align-start pull-start ..etc.) and this is what implemented in so many mainstream projects like android, docbook, xml.org, publican (fedora, redhat and gimp docs), gnome-help (yelp), pango (rendering engine), gtk

http://developer.android.com/reference/android/widget/TextView.html http://fedoraproject.org/wiki/Publican https://developer.gnome.org/gtkmm/stable/classGtk_1_1Alignment.html

muayyad-alsadi avatar Nov 30 '14 12:11 muayyad-alsadi