I maintain a theme called Tendu, and we are just now working on a function that does something similar.
Your implementation is far better then our current approach.

My question - Can this module / technique be implemented only with a function in template.php (+ the lines in the info file)?
I would love to add it as a part to my theme, but I don't want the theme to include a modules/ directory by default.

btw - how does your module handles sub-themes? any special behavior, or does it work just like regular added css file?

Thanks
Tom

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin’s picture

Status: Active » Fixed

With sub-themes, the same rules apply to conditional stylesheets as to regular stylesheets. Sub-themes inherit the conditional stylesheets of their parent themes; and sub-themes can override or remove conditional stylesheets in the normal way.

And, yes, you can add this technique using a tendu_preprocess_page() and a tendu_theme() function. But its tricky. Zen 6.x-1.0-beta3 (and later) does this.

tombigel’s picture

Thanks, I copied the relevant code from Zen and it works :)

One more question I forgot to ask:
In Drupal 6, when an RTL language is selected, for every stylesheet loaded Drupal looks for an additional stylesheet-rtl.css and adds it for incremental RTL changes right after it loads the regular stylesheet.
This rule does not apply to the stylesheets added by this module, I'll try to add it manually and post it here, but it should be a part of the module.

JohnAlbin’s picture

Status: Fixed » Active

Um… not sure. Can't check right this sec, so I'll re-open this issue so I don't forget to check later.

tombigel’s picture

Status: Active » Needs work
FileSize
1.37 KB

Hi again, I created a patch for automatically adding RTL CSS files when needed.
It was tested only on my local Tendu installation, I hope it works for you too.

I hope the patch is in the right format, never created one for a Drupal project myself.

JohnAlbin’s picture

Title: Is there a way to use this technique with template.php only? » Add support for RTL languages
Category: support » feature
Status: Needs work » Needs review

Thanks for the patch! I'll take a look at it soon.

tombigel’s picture

btw - The code with the patch is already integrated in Tendu version 2.x-dev and 2.x beta1

tombigel’s picture

Status: Needs review » Needs work

Found a bug in my code:
If "locale" module is not enabled, the constants LANGUAGE_RTL / LANGUAGE_LTR are not defined.
I tried to replace this line in my patch:

if ($language->direction == LANGUAGE_RTL){

With this line:

if (defined(LANGUAGE_RTL) && $language->direction == LANGUAGE_RTL){

But it doesn't work.

I need help with this one...

tombigel’s picture

Sorry my bad - it was supposed to be:
defined('LANGUAGE_RTL')

So this line:

if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL){

Works!

tombigel’s picture

You can't add a file when editing a comment here, so here's the updated patch...

apaderno’s picture

Rather than using all those backslashes to escape the string delimiter inside it, I would use a different string delimiter.

apaderno’s picture

I changed a couple of string delimiters which should not have been changed.

tombigel’s picture

ok.
I just copied their original "output .=" line...

JohnAlbin’s picture

Status: Needs work » Needs review

So we have a choice of lots of \" or lots of ' . ' in that line. Neither are ideal, but I still find the \" easier to read.

Thanks for the patch, Tom! Can I get someone to confirm the patch in #9 actually works? :-)

JohnAlbin’s picture

Category: feature » bug
FileSize
1.45 KB

This is the same as Tom's patch in #9 but conforms to Drupal's coding standards (with regards to spaces). Also, given how drupal_add_css() works, I've removed the check for defined('LANGUAGE_RTL') as it seems unnecessary.

JohnAlbin’s picture

Title: Add support for RTL languages » Add missing support for RTL languages

Tom, I just re-read your comment in #7 above, LANGUAGE_RTL and LANGUAGE_LTR are not defined in locale.module, they are defined during the bootstrap. http://api.drupal.org/api/constant/LANGUAGE_RTL/6

So, I don't understand what errors you were encountering.

JohnAlbin’s picture

Status: Needs review » Fixed

Ok, I created a fake language for en-us that is RTL. Which, let me tell you, gives very interesting results. :-)

But its enough for me to test this patch. Everything seems to be working.

Thanks for the patch, Tom! http://drupal.org/cvs?commit=216204

tombigel’s picture

@JohnAlbin: Maybe I was wrong about what caused the symptom, I just know what fixed it.
And anyway, checking whether a constant is defined before using it is better practice.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Version: 6.x-1.0 » 6.x-1.1
Status: Closed (fixed) » Needs review

@JohnAlbin Thank you for this useful module.

I'm sorry to reopen this issue but I experiencing problems with my rtl site although I'm using 6.x-1.1 and Tom recent rtl patch if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) should work.

my case:
- site has 2 languages enabled, one ltr and one rtl.
- the site default is the ltr one.
- rtl language negotiation set to path prefix only
- the module should load one of the files, ie6.css or ie7.css if on IE and if language is rtl then load it with it -rtl.css version.

the issue:
If the browser is IE (whether 6 or 7) then the conditional style always load both files (ie6.css and ie6-rtl.css) whether page language is rtl or ltr.

I tried to make the language condition at line 78 to be $language->direction == LANGUAGE_RTL but didn't work.

I'm out of reasons why this module is working for me.

Anonymous’s picture

Update

The issue is clear now

The browser keeps conditional style load both files (ie6.css and ie6-rtl.css) whether page language is rtl or ltr until you "clear cache" from admin>settings>performance.

Once cache cleared you will have no -rtl.css at the ltr . BUT again it gets sticky once you switch to rtl and then it gets back to the first state with no difference (-rtl.css) loads whether on rtl or ltr page until you clear system cache.

drupal core similar functionality adds a dummy query string to keep forcing loads of new copy of files with the url change. http://api.drupal.org/api/function/drupal_get_css/6

$query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);

alexanderpas’s picture

RTL cache overwrote LTR cache (or vice-versa)

this patch should fix it.

tombigel’s picture

@aliadnan:

Weird, I haven't seen this behavior in any of the sites I built on Tendu, and never had a bug report about it.

On the other hand I never used "Path Prefix" in any of my sites. Does Drupal cache things differently in this case?
Or maybe you are doing something else like "Aggressive Mode" caching?

In any case, I'll mark the patch posted here as yet another thing I need to add to Tendu when I have the time... thanks.

JohnAlbin’s picture

Status: Needs review » Needs work

@alexanderpas Your logic looks sound. The cache is being written on a page with indeterminate language. It doesn't make sense to build the cache based only on whatever language happens to be currently active.

However, your patch in #21 doesn't work as the module never uses the new _rtl variable. I'm looking at this now.

When the cache is built, this module should always build a LTR and a RTL cache. And use the appropriate cache depending on whatever language is active on each page load.

JohnAlbin’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 01e3ac3 on 6.x-1.x, 8.x-1.x by JohnAlbin:
    #337975 by tombigel: Add missing support for RTL languages