Essential Theme - User alert in RTL

Essential Theme - User alert in RTL

by Saeed Amiri -
Number of replies: 27

Hi every one

I'm trying to use theme Essential's "user alert" functionality in both LTR and RTL languages. But apparently using the following codes in the two boxes of "Title" and "Alert Text" does not work. 

<span lang="XX" class="multilang">your_content_here</span>

<span lang="YY" class="multilang">your_content_in_other_language_here</span>

As they must be inserted in the code editing mode of HTML editor, I tried replacing the default

 $setting = new admin_setting_configtextarea($name, $title, $description, $default);

in theme's settings.php with 

$setting = new admin_setting_confightmleditor($name, $title, $description, $default); 

But that did not help either. Is the kind of editor used, say, in the course-summary section which uses the mform editor different from the editor I used?

Any ideas would be appreciated.

Saeed

 

 



Average of ratings: -
In reply to Saeed Amiri

Re: Essential Theme - User alert in RTL

by Mary Evans -

Unfortunately, we have not had good results with getting any foreign languages to work with the multi-lang span system in theme settings. The only way to do this is to have two setting per alert. then making ech work depending on the language.

Not easy ...but achievable.

Mary

PS: I suppose you will ask me next... How will I do that?

So I am going away to think about it   just in case! LOL

In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

@Mary

$language= substr($OUTPUT->htmlattributes(),17,2);
----
    if ($language=='en') {
---
    } elseif ($language=='fr') {

and so forth, like we did with the multiple languages for the slider in soa?

I can try and take a look over the weekend if you haven't had chance before then smile

R

In reply to Richard Oelmann

Re: Essential Theme - User alert in RTL

by Mary Evans -

Thanks for the reminder!

I'll dig those file out if I can find them.

Cheers

Mary

In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

@Mary, I know they're on my backup external disk in work, so I'll try and dig them out tomorrow and take a quick look (I was on my way out to a meeting earlier when I found them to post the suggestion, but didn't have chance to copy them and haven't been back to the office.)

@Saeed - you will probably need to create a second setting for each of the text parts of the notices, with slightly different names, then use an 'if' statement in the layout file to determine which one to use based on the language selected.

I'm being vague deliberately, not to be difficult for you but simply because I don't have the files in front of me right now and I don't want to give you wrong code when I know I have the correct code in work. But Mary and I have done something similar to this in a theme we worked on together in the past, so we know it can be done. Hopefully I (or Mary) can get some proper code for you over tomorrow or the weekend smile

Richard

In reply to Richard Oelmann

Re: Essential Theme - User alert in RTL

by Saeed Amiri -

Hi Richard

Thank you very much! I have been altering various lines in the settings.php with little success. Now with the info you gave me, at least, I know I need to think of creating a different setting file for each one of those text areas relating them to their respective RTL or LTR languages. This whole search and replacement thing has practically taught me - like a patient instructor- quite a whole deal.

Saeed

In reply to Saeed Amiri

Re: Essential Theme - User alert in RTL

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

The settings page just needs extra settings for the language based parts - the title and the text of the warning, something like below (note Essential2 is my clone of essential for testing things like this out - you would need your own theme name and also I've used Welsh as my alternate language, you would use whatever other language packs you are using on your site - I've left the English one unchanged, but you could edit that for clarity.

You would then need to add the necessary strings to the language files in the theme/lang/en and theme/lang/cy (for Welsh, replace with your language pack). You would also need to do this for the other two Alert setting groups in the settings.php file of your theme.

That should create the settings and I'll give you the correct code to use it in the layout files (and hopefully full code for this and a language page and instructions) tomorrow, if Mary doesn't beat me to it, being the night bird she sometimes is smile

    //This is the descriptor for Alert One
    $name = 'theme_essential2/alert1info';
    $heading = get_string('alert1', 'theme_essential2');
    $setting = new admin_setting_heading($name, $heading, $information);
    $temp->add($setting);
    
    // Enable Alert
    $name = 'theme_essential2/enable1alert';
    $title = get_string('enablealert', 'theme_essential2');
    $description = get_string('enablealertdesc', 'theme_essential2');
    $default = false;
    $setting = new admin_setting_configcheckbox($name, $title, $description, $default, true, false);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);
    
    // Alert Type.
    $name = 'theme_essential2/alert1type';
    $title = get_string('alerttype' , 'theme_essential2');
    $description = get_string('alerttypedesc', 'theme_essential2');
    $alert_info = get_string('alert_info', 'theme_essential2');
    $alert_warning = get_string('alert_warning', 'theme_essential2');
    $alert_general = get_string('alert_general', 'theme_essential2');
    $default = 'info';
    $choices = array('info'=>$alert_info, 'error'=>$alert_warning, 'success'=>$alert_general);
    $setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);
    
    // Alert Title.
    $name = 'theme_essential2/alert1title';
    $title = get_string('alerttitle', 'theme_essential2');
    $description = get_string('alerttitledesc', 'theme_essential2');
    $default = '';
    $setting = new admin_setting_configtext($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);
    
    // Alert Text.
    $name = 'theme_essential2/alert1text';
    $title = get_string('alerttext', 'theme_essential2');
    $description = get_string('alerttextdesc', 'theme_essential2');
    $default = '';
    $setting = new admin_setting_configtextarea($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);

    // Alert Title - Welsh.
    $name = 'theme_essential2/alert1title_welsh';
    $title = get_string('alerttitle_welsh', 'theme_essential2');
    $description = get_string('alerttitledesc_welsh', 'theme_essential2');
    $default = '';
    $setting = new admin_setting_configtext($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);
    
    // Alert Text.
    $name = 'theme_essential2/alert1text_welsh';
    $title = get_string('alerttext_welsh', 'theme_essential2');
    $description = get_string('alerttextdesc_welsh', 'theme_essential2');
    $default = '';
    $setting = new admin_setting_configtextarea($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);
