Custom page with multi lang support

Custom page with multi lang support

by Rafael Roijackers -
Number of replies: 6

Dear Users,

I'm trying to create a custom support page, were students can find how to configue their computer for some courses. But I need to create it in 3 languages. This is what I currently have:

<?php

require_once('../config.php'); require_login();

$PAGE->set_context(get_system_context());
$PAGE->set_pagelayout('admin');
$PAGE->set_title("OEM Support Center");
$PAGE->set_heading("Support Center");
$PAGE->set_url($CFG->wwwroot.'/oem-pages/support.php');

echo $OUTPUT->header();
?>
<p>
<span lang="nl" class="multilang">your_content_here</span>
<span lang="de" class="multilang">your_content_in_other_language_here</span>
</p>
<?php
echo $OUTPUT->footer();
?>

But this doesn't work. I think I need to embed the Multilang FIlter, but how can I do it? Thank you for your help.

Average of ratings: -
In reply to Rafael Roijackers

Re: Custom page with multi lang support

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you want your text to run through the multilang filter, then you need to call format_text() on it.

e.g.

$mytext = '<p>
<span lang="nl" class="multilang">your_content_here</span>
<span lang="de" class="multilang">your_content_in_other_language_here</span>
</p>';

echo format_text($mytext);

But really, if you're wanting to output different text in different languages and you're not using a text editor to enter the text in the front end, then it would be a lot simpler simply to write:

$lang = current_languate();

if ($lang == 'nl') {
  echo '<p>nl content</p>';
} else if ($lang == 'de') {
  echo '<p>de content</p>';
}

Or if the text is fixed, why not make use of the built-in fix language string support:

echo get_string('mycontent', 'myplugin');

Then, in your plugin's language strings (lang/en/myplugin.php, lang/de/myplugin.php, etc.), add the following:
$strings['mycontent'] = 'The content you want, in each relevant language';


Average of ratings: Useful (2)
In reply to Davo Smith

Re: Custom page with multi lang support

by Rafael Roijackers -

Thank you for your help. Because it will be a long text I've used this function:


$lang = current_language();

if ($lang == 'nl') {
  echo '<p>nl content</p>';
} else if ($lang == 'de') {
  echo '<p>de content</p>';
}

Instead of the echo, I used the include command. And I've created 2 files with the content in their own language. At the frontend the user only sees 1 pages, but in the backend the editing is much easier.

In reply to Rafael Roijackers

Re: Custom page with multi lang support

by Alexander Bias -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Rafael,

as you would write plain HTML in your custom support page anyway, you might be interested in our plugin https://moodle.org/plugins/local_staticpage which lets you display HTML content as a static Moodle page and which support multilanguage content out of the box.

Cheers,
Alex

Average of ratings: Useful (1)
In reply to Alexander Bias

Re: Custom page with multi lang support

by Rafael Roijackers -

Thank you for the idea. But we're using an iomad implementation of Moodle 3.3. So I don't know if this plugin will be supported by Iomad or that the Iomad part will give trouble.

In reply to Rafael Roijackers

Re: Custom page with multi lang support

by Alexander Bias -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Rafael,

I don't know much about Iomad, I can only tell you that the plugin is currently used on approx. 1.400 sites worldwide and that we haven't received any problem reports about Iomad yet. 

Cheers,
Alex

In reply to Alexander Bias

Re: Custom page with multi lang support

by Rafael Roijackers -

Thank you for the advice. Maybe I will check this plugin in the future.