Switch from LTR to RTL and vice-versa using Language Selector plugin

Hi guys,

With the help of the plugins of Susan Tsairi (Theme RTL Default - http://goo.gl/Rs33y) and Jeroen (Language Selector - http://goo.gl/cgC73) I could come up with a plugin for switching from LTR to RTL and vice-versa. I know I am not a PHP developer but this worked for me although it is not stable because it requires you to upgrade the plugin after every other plugin installation or upgrade. So it's half automatic!

As said, works like a charm when it's the last plugin being incorporated to the list of plugins but would like to see your views and tips before producing a robust RTL/LTR (or the opposite) switching on the fly.

Here's my code (hoping for better enhancement as I am not a PHP expert). It works as explained above but it not robust. Any opinions?


     // Initialization of the plugin.
    // We clear out all previously included CSS views that other plugins have put in (using elgg_extend_view)
    function x_init(){
    $current_lang_id = get_current_language();
    global $CONFIG;
        // For backward compatibility, we'll check if the elgg_extend_view() function exists (Elgg 1.7+) or the extend_view() function exists (Elgg 1.6.1 - Elgg 1.7)
        // *** extend_view may exist in previous version of Elgg as well.
        // *** We haven't used any previous versions though so to be safe, we've put 1.6.1 as min version
        if (function_exists('elgg_extend_view') || function_exists('extend_view')){
            // As we see form the elgglib.php file in the elgg_extend_view() function, the views are saved in this array
            // Having our plugin run last means we can reset the array and then just use our own CSS file to extend the view
            if (isset($CONFIG->views->extensions['css'])){
                // Clearing the actual array of views
                $CONFIG->views->extensions['css'] = array();
            // Adding our CSS file. Add all your CSS to the {ELGG_ROOT}/mod/x/views/default/x/css.php file
            if (function_exists('elgg_extend_view') && $current_lang_id != 'ar'){
                elgg_extend_view('css', 'css');
            } else if (function_exists('extend_view')) {
                extend_view('css', 'x/css');
    // Register our initialization function. We put a huge priority number to ensure that it runs last and can clear out all existing CSS
    register_elgg_event_handler('init','system','sswitch_init', 9999999999999);




  • Hi szvest,

    I am interested in your solution, but where can i insert your code? Thank you

  • Hi Youssef,

    It's somehow like any other plugin. Follow these steps:

    1. Create a new subdirectory in your mod directory. Name it whatever... Say you give it 'X' as a name.
    2. Inside the X subdirectory, create a start.php then copy and paste the above code. 
    3. Inside the X subdirectory (where you got start.php), create another subdirectory called 'views'.
    4. Inside Views, create another subdirectory named 'default'.
    5. Inside 'default', create another subdirectory named 'x'.
    6. Inside 'x', place your RTL stylesheet and name it 'css.php'. 
    7. Go to elgg administration and make sure to place your plugin at the bottom (it should be placed as the last plugin). Then activate it.
    P.S. (step 1 to 6) This is the structure {ELGG_ROOT}/mod/x/views/default/x/css.php



  • were you able to make this one as a plugin??

  • @szvest thanks for this! I'm testing it on a dev environment for an Edu project - managed to get it working for 3 languages English, Arabic and Hebrew  (1 ltr lang 2 rtl langs)