Average of ratings:Useful (1)
In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Saeed Amiri -

Hi Mary

I didn't know that the "settings" does not support "multilang" span. So now I have to think of making two settings per each alert? But, as you expected, "How will I do that?"

Meanwhile I do so some messing up with the setting.php file.

Thanks anyways!

Saeed

In reply to Saeed Amiri

Re: Essential Theme - User alert in RTL

by Mary Evans -

Hi Saeed,

You could try just adding a second text area for Persian like so...

FIRST open theme/essential/settings.php and make the following changes...

PLEASE NOTE: This makes changes to Alert 1 ONLY.
The greyed out code represents the PHP code which exists in
../theme/essential/settings.php already whereas the green highlighted code
represents the additions to the settings to enable two different language alerts
to work based on whether or not the user is using a RTL language or not.

    // Enable Alert
    $name = 'theme_essential/enable1alert';
    $title = get_string('enablealert', 'theme_essential');
    $description = get_string('enablealertdesc', 'theme_essential');
    $default = false;
    $setting = new admin_setting_configcheckbox($name, $title, $description, $default, true, false);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);

    // Alert Type.
    $name = 'theme_essential/alert1type';
    $title = get_string('alerttype' , 'theme_essential');
    $description = get_string('alerttypedesc', 'theme_essential');
    $alert_info = get_string('alert_info', 'theme_essential');
    $alert_warning = get_string('alert_warning', 'theme_essential');
    $alert_general = get_string('alert_general', 'theme_essential');
    $default = 'info';
    $choices = array('info'=>$alert_info, 'error'=>$alert_warning, 'success'=>$alert_general);
    $setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);

    // Alert Title.
    if (!right_to_left()) { //
    $name = 'theme_essential/alert1title';
    } else {
    $name = 'theme_essential/alert1title2';
    }
    $title = get_string('alerttitle', 'theme_essential');
    $description = get_string('alerttitledesc', 'theme_essential');
    $default = '';
    $setting = new admin_setting_configtext($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);


    // Alert Text.
    if (!right_to_left()) {
    $name = 'theme_essential/alert1text';
    } else {
    $name = 'theme_essential/alert1text2';
    }
    $title = get_string('alerttext', 'theme_essential');
    $description = get_string('alerttextdesc', 'theme_essential');
    $default = '';
    $setting = new admin_setting_configtextarea($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $temp->add($setting);

NEXT make a few changes to theme/essential/layout/frontpage.php


<!-- Start Alerts -->

<!-- Alert #1 -->
<?php if ($hasalert1) { ?>
 <div class="useralerts alert alert-<?php echo $PAGE->theme->settings->alert1type ?>">
    <a class="close" data-dismiss="alert" href="#">×</a>
    <?php

    if ($PAGE->theme->settings->alert1type == 'info') {
        $alert1icon = $alertinfo;
    } else if ($PAGE->theme->settings->alert1type == 'error') {
        $alert1icon = $alertwarning;
    } else {
        $alert1icon = $alertsuccess;
    }
    if (!right_to_left()) {
        echo $alert1icon.'<span class="title">'.$PAGE->theme->settings->alert1title.'</span>'.$PAGE->theme->settings->alert1text;
    } else {
        echo $alert1icon.'<span class="title">'.$PAGE->theme->settings->alert1title2.'</span>'.$PAGE->theme->settings->alert1text2;
    }  ?>
</div>
<?php } ?>

Hope this helps?

Cheers

Mary

Average of ratings:Useful (2)
In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

+1 Mary's solution! - Much neater than my remembering of what we'd done previously!!! :D

In reply to Richard Oelmann

Re: Essential Theme - User alert in RTL

by Mary Evans -

Indeed...I got to thinking last night, there is no need to duplicate all the other settings as those things like descriptions are the same anyway.

However looking at Gareths idea https://moodle.org/mod/forum/discuss.php?d=252664&parent=1096240, which I need to test and see how that works, as it would certainly open up a new avenue of thought about different language settings.

Cheers

Mary

In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Saeed Amiri -

Hi Mary and Richard

Thank you very much for taking the time to solve this problem. I will test the changes and report the outcome here.

Many thanks

Saeed

In reply to Saeed Amiri

Re: Essential Theme - User alert in RTL

by Saeed Amiri -

Hi Mary

Fantabulous!

I did not get how it works at first, but then I understood I need to change the language and enter my text for that particular language. I like it very much. Settings change with the change of language.

BTW, I think we need a very slight addition in syntax after the curly bracket in the frontpage added codes.

echo $alert1icon.'<span class="title">'.$PAGE->theme->settings->alert1title2.'</span>'.$PAGE->theme->settings->alert1text2;
}
?>

