## Filters: Multi-Language Content (v2)

filter_multilang2
Maintained by Iñaki Arenaza, Iñigo Zendegi Urzelai, Kepa Urzelai
This filter is a greatly simplified multi-language filter. It uses very simple non-HTML tags to mark multi-language blocks. Namely {mlang XX} {mlang} pairs, where XX is the Moodle short name for the language pack (i.e., en, fr, eu, es, es_mx, etc.) It uses the same tags as the filter_multilangsecond plugin (to be compatible with it), but there is one difference between the two. This filter allows standalone {mlang} tags that don't require adjoining alternative language tags. This makes the filter more flexible at the cost of potentially producing empty sets of tags.
1438 sites
43 fans
Moodle 3.4, 3.5, 3.6, 3.7, 3.8, 3.9

# To Install it manually

• Unzip the plugin in the moodle .../filter/ directory.

# To Enable it

• Go to "Site Administration >> Plugins >> Filters >> Manage filters" and enable the plugin there.

# To Use it

• Create your contents in multiple languages.
• Enclose every language content between {mlang NN} and {mlang} tags:
    {mlang XX}content in language XX{mlang}
{mlang YY}content in language YY{mlang}
{mlang other}content for other languages{mlang}
• where XX and YY are the Moodle short names for the language packs (i.e., en, fr, de, etc.) or the special language name 'other'.
• Version 1.1.1 and later: a new enhanced syntax to be able to specify multiple languages for a single tag is now available. Just specify the list of the languages separated by commas:
  {mlang XX,YY,ZZ}Text displayed if current lang is XX, YY or ZZ, or one of their parent laguages.{mlang}
• Test it (by changing your browsing language in Moodle).

# How it works

• Look for "lang blocks" in the text to be filtered.
• For each "lang block":
• If there are texts in the currently active language, print them.
• Else, if there exist texts in the current parent language, print them.
• Else, as fallback, print the text with language 'other' if such one is set.
• Text outside of "lang blocks" will always be shown.

## Definition of "lang block"

Is any text (including spaces, tabs, linefeeds or return characters) placed between '{mlang XX}' and '{mlang}' markers. You can not only put text inside "lang block", but also images, videos or external embedded content. For example, this is a valid "lang block":

{mlang es,es_mx,es_co}
First paragraph of text. First paragraph of text. First paragraph of text.

Second paragraph of text. Second paragraph of text. Second paragraph of text.

An image could go here

Third paragraph of text. Third paragraph of text. Third paragraph of text.

An embedded Youtube video could go here

Fourth paragraph of text. Fourth paragraph of text. Fourth paragraph of text.
{mlang}


## A couple of examples in action

### Using text only

This text:

  {mlang other}Hello!{mlang}{mlang es,es_mx}¡Hola!{mlang}
This text is common for all languages because it's outside of all lang blocks.
{mlang other}Bye!{mlang}{mlang it}Ciao!{mlang}
• If the current language is any language except "Spanish International", "Spanish - Mexico" or Italian, it will print:
  Hello!
This text is common for all languages because it's outside of all lang blocks.
Bye!
• If the current language is "Spanish International" or "Spanish - Mexico", it will print:
  ¡Hola!
This text is common for all languages because it's outside of all lang blocks.
• Notice the final 'Bye!' / 'Ciao!' is not printed.
• If the current language is Italian, it will print:
  This text is common for all languages because it's outside of all lang blocks.
Ciao!
• Notice the leading 'Hello!' / '¡Hola!' and the final 'Bye!' are not printed.

### Using text, images and external embedded content

We create a label with the content shown in the following image:

The "lang block" tags are highlighted using blue boxes. You can see that we have three pieces of content: the Spanish-only content (light yellow box), the language-independent content (light blue) and the English-only content (light red).

If the user browses the page with English as her configured language, she will see the common content (light blue box) and the English-only content (light red):

If the user browses the page with Spanish as her configured language, she will see the Spanish-only content (light yellow) plus the common content (light blue box):

### Contributors

Iñigo Zendegi Urzelai

