Different languages may displayed in multiple directions. Therefore, when switching from one language version of a page to a different language version of the page (e.g. from an English version to an Hebrew version of the same page) the direction needs to be switched.

Following my answer to Xing, here is a suggested implementation:

To correctly support Hebrew, Arabic, and other languages with non-standard direction we should add a 'direction' attribute to the 'language' table on the drupal core. The values of this table may be taken from the full W3C languages direction table. Then, we may add a switch which loads a little extension to 'drupal_[direction].css' which load the correct definitions of the direction, according to the language. For example, for Hebrew and Arabic we may load 'drupal_rtl.css' since the direction is RTL.

(Next, as an extra optional step, we may add a little switch to the phptemplate engine, which dynamically loads an extra theme-specific style file (which may be called style_[direction].css - e.g. style_rtl.css) according to the language chosen by the user. )

Amnon
-
Drupal Israel- Hebrew drupal translation project.

CommentFileSizeAuthor
#3 css-rtl.tgz4.04 KBdruvision
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

druvision’s picture

I've opened the new direction field as an issue for the 'locale' core module : http://drupal.org/node/56110. The style switching seems like the responsibility of this module.

Jose Reyero’s picture

Status: Active » Closed (fixed)

Yes, this is a localization/theming issue.

There are some themes that support bi-directional text.

druvision’s picture

Status: Closed (fixed) » Active
FileSize
4.04 KB

Yet the direction field is needed in the languages table in core. This would make so many things much simpler. It's not only a theming issue - drupal.

For example, in drupal 5.0 there is a separate style sheet for each core module.
Attached is RTL versions of the style sheets.

Having the language direction in core would enable us to automatically load the correct style sheets according to the current language. Doing it in core is correct for all themes. It's inefficient to duplicate the work for each module.

In the 5.0 beta 1 version, there are 16 modules which require attention. In each module folder, there is a CSS file, whose name we've changed from modulename.css to modulename-rtl.css. Hence, the following additional files are attached:

admin-rtl.css, aggregator-rtl.css, block-rtl.css, book-rtl.css, comment-rtl.css, defaults-rtl.css, forum-rtl.css, help-rtl.css, menu-rtl.css, node-rtl.css, poll-rtl.css, profile-rtl.css, search-rtl.css, system-rtl.css, taxonomy-rtl.css, user-rtl.css

In order to continue with the efficiency purpose in the base of the file names, we must load the new files instead of the present files.

In the current RTL localization of Drupal Israel, the CSS files upload code have to be repeatedly copied fo each new theme (code below). Of course, it will be more efficient to upload it once for all themes.

The following code is added in page.tpl.php to change the default styles array:

<?php 
/* Load RTL styles instead of default ones: */
foreach($css as $type => $files){
  $current = $type;
  foreach($files as $name => $file){
    $element = $name;
    $rtl_style = str_replace(".css","-rtl.css",$file['path']);
    if(file_exists($rtl_style)){
      $css[$current][$element]['path'] = $rtl_style;
    }  
  }
 }
?>

The following action loads the new array instead of the default array:

<?php 
//print $styles // commented out in favour of drupal_get_css($css) to include the rtl styles
print drupal_get_css($css) ;
?>

There must be a more generic way to do it - and that's why I think that adding the language direction attriute to core is a good idea.

The attached files are for beta 1. Some location and CSS changes were done in beta 2 - updated files will hopefully follow - but having the direction attribute to files is an important base for it all.

Amnon

druvision’s picture

Status: Active » Needs work
Jose Reyero’s picture

Support to set up RTL languages is already in the HEAD version of i18n, so it will be in i18n 5.0

See function i18n_language_rtl in i18n module

With this and some theme support, it should be enough to have it working.

Cheers,

z.stolar’s picture

Hi Jose,

I havnen't tried the latest HEAD version (BTW, the details in 'view all releases' are outdated), but I took a look on the code.
First thing I want to say - the code looks great, and it surely suggests some nice improvements, as the function you mentioned, and the ability to mark a language as RTL in the locale admin page.
However, the i18n module, to my opinion, should only be used where a site serves multilingual content. In sites that only serve content in one language, installing and configuring, not to mention loading the i18n module is not at all necessary, or, better put - shouldn't be necessary.
We try to look for a way to RTLize drupal at its core. So actualy the module, at its current state, doesn't solve the problem we're trying to deal with: easing the possibilty to change a site's directionality.
The solution, as I mentioned, should be in core level, and the modules' CSS files should be doubled. A simple function should decide which CSS file to load. I realy don't see the need to hussle with another module (great as it is). I'll open another issue (or look for an existing one) that will attack the problem at the core level.

Jose Reyero’s picture

Status: Needs work » Fixed

I'll open another issue (or look for an existing one) that will attack the problem at the core level.

Yes, you should open an issue for locale module

However, in the meanwhile, before it gets into Drupal core, i18n module will provide this option.

druvision’s picture

Title: Language direction switching (right to left <-> left-to-right <-> top-to-button) » Language direction switching (RTL / LTR / TTB) - move to core

Thanks, Jose, for the fast treatment of the RTL support for the i18n module. This should be a great advancement over the previous state.

There is an open core issue (http://drupal.org/node/56110). I've opened it around the same time but it was not treated yet. I will update it with the results of this discussion.

Who can help with the core issue?

Thanks

Amnon

Anonymous’s picture

Status: Fixed » Closed (fixed)