Moodle

Can't add rtl css files. Does Moodle load theme/config.php several times with different $CFG set?

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.9
  • Component/s: Themes
  • Labels:
    None
  • Environment:
    Server: UBUNTU Linux, 2.6.17-11, apache 2, PHP Version 5.1.6
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

Moodle does not load the 'rtl' CSS files.

  1. rtl_styles.patch
    24/Jul/07 1:30 AM
    4 kB
    Urs Hunkler
  2. rtl_theme.patch
    23/Jul/07 7:10 AM
    8 kB
    Petr Škoda (skodak)

Issue Links

Activity

Hide
Urs Hunkler added a comment -

1) I added central var langdirection - is in CVS
set $CFG->langdirection in lib/setup.php line 590
$CFG->langdirection = (get_string('thisdirection') == 'rtl') ? 'rtl' : 'ltr';

2) I added body CLASS for langdirection - is in CVS
add body class in lib/weblib.php - print_header line 2455
if (!empty($CFG->langdirection)) { $pageclass .= ' ' . $CFG->langdirection; }

3) I select theme sheets depending on $CFG->langdirection (debugging included) - is in CVS
trigger_error('custom_corners/config.php - $CFG->langdirection: '.$CFG->langdirection, E_USER_NOTICE);

if ($CFG->langdirection == 'rtl') {
$THEME->sheets = array('user_styles', 'styles_rtl');
trigger_error('custom_corners/config.php - is rtl ::: ', E_USER_NOTICE);
} else {
$THEME->sheets = array('user_styles');
trigger_error('custom_corners/config.php - is not rtl ::: ', E_USER_NOTICE);
}

trigger_error('custom_corners/config.php - $THEME->sheets: '.$THEME->sheets[0].', '.$THEME->sheets[1], E_USER_NOTICE);

1 and 2 work perfectly.

3 does not work. Moodle always uses the ltr sheets.

The set of debug messages is written to the error log 4 or more times. The first time correctly with the right langdirection. All following message sets war wirtten with the wrong langdirection. Does this mean that Moodle loads the theme/config.php several times and with different global variables?

Show
Urs Hunkler added a comment - 1) I added central var langdirection - is in CVS set $CFG->langdirection in lib/setup.php line 590 $CFG->langdirection = (get_string('thisdirection') == 'rtl') ? 'rtl' : 'ltr'; 2) I added body CLASS for langdirection - is in CVS add body class in lib/weblib.php - print_header line 2455 if (!empty($CFG->langdirection)) { $pageclass .= ' ' . $CFG->langdirection; } 3) I select theme sheets depending on $CFG->langdirection (debugging included) - is in CVS trigger_error('custom_corners/config.php - $CFG->langdirection: '.$CFG->langdirection, E_USER_NOTICE); if ($CFG->langdirection == 'rtl') { $THEME->sheets = array('user_styles', 'styles_rtl'); trigger_error('custom_corners/config.php - is rtl ::: ', E_USER_NOTICE); } else { $THEME->sheets = array('user_styles'); trigger_error('custom_corners/config.php - is not rtl ::: ', E_USER_NOTICE); } trigger_error('custom_corners/config.php - $THEME->sheets: '.$THEME->sheets[0].', '.$THEME->sheets[1], E_USER_NOTICE); 1 and 2 work perfectly. 3 does not work. Moodle always uses the ltr sheets. The set of debug messages is written to the error log 4 or more times. The first time correctly with the right langdirection. All following message sets war wirtten with the wrong langdirection. Does this mean that Moodle loads the theme/config.php several times and with different global variables?
Hide
Urs Hunkler added a comment -

I need urgent help!

I tired to understand the process 2 days long, but I could not find any starting point to understand why the config.php seams to be loaded several times.

How does Moodle handle the theme building? Might I have found a bug?

Show
Urs Hunkler added a comment - I need urgent help! I tired to understand the process 2 days long, but I could not find any starting point to understand why the config.php seams to be loaded several times. How does Moodle handle the theme building? Might I have found a bug?
Hide
Urs Hunkler added a comment -

Martin (or Petr), are you interested in true rtl support? If yes, please help!!!

Show
Urs Hunkler added a comment - Martin (or Petr), are you interested in true rtl support? If yes, please help!!!
Hide
Mauno Korpelainen added a comment - - edited

Urs,

just one thought: is it possible to have the code in styles.php of language folders because this problem is only connected to rtl languages?
You already have a possibility to set $THEME->langsheets = true; in theme config.php and to include styles.php inside rtl language folders - or simply have different code for ltr languages styles.php and rtl languages styles.php.

