## Filters: Multi-lingual Content

filter_multilangsecond
Maintained by Vanyo Georgiev
This filter is a more flexible version of multilang filter. One of three possible choices can be selected by the filter admin setting: HTML syntax, Non HTML syntax or Both. If the non html syntax is chosen language block looks like: {mlang en}English{mlang}{mlang bg}Bulgarian{mlang}. In case of Html syntax, language block is a sequence of identical html tags with lang="XX" attributes span or div or any other.
87
108
5

This filter is a more flexible version of Moodle multilang filter.

It has an admin setting filter_multilangsecond_mode.

One of three possible choices can be selected by this setting:

* HTML syntax
* Non HTML syntax or
* Both

In case of HTML syntax the language block is a sequence of identical
html tags with lang="XX" attributes:

<h1 lang="en" xml:lang="en">Heading in English</h1>
<h1 lang="bg" xml:lang="bg">Heading in Bulgarian</h1>

or

<p lang="en" xml:lang="en">Paragraph in English</p>
<p lang="bg" class="..." xml:lang="bg">Paragraph in Bulgarian</p>
<p lang="ro" xml:lang="ro">Paragraph in Romanian</p>

Note: In headings only the "official" multilang HTML syntax with <span class="multilang" lang="xx"> tags works. Example:
<span class="multilang" lang="en">English Title</span><span class="multilang" lang="bg">Заглавие на български</span>
This is because of removing of other html tags by format_string function.

The old syntax with <lang> tags is valid too.

In case of Non HTML syntax the language block looks like this:

{mlang en}English{mlang}{mlang bg}Bulgarian{mlang}

Each language dependent string is enclosed by {mlang xx} and {mlang}
elements. Between closing {mlang} element and the next opening
{mlang yy} element must not be any other symbols, or html tags. Avoid
to insert spaces, line or paragraph brakes between {mlang}{mlang yy}
elements in language blocks.

When the Both option is chosen for filter_multilangsecond_mode setting,
the filter processes the strings twice. First time to replace the non
HTML language blocks and second time to replace the HTML language
blocks. For performance reasons choose Both option only if you really
need both syntaxes.

If you find that this filter is not working with some string, check in the source code if this string is processed with format_string or format_text function before it is displayed. In not, correct the source code.

### Contributors

Vanyo Georgiev (Lead maintainer)
Please login to view contributors details and/or to contact them

• Thu, Sep 11, 2014, 4:27 AM
Hi David,

Another thing I would suggest is to try to use format_text() instead of format_string().
• Thu, Mar 5, 2015, 4:57 AM
Hello Vanyo,

first let me congratulate you on a great plugin! Very good job indeed.
I just installed the latest moodle release 2.8.3+ and I installed your plugin as well and It works great!

I have a question about it though. I don't know if it is something that your plugin can do or not but if it possible please tell me how it can be done.

I need to create a multilingual site with multilingual content. The content is in scorm and pdf format. Is it possible to add two activities, each containing a different translation of the same scorm/pdf and only the appropriate to be visible?

I have managed to only show the title and the description of the one that matches the selected language but the icon of the file still appears. Is it possible somehow to make that 'dissapear'?

I have a screenshot in case It's not clear what I mean.
(http://postimg.org/image/6qifk3onl/)

Thank you very much and keep up the great work!
• Mon, May 4, 2015, 12:43 AM
Hi Apostolos,

We do a lot of SCORM courses on multilingual Moodle sites. Our solution was to make your SCORM course multilingual as well instead of having two SCORM courses.

As for the files, ideally you should be able to simply put a restriction by user profile field however the Preferred Language field is unfortunately not included in the list of available profile fields. Your choices are to:

1) Make your PDF documents multilingual.

2) Link to your documents from a Label or Page type activity where you can wrap the URL in some {mlang} tags

