Detection of language direction and changing layout according to language

Hi developers.

As you may know some languages have different direction. for example Arabic or Persian have Right to Left direction.

There is a feature in "Social Engine" that detects user's language settings and changes the page layout and direction according to these settings. I think this is a cool feature and should be implemented in elgg script.

  • I see that you have already made a RTL theme:

    Can you say what exactly blocks implementing of the automatic direction changing? If you can define the blockers and paint points, we can try to fix them in the Elgg core.

  • I hope I understood your question.

    Well, if we think about a language as a class, every language can have name and direction attributes. This should be implemented in the core. for example English language has direction="ltr" and Persian Language has direction="rtl". This solution can be applied only if the user registered on the site.

    for guest users we can read user's regional settings from the client's operating system and change the layout based on user's regional and language settings. I think elgg can access these settings via request headers on the server side. 


    I have seen the following css code before in the Social Engine script:



           direction = ltr;


    html[dir="rtl"] body


          direction = rtl;


  • Couldn't it be achieve by conditional loading of css files?

    For example in mod/my_theme/start.php:

    function my_theme_init() {
        $user = elgg_get_logged_in_user();
        $rlt_languages = array('fa', 'ar');
        if (in_array($user->language, $rtl_languages) {
            elgg_load_css('my_theme_rtl); // CSS for right to left
        } else {
            elgg_load_css('my_theme_ltr); // CSS for left to right
  • Yes @Juho, your solution is very easy and complete. But I think it should be applied to the default Aalborg theme. Also please note that there are much more rtl languages in the world not just Persian and arabic

  • Feel free to open a GitHub issue if you specific ways we can improve RTL support.

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.