### Awards

• Tue, Oct 16, 2018, 10:14 PM
Dear Iñaki,

do you thinking about extension your filter with something like default wording. In case, that you have content in EN and CZ for example, and user has selected some other language, he gets emptz string.

• Thu, Feb 21, 2019, 11:34 PM
Dear Iñaki, thank you for the beautiful and very useful plugin! We use it on a bilingual moodle 3.5 site with courses and glossary. The issue is with the bilingual glossary entries which do not show in the mouse- over tooltip as expected. So my question is: does the plugin work with tooltips showing content of glossary terms in the course text? In our case the tooltip is showing the full string with the mlang's instead of the respective language only.

• Mon, Mar 25, 2019, 7:17 PM
Dear Iñaki,

I tried to insert a "drag and drop into text" question into my moodle course using your plugin. The translation of the quotation text works well but the choice text (which are the drag texts) are visualised like "{mlang DE}Text DE{mlang}{mlang EN}Text EN{mlang}".

Am I doing anything wrong? Or have I to consider something else?

Best regards
Christian
• Mon, Mar 25, 2019, 11:13 PM
@Стоян Дренски

That's actually a bug in the glossary filter and module. The glossary filter adds the glosarry entry concept as is, without trying to filter it first. So the multilanguage filter can't even try to do its jobs. And something very similar happens when you click on the auto-linked glossary entry: the AJAX call doesn't try to apply the filters to the entry concept and definition, so the multilang filter is not called, and you get the raw original string (wit all the {mlang} tags, etc.).

Applying the patch available at https://gist.github.com/iarenaza/cd5bb7c766e457caa73e73298bcbf31b should fix the issue (patch is for latest 3.5 version, so line numbers might change a bit depending on exact 3.5 version).
• Tue, Mar 26, 2019, 12:20 AM
Dear @Christian Putzenlechner,

I'm afraid you are not doing anything wrong. It's simply that the "drag and drop into text" question type (and I suspect other drag and drop question types too) are not multi-language ready. The multi-language filters (all of them, including mine) can only work if the texts to be displayed are passed through the filtering mechanisms (usually format_string() and format_test() functions).

I've seen that the "drag and drop into text" question type doesn't use those mechanisms in a few places. But in this particular case, the problems are deeper. Because when you do something like the following to define a question:

{mlang en}Question EN: gap 1 \[\[1]] , gap 2 \[\[2]]{mlang}{mlang DE}Question DE: gap 1 \[\[1]] , gap 2 \[\[2]]{mlang}

the drag and drop into text question type stores the question as this (at least in Moodle 3.5):

{mlang en}Question EN: gap 1 \[\[1]] , gap 2 \[\[2]]{mlang}{mlang DE}Question DE: gap 1 \[\[3]] , gap 2 \[\[4]]{mlang}

As you can see, it renumbers the second language gaps, in effect making the question have more gaps than intented! This later means that when you are presented with the question in a single language (e.g., EN), you can only fill in two gaps (because there only appear two empty gaps!). So from grading point of view, you have a partially correct question, because you didn't fill in all the gaps!

As I sais before, this is a deep issue in that question type and I suspect it needs changes in quite a few places. I don't master the quiz/questions code at all, so I'd say it's better to open a Moodle bug in the official tracker and try to get the issue fixed there by the official maintainers.

Saludos.

Iñaki.
• Fri, May 31, 2019, 4:24 PM
i check the docs but i can't find the information :
can the plugin support multilang in the tag ?
example : can we write " {mlang DE EN FR} OK {mlang } " instead of writing :
{mlang DE} OK {mlang }
{mlang FR} OK {mlang }
{mlang FR} OK {mlang }
• Fri, May 31, 2019, 10:51 PM
Hello Pierre:
AFAIK, it is not possible, but you could have a workaround: since the plugin defaults if it doesn't find the string in the appropriate language, you could define a string for those cases, something like:
{mlang ES} Bien {mlang }
{mlang EN} OK {mlang }