Show
Mauno Korpelainen added a comment - - edited Urs, just one thought: is it possible to have the code in styles.php of language folders because this problem is only connected to rtl languages? You already have a possibility to set $THEME->langsheets = true; in theme config.php and to include styles.php inside rtl language folders - or simply have different code for ltr languages styles.php and rtl languages styles.php.
Hide
Urs Hunkler added a comment -

Mauno, the langsheets might be an emergency solution if nothing else works.

Themes will need a longer documentation where users need to copy which files. That is contra productive. Therefore I prefer a solution within the theme logic. And I don't understand why my approach is not working.

Probably we will have to wait for an answer until Moodle enters the User Experience market maturity stage

Show
Urs Hunkler added a comment - Mauno, the langsheets might be an emergency solution if nothing else works. Themes will need a longer documentation where users need to copy which files. That is contra productive. Therefore I prefer a solution within the theme logic. And I don't understand why my approach is not working. Probably we will have to wait for an answer until Moodle enters the User Experience market maturity stage
Hide
Petr Škoda (skodak) added a comment -

I do not think this could work, the problem is that the theme css files are included from style.php which does not known the correct language (no course_setup()).

Solution could be to use one sheet for both rtl and ltr languages - see attached path, seems to work fine for ar lang pack here (with one minor corner bug on the frontpage)

Show
Petr Škoda (skodak) added a comment - I do not think this could work, the problem is that the theme css files are included from style.php which does not known the correct language (no course_setup()). Solution could be to use one sheet for both rtl and ltr languages - see attached path, seems to work fine for ar lang pack here (with one minor corner bug on the frontpage)
Hide
Mauno Korpelainen added a comment -

Yes, a single stylesheet works ok. I tested one version in http://tracker.moodle.org/browse/MDL-9977 and the main problem was to set paddings and margins properly for all browsers. It may be easier to create new themes with three images for box top and three images for box bottom instead of one bt and one bb image.

Show
Mauno Korpelainen added a comment - Yes, a single stylesheet works ok. I tested one version in http://tracker.moodle.org/browse/MDL-9977 and the main problem was to set paddings and margins properly for all browsers. It may be easier to create new themes with three images for box top and three images for box bottom instead of one bt and one bb image.
Hide
Urs Hunkler added a comment -

I got a solution: Looking at the langsheet handling I found out, that lang info is handled via parameters in the url.

I added a langdir parameter in weblib and add it to the url in styles.php.

This way one can define any file in any theme with '_ltr' or '_rtl' postfixes and Moodle will filter out the wrong one. And this way theme designers can decide if they want to use alternative CSS files for ltr and rtl positioning. This is the preferable way because we keep the CSS downloaded as small as possible.

Or they may write ltr only CSS and add one rtl CSS file which overwrites the important definitions.

Just add the CSS files for both directions in the theme config file. Moodle filters out the "wrong" ones.

We need such a solution because transferring ltr and rtl formatting in one file makes the CSS much larger. And Moodle CSS is already that large that I prefer to not add any unnecessary byte. Most programmes I know offering rtl support solve the issue with separate ltr and rtl CSS files which are selected depending on the language writing direction.

Petr, are there any concerns using this method?

Show
Urs Hunkler added a comment - I got a solution: Looking at the langsheet handling I found out, that lang info is handled via parameters in the url. I added a langdir parameter in weblib and add it to the url in styles.php. This way one can define any file in any theme with '_ltr' or '_rtl' postfixes and Moodle will filter out the wrong one. And this way theme designers can decide if they want to use alternative CSS files for ltr and rtl positioning. This is the preferable way because we keep the CSS downloaded as small as possible. Or they may write ltr only CSS and add one rtl CSS file which overwrites the important definitions. Just add the CSS files for both directions in the theme config file. Moodle filters out the "wrong" ones. We need such a solution because transferring ltr and rtl formatting in one file makes the CSS much larger. And Moodle CSS is already that large that I prefer to not add any unnecessary byte. Most programmes I know offering rtl support solve the issue with separate ltr and rtl CSS files which are selected depending on the language writing direction. Petr, are there any concerns using this method?
Hide
Petr Škoda (skodak) added a comment -

Minor problem might be with caching, I would recommend using optional_param with default ltr.

Do you need any help with coding?

Show
Petr Škoda (skodak) added a comment - Minor problem might be with caching, I would recommend using optional_param with default ltr. Do you need any help with coding?
Hide
Urs Hunkler added a comment -

Petr, thanks for offering your help. Going this way there where only two small changes and some cleaning up to do. "MDL-10075 - changes done following Petr's patch and optional_param with default ltr".

Show
Urs Hunkler added a comment - Petr, thanks for offering your help. Going this way there where only two small changes and some cleaning up to do. "MDL-10075 - changes done following Petr's patch and optional_param with default ltr".

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: