In order to implement true language direction switching needed by the internationalization module, a new field needs to be added to the locales table, which specifies the language direction. To correctly support Hebrew, Arabic, Chinese 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.

Suggested field name: "direction"
Suggested values: ltr (default), rtl (right-to-left), ttb (top-to-button).

For more information on the source of this request you may take a look here - an issue I've opened, and Here - a post I've answred.

CommentFileSizeAuthor
#1 css-rtl_0.tgz4.04 KBdruvision

Comments

druvision’s picture

Title: Language direction - add an extra field to the locales table » Language direction support (RTL)
Version: x.y.z » 5.x-dev
Status: Active » Needs work
StatusFileSize
new4.04 KB

Since the issue was opened, language direction support was added to the i18n module. However, it's agreed this should really be moved be core.

The solution, 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).

The direction field is needed in the languages table in core. This would make so many things much simpler.

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, generically, on core.
Currently, The following code is added in page.tpl.php to change the default styles array:

/* 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:

//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. Once the base exist, we can update files as needed.

druvision’s picture

To summerize, we believe Drupal's core should have an RTL (/TTB) version of each of the css files of the core modules added to the core distribution, and add a function which will select the right file. We will supply the right RTL file.

We believe that If the core will allow dual files, then contrib modules will also start to add this option. Also, if the function which loads CSS files will select the right version, then it will be done automatically for contrib modules as well, without writing any special functions.

Amnon Levav
Drupal Israel

killes@www.drop.org’s picture

I think the right table to add this is the locales_meta table. It already contains language specific stuff like the way that plurals are handled.

The question is: How do we get this information /into/ that table? The plurals for example are added from the PO files. However, I don't think that rtl is a valid header for PO files.

Steven’s picture

Have you considered automatic mirrorring of CSS files?

Steven’s picture

Version: 5.x-dev » 6.x-dev
druvision’s picture

>> KILLES asked: How do we get this information /into/ that table

Hi Killes,

I hope I understand you correctly. I think "this" in your question means = "the RTL information".

Language direction (LTR / RTL / TTB) is a constant language attribute. The default is LTR, so there are only 20-30 constant values to put info the locales_meta table. Not such a big deal.

I suggested adding a "direction" column to the locales_meta table (this will provide more flexibility for developers). Your suggestion of a property is also possible but more difficult to work with.

A good strating list of locales contains "ar", "fa", "he", "ur" and "yi" (ref: http://drupal.org/node/3696). There are 10-20 more languages (ref: http://www.i18nguy.com/temp/rtl.html) but I suggest they will be added upon request.

Here is the basic code from http://drupal.org/node/3696:

$rtl = array("ar", "fa", "he", "ur", "yi"); // There are a couple or so more

Yes, Steven. We have considered automatic mirrorring of CSS files:
1. We have already defined a general algorithm for that, but it won't always work, so such an automatic conversion can only be used as a deafult, with a possibility for override.
2. Automatic CSS mirring is an additional layer. First deal with having the language direction in the database, and define the architecture. Only then we can create various algorithms. I think this is the right order.
3. Once we have the basic core DB structure covered, we can make PHPTemplate smarter. Automatic CSS mirroring must also have the ability to override it on a per-template basis. Sometimes it's needed. We can allow CSS to take the mirrored file, if available, and later even try to create it, but this is an advance solution.

Saied Taghavi’s picture

dear levavie,
after a search in forum and reading lots of topics about drupal rtl support it seems that your approach is better than others and more acceptable. but it is not clear that this approach and attached file(s) cab be applied to drupal 4.7.4 (current stable version). i want to ask you if possible describe your approach a bit clear specifically for latest stable version.
thanks

druvision’s picture

Hi Saied,

This whole post is related to drupal 5.0 RTL support.

Drupal 4.7.x is much easier - but please open a separate issue for that. You simply need to use the BIDI theme (or download similar RTL themes from here. Find somebody that will translate it for you...

Amnon

druvision’s picture

For the meanwhile I've add a new 5.0 theme, Garland RTL, which implements my RTL ideas. Your help is welcome for testing and submitting fixes.

Currently, the RTL language detection code is hardcoded inside page.tpl.php - I hope it will be moved to core, so it will be available for all themes. Anyway, this is a big advancement over the previous state.

druvision’s picture

Title: Language direction support (RTL) » language direction API : locale_is_rtl_lang ($language)

To summerize the thread above:

Currently, anyone who needs to know the language direction must hardcode it. The following code is used by the new Garland RTL theme, which aims to be the standard theme for RTL languages:

$is_rtl_lang = array("ar", "fa", "he", "ur", "yi"); // There are a couple or so more

Locale.module must provide information about the language direction.

It will be more efficient to store those values as an array.

Suggested API

/* The function returns the language direction: 'ltr' (default), 'rtl' and 'ttb'. */
function locale_get_direction ($locale) {
}

