Content in different language

Content in different language

by Ilona El -
Number of replies: 11

Hello!!! 

I would like to achieve the following:

I have text within 

<?php if (!isloggedin() or isguestuser()) { ?>

<p> text </p>

<?php } ?>

so that my users can see diferrent text when logged in or logged out.

Now I would like the text that appears to the logged in users to variegate depending on the chosen language. That is why I used this

<?php if (!isloggedin() or isguestuser()) { ?>

<p style="text-align: center;"><strong><span lang="en" class="multilang">english text</span><span lang="el" class="multilang">greek text</span></strong></p>

<?php } ?>

however this doesn't seem to work (within frontpage.php file)

Any suggestions please? Tnx for your time!

Average of ratings: -
In reply to Ilona El

Re: Content in different language

by Robert Brenstein -
You have two options

1. put your string, I mean the <span lang="en" class="multilang">english text</span><span lang="el" class="multilang">greek text</span> into a variable and then run it through the format_string() function.

2. put the text of your string into one of the language files in all your language packs and fetch through the get_string() function.

The second option allows you to modify the strings or add new language strings without having to go into the code, but it is more effort to set things up.
Average of ratings: Useful (1)
In reply to Robert Brenstein

Απάντηση: Re: Content in different language

by Ilona El -

Mmmmm... well.. I think I will need your help on doing this... I can understand that the first choice is easier... could you please provide me with further guidelines on how to create such a variable and then run it through the function? 

Tnx for your time & assistance!

In reply to Ilona El

Re: Απάντηση: Re: Content in different language

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Actually there is a better way but it would involve changing your two themes if you are still using Overlay (Text) & Overlay (Graphics).

The work here would involve adding a setting to the theme that would allow the Admin to add a notification in whatever languages you need to add it.  It could also be set to be visible before or after login.

If this is what you think you want then tell me and I will see if I can dig out the code to do this.

Cheers

Mary

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

Re: Απάντηση: Re: Content in different language

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

This is an amendment to the settings.php in the Overlay (text_ theme I made for you.

    // Welcome setting.
    $name = 'theme_overlay_text/welcome_'.current_language();
    $title = get_string('welcome','theme_overlay_text');
    $description = get_string('welcomedesc', 'theme_overlay_text');
    $default = get_string('welcometxt', 'theme_overlay_text');
    $setting = new admin_setting_confightmleditor($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $settings->add($setting);

That bit of code allows you to type different languages into the settings page dependent on the language selected at the time of adding the text into the settings page. In other words it stores both languages but only displays the text depending on what language it is.

So first you select English in the Lang menu and type the message in English. Then save that setting.

Next you change language to Greek go to the settings page and type in the message in Greek and save.

Go to Frontpage and after changing the language in the Lang menu the message will be displayed depending on the language you have set. At least that is how it is supposed to work.

Hope this helps?

Cheers

Mary

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

Απάντηση: Re: Απάντηση: Re: Content in different language

by Ilona El -

Mary!! Your posts are always really helpful! Thank you very much for your time. 

The moodle site I am trying to edit now is not the one that has the two themes (overlay text and overlay graphics). 

So is there a way the solution you mention above works within overlay theme too, where welcome text doesn't exist?

 

In reply to Ilona El

Re: Απάντηση: Re: Απάντηση: Re: Content in different language

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

No you need to add the setting. Gareth knows more about this as it was a solution he found in another theme!

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

Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Content in different language

by Ilona El -

OK Mary thank  you!! 

So I am trying to make the changes within overlay text theme. I changed the settings.php file adding the code you mentioned [  $name = 'theme_overlay_text/welcome_'.current_language();  ]. After that within frontpage.php file I added 

<div class="region-content">

<?php if (!isloggedin() or isguestuser()) { ?>

      <!-- START WELCOME MESSAGE -->

      <?php if ($haswelcome) {

            echo $PAGE->theme->settings->welcome;

                } else {

                     echo '';   } ?>

        <!-- END WELCOME -->

<?php } ?>

   <?php echo $OUTPUT->main_content() ?>

 </div>

Then I entered "Overlay text" theme settings and typed within "welcome frame" -> check english text (while being in English language mode). After saving this, I changed to Greek language mode. The "welcome frame" was empty so I entered -> check greek text and saved it. 

However I think I am missing something since I can only see the default message when not logged in:

Hello World!

Here we can add the text which will differentiate from the other theme. 

Overlay Text will be based on text

no matter which language I choose. When I loggin the welcome text doesn't appear (this is ok).

Any suggestions?  

In reply to Ilona El

Re: Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Content in different language

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

The welcome text is added via the area in the setting page for Overlay theme yes?

Site Administration > Appearance > Themes > Overlay Text settings link 

This is where you need to add the English version of the welcome message and then save then change language and go to 

Site Administration > Appearance > Themes > Overlay Text settings link and type welcome message in Greek. Then save and check that the massage is there in Greek. You do Not need multilingual span for this it should work without as the text is saved in database.

Once you see the message. Change back to English and the eng version should then be visible.  

If this is not working then 

I will need to do some testing as I may have missed a step out.

In reply to Mary Evans

Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Content in different language

by Ilona El -

Mary unfortunatelly this doesn't seem to work. 

Yes, the welcome text is added via the area in the setting page for Overlay text theme (Overlay text settings). However, when I type welcome text while being in english language and then change to greek, the welcome text remains the same. ..

In reply to Ilona El

Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Content in different language

by Ilona El -

Any news on this please ? 

In reply to Ilona El

Re: Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Απάντηση: Re: Content in different language

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

I sent you an email earlier today...did you get it? I want to send you the Overlay Text theme which has the language setting in it, but wanted to check if your email is the correct one.

Can you check you SPAM/JUNK mail box just in case? smile

Thanks

Mary