Multi-Language Content (v2)

Filters ::: 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.
Latest release:
5370 sites
1k downloads
95 fans
Current versions available: 5

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 XX} and {mlang} tags (also known as a "language blocks"):
    {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, en_CA, en_kids, fr_ca, 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. E.g.,:
  {mlang en,es,fr_ca}Text displayed if the user's active language is en, es or fr_ca, or one of their parent languages.{mlang}
  • Test it (by changing your browsing language in Moodle

How it works

In the descriptions below, "the user's active language" refers to the language that the user has configured as the active browsing language at a given moment. It can be the language that the user has configured in his or her profile, or the language that the user has temporarily set by choosing a different browsing language from Moodle's language menu.

Default behaviour

  • Look for language blocks in the text to be filtered.
  • For each language block:
    • If there are texts in the user's active language, print them.
    • Else, if there exist texts in any parent language(s) of the user's active language, unless the parent language is 'en', print them. This behaviour is configurable in version 2.0.5 and later (see "Configurable parent languages behaviour" below).
    • Else, as fallback, print the text with language other if such one is set.
    • Else, don't print any text inside the language block.
  • Text outside of language blocks will always be printed.

Configurable parent languages behaviour

Since version 2.0.5, the plugin offers a setting to configure how the filter will behave when processing a language block, with respect to parent languages.

As stated above, the filter determines whether a text in a language block should be displayed or not based on the language(s) specified in the block, and the user's active language. This matching process can follow three different approaches, known as "parent languages behaviour". The sections below describe each of the available parent language behaviours.

Always use parent languages, excluding 'en'.

This is the default setting. The filter takes the user's active language (e.g., en_us_kids12) and computes its parent languages list. When computing the parent languages list, en is never included in that list. E.g, for en_us_kids, the parent languages list would only include en_us (even if en is the parent langauge of en_us, as en is always excluded from the parent languages list in this case). But for fr_ca_kids12, the parent languages list would include fr_ca and fr.

The filter then checks if any of the languages specified in the language block matches either the user's active language, or any of the languages in the parent languages list. If any match if found, the language block is printed. If no match is found, the language block is not printed.

Example 1: If the user's active language is en_us_kids12, the parent languages will include en_us only (as en will always be excluded in this behaviour). Thus, a language block like {mlang en_us_kids12}Some content in en_us_kids12{mlang} will be printed. And so will a language block like {mlang en_us}Some content in eu_us{mlang}. But a language block like {mlang en}Some content in en{mlang} will not be printed. Because en is excluded from the list of parent languages and thus will not match the language block's language.

Example 2: If the user's active language is fr_ca_kids12, the parent languages will include fr_ca and fr. Thus, a language block like {mlang fr_ca_kids12}Some content in fr_ca_kids12{mlang} will be printed. And so will a language block like {mlang fr_ca}Some content in fr_ca{mlang} and a language block like {mlang fr}Some content in fr{mlang}.

Note: English can still be used explicitly in the language block. But the text of that language block will only be printed when the user's active language is exactly en.

Always use parent languages, including 'en'.

This setting works like the previous one, but it doesn't exclude the en language from the list of valid parent languages of the user's active language.

Example 1: If the user's active language is en_us_kids12, the parent languages will include en_us and en (as with this setting, en is not excluded from the list of valid parent languages). Thus, a language block like {mlang en_us_kids12}Some content in en_us_kids12{mlang} will be printed. And so will language blocks like {mlang en_us}Some content in en_us{mlang} or {mlang en}Some content in en{mlang}.

Example 2: If the user's active language is fr_ca_kids12, the parent languages will include fr_ca and fr. Thus, a language block like {mlang fr_ca_kids12}Some content in fr_ca_kids12{mlang} will be printed. And so they will language blocks like {mlang fr_ca}Some content in fr_ca{mlang} or {mlang fr}Some content in fr{mlang}. But a language block like {mlang en}Some content in fr{mlang} will not be printed. Because in this case, the en language is not a parent language of fr_ca_kids12 (only fr and fr_ca are).

Never use parent languages.

As the name suggests, no parent languages are ever used. The filter only matches the languages explicitly listed in the language block to the user's current language, without considering any parent languages.

Example: If the user's active language is fr_ca_kids12, a language block like {mlang fr_ca_kids12}Some content in fr_ca_kids12{mlang} will be printed. But language blocks like {mlang fr_ca}Some content in fr_ca{mlang} or {mlang fr}Some content in fr{mlang} will not be printed.

Definition of a language block

It is any text (including spaces, tabs, linefeeds or return characters) placed between '{mlang XX}' and '{mlang}' markers. You can not only put text inside a language block, but also images, videos or external embedded content. For example, this is a valid language 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 language 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 language 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 language 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 language 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:

Multi-Language content in Spanish, English, an language-independent content

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):

Multi-Language content when browsed in English

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):