Suggested implementation

/* The function returns the language direction: 'ltr' (default), 'rtl' and 'ttb'. */
function locale_get_direction ($locale) {
   // There are a couple or so more. Put the codes of your RTL languages here
   static $rtl_langs = array("ar", "fa", "he", "ur", "yi"); 

  if (in_array ($locale, $rtl_langs)) {
    return "rtl";
  } 
  else {
     return 'ltr';
  }
}

Of couse if we want to be generic, we can store those values a new column, named 'direction', in the 'locales_meta' table, and initialized by drupal DB creation:

This brings us to the alternate implementation:

function locale_get_direction ($locale) {
  $result = db_query("SELECT direction from {locales_meta} where locale='%lid' ", $locale);
  if ($row = db_fetch_object($result)) {
    return $row->direction;
  }
  else return FALSE;
}

But this seems like an overkill. All we need is an array of 10-20 constant values, so I will go with the first implementation.

So, please review & commit the 1st implementation

druvision’s picture

Status: Needs work » Needs review
druvision’s picture

Title: language direction API : locale_is_rtl_lang ($language) » language direction API : locale_get_direction ($locale)

Changing the function name in the title to locale_get_direction ($locale)

dries’s picture

The API looks good, but we'll want to pull this out of the database. People can add custom languages (or derivative languages such special language dialects) through the user interface. Thus, it is impossible to use a static array.

As for the CSS, would it be possible to have a small rtl.css or ltr.css that gets included? If so, could the other stylesheets be 100% agnostic? It would be great if we could isolate the RTL/LTR specific bits but I doubt that is possible.

z.stolar’s picture

About CSS - In Drupal Israel we already did some work to provide core RTL CSS files. These files are also provided with the RTL version of Garland - Garlandrtl.
I think breaking the CSS into two seperate files (e.g. defaults-sizes-and-colors.css and defaults-directionality.css) would be a nightmare to work with. However, since core CSS files are hardly changed during a release's life span, it's quite easy to have two versions of the CSS files, and have a core function to load the correct one.
As already stated elsewhere, this would hopefuly incourage contrib modules authors to include two version of their CSS, or at least would enable other people to easily contribute the RTL CSS, in the same way it is done with translations.

alaa’s picture

dries in a perfect world an rtl css should be a mirror of the default ltr css.

so padding, border and margine values for left and right should be reversed, for floats and text-align we should change the value from left to right and vice versa.

but browser bugs (rtl support sucks in all browsers, IE is not the exception here) and complex designs require tweaks and hacks.

I doubt we can ask themer's to cope with all that, but for module css (specially core), I'm sure we can have perfect mirrors (generated or hand made) and let themers worry about the bugs and the hacks.

druvision’s picture

Title: language direction API : locale_get_direction ($locale) » core language direction (RTL) support

This thread had two discussions going on parallel (I expect more to come):

The first issue (locale_get_direction API) has passed review and solution has been decided (the API concept is approved. The language direction property needs to be saved in the database) - please assign it to the right person to do the change!

For the second issue (Location of CSS RTL files for core and contrib modules) - decision has yet to be taken on where to save them (no, we can't do it automatically).

Those issues should be discussed on separate threads.

I am now splitting up the discussion - this will enable us to move forward more smoothly.

Since we don't have a separate RTL compenent to the drupal project, I will leave this issue as a summary issue to hold the current status of RTL translation. Please post specific information to the relevant issues.

druvision’s picture

Status: Needs review » Active

Issues 1 and 2 seem to be solved by the Budapest internationalization meeting finding, while issue #3 is still open, so I hope to summerize it soon.

druvision’s picture

I've summerized issue #3 here: Automatically load RTL CSS files

gábor hojtsy’s picture

Status: Active » Closed (duplicate)

Issues are split, and Drupal 6 core already has support for RTL languages (although not RTL CSS yet), so marking this issue duplicate.