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:
3786 sites
1k downloads
74 fans
Current versions available: 4

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
  • Mon, Feb 6, 2023, 6:45 PM
    Hi, Michael,

    Regarding the issue with the course index: we knew about it (https://github.com/iarenaza/moodle-filter_multilang2/issues/34) but weren't 100% sure it was a core issue, now that it has been confirmed we've directed it to the Moodle Tracker.

    Thank you!
  • Mon, Mar 13, 2023, 4:41 PM
    Hi
    Is there a way to support tags with this plugin? It does not seem to work...
    BR
    David
  • Tue, Mar 14, 2023, 11:20 PM
    Hi @David,

    The plugin does support any content or resource type that calls format_string() or format_text() to render itself on the final page. The plugin doesn't do anything special to support each different type or content or resource type.

    As a proof of concept, you can check the standard Moodle language filter. If the standard filter works with tags, then this plugin should work (it it doesn't, then it's clearly a bug in the multilang2 plugin). If it doesn't work with the standard filter, there is no way multilang2 can work.

    Saludos.

    Iñaki.
  • Sat, Apr 15, 2023, 4:02 AM
    Hello Iñaki:

    Thank you for the great work here. I am running version 4.1 (Build: 20221128). I am having trouble with a translation working in a lesson. In specific, it is a matching page. The "Matches with answer" field appears as it is written in the drop down menu options.

    {mlang en}Torah{mlang} {mlang es}Torá{mlang}

    I read in this thread that drag and drop questions had issues. Is this also the case for matching questions page?
    Any ideas for a solution?
    Muchas gracias y saludos,
    José
  • Sat, Apr 15, 2023, 10:32 PM
    Hola José,

    with a 99.999% probability, this is a bug in the lesson module. Unfortunately, multi-language filter support (not just for our plugin, but for the standard official Moodle one) is not 100% functional even in Moodle "core" code (not to speak about 3rd party plugins). Just as an example, the various issues already mentioned in this thread (drag and drop questions, course menu, resource tags, etc.)

    To verify that is is not the 0.001% case, you can enable the standard multi-lang plugin and use its syntax in that particular lesson. If you still get the original HTML (and not the filtered result), then the problem is in the Moodle lesson module. If you get the correctly filtered result, then it's a bug in our plugin.

    Recibe un saludo cordial.

    Iñaki.
  • Mon, Apr 17, 2023, 10:05 PM
    Hola Iñaki:

    Thank you for responding so promptly. I will do as you suggest and find out where the issue resides.
    Un saludo cordial y muchas gracias,
    José
  • Sun, Apr 23, 2023, 2:20 AM
    Hi I am trying to use this in course summary, however it is breaking the UI, as it is adding additional bold or strong tags, setting the width itself for those in columns, like i hv 2 columns one is 60 and other 40, so after adding this for course summary for 4 languages it is making 40 as 10 in width, any suggestions
  • Sun, Apr 30, 2023, 9:58 PM
    Hi @Rudraksh Batra

    I can assure you this plugin doesn't add any tags whatsoever to the content that you yourself enter. It simply selects the portion of the content you specified for the language that Moodle is using to display that page at that moment.

    So whatever is painted there, it's either you who put it there, or some other code: either Moodle's core code, or another plugin's code.
  • Mon, May 1, 2023, 11:59 AM
    FYI: Tested it on Moodle LMS 4.2. Works for me!
  • Sun, May 28, 2023, 11:52 AM
    Hi @Iñaki

    Thanks for replying.

    Now i am trying to use the same in quiz, however it is not getting applied. any specific setting other than filter content and heading.

    pls advise
  • Sun, May 28, 2023, 9:22 PM
    Hi Rudraksh,

    If a filter works in one place in Moodle but not another, there is usually one of two reasons.

    1) there is a typo in the tag (check the HTML view for invisible characters if using Atto or TinyMCE); or

    2) The component you are using does not support filters yet. This is not a problem with the filter. In your case, try changing question type to one that does support filters.

    Filters are supported in most but unfortunately not all of Moodle yet. For example, I know for a fact that they are not supported in some types of quiz questions and not supported in H5P activities either. If it really doesn't work in a particular place in Moodle, it may be possible to get it fixed. You will need to determine who the owner is of the component and request that the filter functionality be added. If this is a core Moodle question type (i.e. it came with Moodle), you can report this as a bug at https://tracker.moodle.org or fix it yourself and submit the fix for integration into Moodle core. For 3rd party question types, you will need to contact the developer using the link on the plugin's page.

    Alternatively, create a unilingual quiz for each language and use the Restriction by Language plugin found at https://moodle.org/plugins/availability_language . This will enable you to display language-specific quiz activities based on the current UI language. It works with all types of activities and resources. One of the down sides to this is that learners will not be able to switch language within the activity.

    You might want to consider following up with quiz-related questions in the Moodle Quiz Discussion forum at https://moodle.org/mod/forum/view.php?id=737

    Hope you found this information helpful.

    Best regards,

    Michael Milette
  • Tue, Jun 20, 2023, 12:19 AM
    Hello Iñaki and others:

    Just a quick note to let you know that I have opened an issue in Jira for the problem with Lessons activity not working with Matching questions with the Multilang content 2. It has been identified by others as well. For those of you interested in following this issue or voting on it, the tracking is:

    https://tracker.moodle.org/browse/MDL-78481

    Hoping for a prompt resolution. Regards and thank you!
    José Balcells
  • Thu, Aug 17, 2023, 5:05 AM
    Just a quick note to say that I have just published version 2.0.0 of the plugin, which officially supports 3.11, 4.0, 4.1 and 4.2.

    A big shout-out to Michael Millete, Luca Bösch and Petr Skoda, that contributed the majority of the fixes and enhancements!

    Saludos.

    Iñaki.
  • Wed, Aug 23, 2023, 5:19 PM
    A very useful tool – I am disappointed though that it does not work in the page footer.
  • Wed, Aug 23, 2023, 8:52 PM
    Hi Martin,

    This is not an issue with the filter. It does work in page footers but it depends on the theme you are using.

    If it is not working in your theme, contact your theme's developer and ask them to fix it. It is usually a pretty quick fix but it must be done by a programmer.

    If you have the skills to do it yourself, the content to be displayed needs to be passed through the format_string() or format_text() functions which are part of the Moodle Output API. More information is available at https://moodledev.io/docs/apis/subsystems/output#output-functions

    Hope you find this helpful.

    Best regards,

    Michael Milette
1 2 3 4 5 6 7
Please login to post comments