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:
4878 sites
2k downloads
91 fans
Moodle 4.1, 4.2, 4.3, 4.4, 4.5, 5.0

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:

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 RSS

Show comments
  • Ian Rogers
    Thu, 30 May 2024, 3:22 AM
    Does it support Moodle 4.4+ yet?
  • Iñigo Zendegi Urzelai
    Tue, 4 Jun 2024, 9:55 PM
    Hi Ian,

    As far as we've tested the plugin works fine on Moodle 4.4.
  • Dominic Gospodnetich
    Mon, 1 Jul 2024, 3:02 AM
    Hey there,

    I've been using this plugin for a bit and It's been great, but I'm running into an issue in specifically the mobile app. For some reason if course content is in a 'page' then it will only display in English. This applies to just the body text in the page, Course titles and everything else on the UI will switch language but body text does not. I wasn't able to find anyone else having this issue so I figured I would ask here. The web version works completely fine, and mobile works outside of individual pages in a course. Let me know if I'm missing something here, and thanks for the plugin!
  • Iñaki Arenaza
    Wed, 3 Jul 2024, 6:35 AM
    Hi Dominic,
    if the plugin is working for the web version, and is working for the mobile version except for individual pages, then the problem is on the mobile app. The filter implements a single function, that does exactly the same thing in all cases.

    This has been the case in more cases than I can remember: some moodle code (either from Moodle core, or a third party plugin) renders a piece of code without calling the functions needed to apply the filters (namely format_text() and format_string(), and the equivalen ones in Javascript land). And so the filter is not applied.

    In one occasion, the problem was slightly different, and maybe that is your case too? The code calling the filtering functions didn't set the user language properly before doing the call, so the filter ended up using the wrong language for the filtering.

    Saludos.
    Iñaki.
  • Dave Foord
    Thu, 11 Jul 2024, 3:22 PM
    @Dominic - I have also spotted the same issue, in that the mlang tags appear to have stopped working in the Mobile app (I am sure they were working in the app before). I will report this as a bug on the mobile app page.
  • Dave Foord
    Thu, 11 Jul 2024, 8:46 PM
    I have reported the above issue to Moodle HQ - https://tracker.moodle.org/browse/MOBILE-4629
  • Dave Foord
    Fri, 12 Jul 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 Jul 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 Jul 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 Jul 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 Jul 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 Jul 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
1 2 3 4 5 6 7 8 9 10
Please login to post comments