3) Give the "Restriction by language" plugin by Renaat Debleu ( https://moodle.org/plugins/view/availability_language ) a try. This is only available for Moodle 2.7+. Don't forget to click the open eye to hide the activity if the condition is not meet.

Options #2 and #3 will both enable you to display content just in the users preferred language and #2 will enable you to even get rid of the icon if so desired.
• Fri, May 22, 2015, 8:55 PM
Just a quick note to confirm that the plugin seems to work for me on Moodle 2.8, 2.9 and 3.0-Alpha.
• Tue, May 26, 2015, 1:22 PM
If you change the "$plugin->requires =..." line in the plugin's version.php file to 2011033010, it actually is compatible all the way back to Moodle 2.0!!! • Fri, Aug 14, 2015, 2:22 PM Hello I installed your plugin but it not working in my site. I'm using moodle 2.9. Can you help me?? • Wed, Sep 2, 2015, 1:54 AM Hello, firstly, thank you very much for the wonderful plugin! I've installed on Moodle 2.9, and it's working great, with one exception. Within my 'Book' settings, I have the Name: field using nonHTML syntax, for example... {mlang en}Settings Tab{mlang}{mlang es}Ficha Configuración{mlang}{mlang pl}Zakładka Ustawienia{mlang}. This displays perfectly in each respective language, everywhere except at the top of each Chapter page. The full non-parsed string is being displayed. Any ideas? Thanks again! • Fri, Sep 11, 2015, 9:52 PM Hi Vanyo, let me add my thanks to others. I'm facing the same problems of Josh: as an example, I name cathegories and courses using {mlang xx}name in xx{mlang}{mlanh yy}name in yy{mlang} (Moodle 2.9.1; settings: nonHTML syntax, filter contents and headings). Categories are correctly displayed showing the name corresponding to the language selected. Instead, names of courses are correct when displayed within the list of categories, while the full non-parsed text is shown in the list of available courses (or in the list New courses displayed by the Klass theme I'm using). The same thing happens regarding block titles and other places, as the footnote in the footer, and the title and the description of front page for the theme (not on the front page summary, where the filter works nicely). You can give a look at the phenomenon opening https://mathverse.org/learn . Please help us solving the issue. Thanks • Fri, Sep 11, 2015, 10:04 PM Hello Alessandro, I actually found a solution to my problem that may also help in your case. Please see here: https://moodle.org/mod/forum/discuss.php?d=319398 . My recommendation for you would be, search your \learn\view.php file for cases of (just for example, variable names will be different): "$OUTPUT->variable($var->name);". Try changing this to: "$OUTPUT->variable(format_string($var->name));". This was the fix for me, and hopefully it is as simple as this for you as well. • Sat, Sep 12, 2015, 4:33 AM Thank you, Josh. After some work, I found that the issues are due to some multi-language support bugs in moodle and in the Klass theme. Concerning blocks one has to add calls to the function format_string() at lines 165 and 239, so as to have format_string($this->title) instead of $this->title, of file moodle//moodleblock.class.php. Concerning the Klass theme one has to substitute format_string($course->fullname) to \$course->fullname wherever it appears in file moodle/theme/klass/renderers/course_renderer.php

These fixes have been written here to help users of Multi-lingual Content filter, so they need not search everywhere for a solution. When I will have time to do it, I will also report the bugs and the fixes to the dedicated forums.
Bye
• Sat, Sep 12, 2015, 4:35 AM
Sorry, for bloks the file to be fixed is moodle/blocks/moodleblock.class.php instead of moodle//moodleblock.class.php (obviously).
• Fri, Oct 16, 2015, 3:19 AM
Hello,

Is it possible to use this plugin with fields on forms like on field "Course full name"? How?

The language portuguese Brazil (pt_br) must be used as {mlang pt_br}?

Thank you!

Darci
• Sat, Oct 17, 2015, 2:17 PM
Hello Darci,

I just published a new version. Please, try it. The problem you reported must be solved in this version.

Thank you for your comment!

Vanyo
• Fri, Nov 20, 2015, 12:25 AM
Hello Vanyo,

I'm using your filter a lot in my math site, but I have this problem: math formulae are written with the latex language and the MathJax filter translates them to a two dimensional representation (which is the one we humans are used to). The fact is that latex formulae need to use the curly bracket to apply some formatting, e.g. if I want to display the formula 1/(x+y) bidimensionally (that is, with the denominator standing under the numerator) I need to write $$\frac{1}{x+y}$$. The \frac command informs MathJax to put the first argument enclosed by {} (i.e. 1) over the fraction line and the second argument (i.e. x+y) under it. When I put such formulae between {mlang XX} and {mlang} because they need to be inserted into the text, the presence of the curly brackets breaks down the functionality of your filter. Can you please make your filter more robust allowing to insert these brackets inside the text?

Thanks

Alessandro
• Fri, Nov 20, 2015, 12:30 AM
Oh, I forgot: I could use your filter in the HTML-mode, but students would undoubtedly prefer to use the {mlang} construct instead of delving into the HTML code they don't know...

Alessandro