And if you log in in FR or any other language installed and it can't find the language, it will use whatever language you have as default for the platform

Cheers
• Sat, Jun 1, 2019, 1:41 AM
Hi Pierre and Brandon,

the official version of the plugin doesn't have that feature. But there is an additional git branch (called wip-master-langlist) that has it: https://github.com/iarenaza/moodle-filter_multilang2/tree/wip-master-langlist

I am a bit reluctant to make that feature part of the official plugin, but I have been maintaining it up to date in sync with the official one so far. It is the one that I called the "extended" version in a Nov 2016 comment. Then I said that I didn't expect that the "extended" version of the plugin would fall out-of-date, given that it is 85-90% of the same code as the standard one, and I've kept both in sync since then. So no hard guarantees, but several people have been using it since then.

Saludos.
Iñaki
• Tue, Aug 13, 2019, 2:52 AM
Hi Iñaki, just in case it might be useful, have you considered adding a setting to your plugin which would enable or disable the extended feature? That way you would not need to maintain a separate extended version.
• Tue, Aug 13, 2019, 5:33 AM
For anyone upgrading to Moodle 3.7 or later, I noticed that the following might affect your multilingual site:

When you were using a localized languages such as French Canda (fr_ca) in versions of Moodle up to and including 3.6, you used to be able to use the syntax:
{mlang fr_ca}content{mlang} OR {mlang fr-ca}content{mlang} OR {mlang fr}content{mlang}

As of Moodle 3.7, you can only use the following syntax:
{mlang fr}content{mlang}

This doesn't appear to be a result of a change in the plugin but rather in Moodle.

Doesn't bother me (I am not considering this an issue). If it is a big problem for you, you might have better luck with the https://moodle.org/plugins/filter_multilangsecond plugin. I have not used that one in several years. The code works differently so it might be more backwards compatible with your site.

Best regards,

Michael Milette
• Thu, Oct 10, 2019, 4:30 PM
Hi Iñaki Arenaza,
We have implemented this plugin in our LMS Site, it was working good with the all custom pages.But we are facing some issue with the front page Slider Caption.It was not supporting the tags you mentioned.I have mentioned the exact output which we are receiving.

NOTE:
We are using our own custom theme.

Output:
{mlang en}XXXX YYYY ZZZZ {mlang}

Am I doing anything wrong? Or have I to configure something else?

Best regards
Muthuswamy
• Tue, Mar 24, 2020, 3:14 PM
Hello. Thank you for this amazing plugin. I have just one problem. I'd like to use it to "dataform" or "database" plugin, especially for the options(of select or menu). But I found out that it doesn't work. How can I deal with it? Thank you.
• Tue, Mar 24, 2020, 8:53 PM
Hi Lee Megan,

I have been digging a bit in the "dataform" plugin code, and it is clearly an issue in it. When rendering the contents of a select-type field, it doesn't call "format_tring()" on the entries to display. It that function is not called, no filtering plugins are applied (of which filter_multilang2 is just one). I verified it by adding these 3 lines of code before this line: https://github.com/itamart/moodle-mod_dataform/blob/master/field/select/classes/renderer.php#L206

foreach ($options as$key => $val) {$options[$key] = format_string($val);
}

I didn't check the rest of the field types, but I wouldn't be surprised it the calls to "format_string()" or "format_text()" (depending on the type of content to show in each case) are missing too. So you should open a bug in the dataform plugin bug tracker and let the maintainer know about this issue.

Saludos.

Iñaki.
• Thu, Apr 16, 2020, 3:04 AM
Pro Tip: For anyone who is having trouble getting it working, please test in a page or a the content area of an HTML block first using the Boost or Classic theme. Until it is working in one of these two places with the Boost theme, it is not configured correctly or enabled. You can then switch to a 3rd party theme or other plugins. If the same page or block no longer works, you know the problem is with your theme or plugin and not Moodle or the Multi-Language Content (v2) plugin. Hope you find this tip helpful.
• Wed, Jul 8, 2020, 8:25 PM
FYI: I tested it and it seems to work well with Moodle 3.9.