Thank you very much

Saeed

In reply to Saeed Amiri

Re: Essential Theme - User alert in RTL

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi,

To improve the solution even further you can use the 'current_language()' function.  Then postfix that to the setting name:

$name = 'theme_essential/alert1title_'.current_language();
....
$name = 'theme_essential/alert1text_'.current_language();

then you would not need the 'if' switch:

$name = 'alert1title_'.current_language(); 
$titlesetting = get_config('theme_essential', $name); 
$name = 'alert1text_'.current_language(); 
$textsetting = get_config('theme_essential', $name); 

echo $alert1icon.'<span class="title">'.$titlesetting.'</span>'.$textsetting;

Then will be language specific.

Cheers,

Gareth

 

In reply to Gareth J Barnard

Re: Essential Theme - User alert in RTL

by Mary Evans -

Did you test this Gareth? As I don't think that would work as I was under the impression that you need to have more than one text box for the data to be cached. But I might be wrong.

I need to try this out.

Thnaks

Mary

In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Oh, to be fair I did not test as used my minds Moodle emulator.

Concept is based upon some work in https://github.com/gjb2048/moodle-theme_shoelace/blob/en_ar_master/config.php.  And the fact that there is no caching in this case because the actual data is in the database, hence the 'get_config' call, so the cache is bypassed.  More of a PHP end dynamic data fetch concept.

In reply to Gareth J Barnard

Re: Essential Theme - User alert in RTL

by Mary Evans -

It doesn't work unfortunately. Pity really would have been a pretty good solution otherwise!

Back to the drawing-board! darn PHP code

Chees

Mary

In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Odd.  Time for a Shoelace proof of concept.

In reply to Gareth J Barnard

Re: Essential Theme - User alert in RTL

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Eee by gum lass, stop takin yee whippets for a walk and clap yer eyes on this: https://github.com/gjb2048/moodle-theme_shoelace/commit/8490efef542f974925858032b0bc55af78c69157 - thee trouble down tut mill = sorted smile

To test, download a copy of the theme from https://github.com/gjb2048/moodle-theme_shoelace/tree/MOODLE_26_MULTILANG_FOOTNOTE, install, go to the Shoelace settings and type in the footnote, save, change language, observe the footnote setting is blank, enter word appropriate to that language in the settings, save.  Then switch between languages observing the footnote words changing.

In reply to Gareth J Barnard

Re: Essential Theme - User alert in RTL

by Mary Evans -

There's truble in't Essential theme...never mind t'mill lad!

It ain't workin with thy codeification ideas above they station!

In reply to Mary Evans

Re: Essential Theme - User alert in RTL

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

LOL smile - I think I need to look at a copy of the code in its entirety.  Is it not bee thy footbridge above thy station? smile

In reply to Gareth J Barnard

Re: Essential Theme - User alert in RTL

by Julian Ridden -

You two are mad! :D

But should you find a working solution I am more than happy to bring it into the theme code.

Julian

In reply to Julian Ridden

Re: Essential Theme - User alert in RTL

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
In reply to Gareth J Barnard

Re: Essential Theme - User alert in RTL

by Saeed Amiri -

Hi Gareth

Was away for some time. Many thanks for the change!