Multi-Language content when browsed in Spanish

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2

Contributors

Iñaki Arenaza (Lead maintainer)
Iñigo Zendegi Urzelai
Please login to view contributors details and/or to contact them

Comments

Show comments
  • Dave Foord
    Thu, 11 July 2024, 8:46 PM
    I have reported the above issue to Moodle HQ - https://tracker.moodle.org/browse/MOBILE-4629
  • Dave Foord
    Fri, 12 July 2024, 5:44 PM
    It turns out that the issue that I raised regarding this, is a non-issue - in that the mlang tags are working correctly. The key when testing, is if you have already visited an item (e.g. a book) in one language, and then you change your preferred language within your Moodle preferences, we have to re-download that book on the mobile app in order for the change to get actioned. What was happening before, was I was viewing a cached version of the book showing the old language, rather than the book showing the correct language.
  • Sandra Stickelmann
    Thu, 3 Apr 2025, 2:48 PM
    Hi,
    thanks a lot for this plugin - just one question:
    Normally, a user only sees the language he/she should see.
    If I use the search function however, the result shows the complete coded text, such as {mlang de}Verifizierung{mlang}{mlang en}Verification{mlang}.

    Are the tags not working when using the search-function?
  • Dave Foord
    Thu, 3 Apr 2025, 3:38 PM
    @Sandra - I ahve checked on the Moodles that I support, and I am seeing exactly the same as you - which does suggest that the tags are not working within the search function. This is probably an issue with the search function, rather than this plugin (e.g. the search function doesn't recognise any filters). I have posted to the general developer forum, to see if anyone else has any ideas here:

    https://moodle.org/mod/forum/discuss.php?d=467266
  • Dave Foord
    Fri, 4 Apr 2025, 3:01 PM
    @Sandra - I have created a ticket for this issue at https://tracker.moodle.org/browse/MDL-85108 - hopefully someone will pick this up, and get a fix sorted soonish. If others are interested, please vote for the ticket.
  • Melvyn Gomez
    Thu, 24 July 2025, 8:45 AM
    I'm using moodle 4.5.4 and all the notifications popup and via email using this sintax {mlang es}{mlang} are not working, all the text is not being filtered, i found some places outside of the plugin to apply the patch and use format_string and format_text but it can be a plugin bug or core bug?
  • Dave Foord
    Thu, 24 July 2025, 2:21 PM
    @Melvyn - is your issue that:

    a) the mlang tags are not working at all, or
    b) is it just that the {mlang es} is not working, but other languages are working?

    If a) then certain areas in Moodle don't support filters at all, so they won't work, and not much we can do apart from raise a ticket for someone to look into this and make filters work in that area.

    If b) then first thing to check is that you have Spanish available as one of the languages in the site. If that is avaialble, then something I spotted once was the {mlang es} tags were not working within a certain context (I forget which), when other languages were working. What I found was I had to rearrange the order of the filters - effectively moving the {mlang} filter down the list until it worked.
  • Melvyn Gomez
    Thu, 24 July 2025, 2:45 PM
    my bad Dave, i mean the tags in general are not working, not only spanish, for example is not working in the popup notification and when you want to see the full notification message, i found that error is in the file /message/output/popup/classes/popup_notification.php, function export_for_template and line $context->shortenedsubject = shorten_text($context->subject, 125); must be $context->shortenedsubject = shorten_text(format_text($context->subject, FORMAT_HTML), 125);

    Other issue is in the file /mod/assign/classes/notification_helper.php, funcion send_due_soon_notification_to_user and this code
    $stringparams = [
    'firstname' => $user->firstname,
    //'assignmentname' => $assignmentobj->get_instance()->name, //old code wrong
    //'coursename' => $assignmentobj->get_course()->fullname, //old code wrong
    'assignmentname' => format_string($assignmentobj->get_instance()->name, true, ['context' => $context]), //new code
    'coursename' => format_string($assignmentobj->get_course()->fullname, true, ['context' => $context]), //new code
    'duedate' => userdate($duedate),
    'url' => $url,
    ];

    but that's only for viewing purposes, in the email notification, the tags are not working, before worked in Moodle 4.1, i'm getting emails like this
    Due on Tuesday, 22 July 2025, 23:59: {mlang es}Actividad preparatoria: Análisis de una negociación subóptima{mlang}{mlang pt_br}Atividade preparatória: Análise de uma negociação subótima{mlang}{mlang en}Preparatory activity: Analysis of a suboptimal negotiation{mlang}

    All the due notifications and their lang tags are not working; so maybe is not a core issue, is a plugin glitch, what do you think?
  • Dave Foord
    Thu, 24 July 2025, 2:54 PM
    @Melyvn - we will need to wait for one of the plugin owners/developers to answer your question, as this goes beyond my level of understanding.

    In terms of the pop up issue - I know for example that if you use the glossary autolinking set up, the header of that doesn't currently support filters, so it may be that the message pop up also doesn't. A useful way to test this, is to apply a different filter in an item and see if that works or not. If all filters don't work, then you know it is a 'core' issue. If other filters work, but {mlang} doesn't then it is probably a plugin issue.

    Can I check - within the 'manage filters' page on your site, is the Multi-Language Content (v2) filter set to 'Content and Headings' or just 'Content'. If it is just set to 'Content' then change it to 'Content and Headings' and see if that helps.
  • Iñigo Zendegi Urzelai
    Thu, 24 July 2025, 3:07 PM
    Hi, Melvyn

    Those Moodle 4.5 notification messages not applying correctly the filters are Moodle core code bugs, and there are already two issues in the Moodle Tracker working to solve them (both already have fix proposals):
    https://moodle.atlassian.net/browse/MDL-85802
    https://moodle.atlassian.net/browse/MDL-85684
  • Davide Vigano
    Fri, 5 Sept 2025, 7:44 PM
    Ciao!
    Vorrei sapere se è possibile non visualizzare gli {mlang} nei risultati delle ricerche in Moodle 4.5.5. Grazie!
  • Davide Vigano
    Fri, 5 Sept 2025, 7:44 PM
    Hello!
    I would like to know if it is possible to hide {mlang} in search results in Moodle 4.5.5. Thank you!
  • Iñaki Arenaza
    Sat, 6 Sept 2025, 4:41 PM
    Hi @David,

    I'm sorry, but there is nothing that the multilang2 plugin can do about it. Filter plugins can only filter text that is sent to the user (browser, mobile app, emails), and only when asked to do so. It is the responsability of the search engine to either ignore or hide the `{mlang}`filter markers (and other filters' markers too, if relevant).

    Saludos.
    Iñaki.
  • John Gourlay
    Sat, 28 Mar 2026, 10:19 PM
    Wondering what, if anything, has changed - Not honouring: Multi-Language Content (v2) "Always use parent languages, including 'en'" ?

    https://moodle.org/mod/forum/discuss.php?d=473743

    John
  • Iñaki Arenaza
    Fri, 3 Apr 2026, 10:55 PM
    Hi John,

    except for language pack changes, nothing has change in the code since version 2.5.0. That was published on 2024.11.27. Even if we take the language pack changes into account, version 2.5.0.2 (the latest one) was published on 2025.04.17 (nearly a year ago). And nothing has changed in the plugin since then.

    I don't know what plugin version, and what Moodle version you are using, so it's difficult to diagnose what could be going on. If you are using a very recent Moodle version (that we may have not tested yet), there could have been changes in Moodle core that broke that functionality?

    Saludos.

    Iñaki.
1 2 3 4 5 6 7 8 9 10
Please login to post comments