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:
1912 sites
1k downloads
48 fans
Current versions available: 3

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
  • 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?

    Thank you in advance
    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.
  • Thu, Aug 20, 2020, 6:35 PM
    i have a problem with multi lang add on.
    While it is working with books, pages, headings etc. it does not work with course summary.
    Any suggestions?
  • Sat, Aug 22, 2020, 12:50 AM
    Hi @Valadis Kefalis

    As suggested by Michael Milette, are you testing it with the Boost or Classic theme? Many non-core themes have issues with filters in general (not just multilang2, but any filter). So before digging further, can you confirm that it doesn't work in the course summary if you use the Boost or Classic theme?

    Saludos.

    Iñaki.
  • Thu, Nov 19, 2020, 9:23 PM
    Hi! I want to know whether this plugin is available by default in any of the version of Moodle or I need to install it separatelly every time I want to upgrade the Moodle version? I can not find this information (or I don't know where to search ;) ). Thank you for help in advance.
  • Thu, Nov 19, 2020, 9:40 PM
    Hi Oktawia,

    All the plugins of the plugin database (and this one too) are non-standard plugins, so you'll have to install them in addition to the Moodle core on every Moodle instance you want to use it.
  • Tue, Jan 5, 2021, 12:28 AM
    Hi!
    I have a question about this plugin according to course names. I'm using this plugin to create a platform fully displayed in 9 different languages. How can I apply this to course names? I know that it is working - I checked based on 2-3 languages, but the field is too short to type all 9 languages. Is there any way of how I can overcome this issue? Maybe you have some tips for me how can I make it possible to apply all of the 9 languages?
    Thank you for any advices and information in advance!
  • Tue, Jan 5, 2021, 3:54 AM
    Unfortunately it is not easily possible to expand the course name field. It would require you to make and maintain at least two customizations in Moodle, one to increase the size of the field in the database and the other to modify the size of the field for the course name. Note that you may encounter similar limitations in other parts of Moodle.

    For more information on this issue and some workarounds, see https://tracker.moodle.org/browse/MDL-70556
  • Fri, Feb 12, 2021, 11:04 PM
    Hello Iñaki, Iñigo and Kepa,

    Your plugin is absolutely amazing. Thank you so much for this.
    I am using it with the Edwiser RemUI theme and Edwiser's course formats. In some areas such as course description in the list of all courses, the {mlang} tags do not work. Instead you see the entire string unfiltered, i.e. {mlang en}Let's study together{mlang}{mlang ja}一緒に勉強しましょう{mlang}.

    Reading the comments here it seems like it may be an issue with the Edwiser course formats and theme not calling specific functions or missing something in their code that can display your plugin. I would like to ask them about this and if they can fix it.

    Can you please advise what your plugin requires in their code to properly display? I do not know how to describe it to them so they can see if it is something they can fix on their side.

    Thank you in advance.
  • Fri, Feb 12, 2021, 11:12 PM
    Hi Raymond,

    This plugin only require the call of the standard functions to apply the filters in Moodle, usually format_string or format_text.
1 2 3 4 5
Please login to post comments