In RTL languages the direction should be set to be from right to left and hence everything on the page should be mirrored horizontally. Graphical arrows that point to the right, should now point to the left. Things that float right, should now float left. padding-left values, should go to padding-right values and vice versa. Other rules which are not direction oriented would remain the same.

The solution is to have a drupal_RTL.css file. I will shortly show an example of that file. This file should be loaded from common.inc in addition to drupal.css in case of RTL languages to override a few rules of the defaults.

This way drupal would support RTL language and mambo and zope/plone won't have an advantage over drupal on this issue ;).

For now, temporary I put the logic into my own template.php like this

// $Id: template.php, v 0.01 $
/**
 * Catch and override the theme_stylesheet_import function from theme.inc
 */
function phptemplate_stylesheet_import($path, $media = 'all') {
// May be it's better to add a variable isRTL to locales_meta
// table so as not to hardcode the languages in the code
  $rtl = array("ar", "fa", "he", "ur", "yi"); // There are a couple or so more
  if (in_array(locale_initialize(), $rtl)) {
    if (file_exists(path_to_theme() . '/drupal_RTL.css')) {
      theme_add_style(path_to_theme() . '/drupal_RTL.css', $media);
    }
    if (file_exists(path_to_theme() . '/RTL.css')) {
      theme_add_style(path_to_theme() . '/RTL.css', $media);
    }
  }
  return theme_stylesheet_import($path, $media);
}

Which would work but would require an unnecessary step of duplicating this same file in all the themes directories.

When we make this clear in the documentation, the developers of the themes could make their design in a more or less symmetric way that doesn't even require a separate RTL.css file but when the need arises, the theme author or any one interested could very easily make that file available and official part of the theme. As an example, I quickly tested the theme fancy and here is a minimal file that works.

/* Override styles from style.css */
#logo img {
  float: right;
}
#menu {
  text-align: left;
}
#primary-tabs {
  float: left;
}
.bleft {
  width: 10px;
}
.bleft-img {
  background: #ce5003 url(images/cr.png) no-repeat top right;
}
.bright-img {
  background: #ce5003 url(images/cl.png) no-repeat top right;
}

Hope this would help solve the problem in a neat way.

Comments

Steven’s picture

I definitely like the idea of providing a drupal-rtl.css with overrides. Granted, this means a bit of extra bandwidth for RTL users (because the LTR styles are also sent), but the number of styles to override should be pretty small and it keeps maintainability.

A theme-specific rtl.css is a nice idea because it would allow a single theme to accomodate both directions for mixed language sites, where now you would have to create two separate themes.

But this is definitely a new feature, not for 4.7.

Zen’s picture

Category: bug » feature
munzirtaha’s picture

Thanks Steven,
I am really happy that you like the idea. We can also wait to see it after the release of 4.7.

But has drupal the flexibility to implement it as a module. I can try it myself if you give a hint whether this is possible and which hook should I look at.

munzirtaha’s picture

Here are the completed and revised drupal_RTL.css and RTL.css (for theme fancy)

munzirtaha’s picture

StatusFileSize
new1.32 KB

Hi Steven, I would appreciate it if you also consider this small patch. This would allow the pages numbers to flow from right to left when direction: rtl; is used in drupal_RTL.css. So, instead of having the page numbers like 123456, it would appear as 6 5 4 3 2 1. Without a space in between, RTL rules would have no effect since it would be considered one word. Without this change we need to go patch all the available and future themes to override theme_pager_list. Since, this change is so trivial (just two spaces), I won't be afraid to request it go to 4.7 if possible ;)

--- includes/pager.inc 2006-04-23 02:04:53.000000000 +0300
+++ includes/pager.inc.new 2006-04-23 02:18:28.000000000 +0300
@@ -317,10 +317,10 @@
// Now generate the actual pager piece.
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current) {
- $output .= theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters);
+ $output .= theme('pager_previous', $i .' ', $limit, $element, ($pager_current - $i), $parameters);
}
if ($i == $pager_current) {
- $output .= ''. $i .'';
+ $output .= ''. $i .' ';
}
if ($i > $pager_current) {
$output .= theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters);

munzirtaha’s picture

StatusFileSize
new863 bytes

For some unknown reason, the diff is truncated. Here is a real patch ;)

munzirtaha’s picture

StatusFileSize
new2.59 KB
munzirtaha’s picture

Version: 4.7.0-beta5 » 4.7.0
StatusFileSize
new2.64 KB

Steven told me on #drupal that the solution of adding the space is non-semantic. Hence, I come up with another neater solution which is to add
#pager {
unicode-bidi: bidi-override;
}
to drupal-rtl.css.

I used to know there is something called unicode-bidi but I haven't tried to figure out what is it till I was trapped by Steven to find a better solution. Thanks.

Attached is a new version of drupal-rtl.css

webchick’s picture

Version: 4.7.0 » x.y.z

feature requests are against cvs

munzirtaha’s picture

StatusFileSize
new365 bytes

I hope some one would commit the changes to cvs before we hear there is already a freeze. Attached is an rtl.css for bluemarine too.

bdragon’s picture

Version: x.y.z » 6.x-dev
Status: Active » Fixed

Drupal 6 is finally getting RTL override support.
http://drupal.org/node/132442#language-rtl

Anonymous’s picture

Status: Fixed » Closed (fixed)