Filters: Multi-Language Content (v2)

filter_multilang2
Maintained by Picture of Iñaki ArenazaIñaki Arenaza
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.
913 sites
729 downloads
36 fans

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}
  • Where XX and YY are the Moodle short names for the language packs (i.e., en, fr, de, etc.)
  • Test it (by changing your browsing language in Moodle).

How it works

  • Look for "lang blocks" in the code.
  • For each "lang block":
    • If there are texts in the currently active language, print them.
    • Else, if there exists texts in the current parent language, print them.
    • Else, don't print any text inside the lang block.
  • Text outside of "lang blocks" will always be shown.

Definition of "lang block"

A 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}
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}

One example in action

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

Picture of Iñaki Arenaza
Iñaki Arenaza (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Richard Samson
    Tue, Apr 17, 2018, 4:49 PM
    Hi!

    We use this great plugin. Thank you!

    I want to report a possible incompatibility with the html button for the ATTO editor. We were having trouble with an issue:

    https://moodle.org/mod/forum/discuss.php?d=369155#p1488384

    Our computing boffins have finally managed to find the incompatability (though not the underlying cause).

    It turns out that there seems to be some interference between the HTML toolbar button and the multilang2 toolbar button in ATTO.

    In the ATTO toolbar configuration dialogue, you have to load html before multilang2.

    In other words,

    other = fullscreen,preview,multilang2,html
    doesn't work
    other = fullscreen,preview,html,multilang2
    works

    Is there a bug in the multilang2 code? Or somewhere else?

  • Picture of Iñaki Arenaza
    Fri, Apr 20, 2018, 5:30 AM
    Hi Richard,

    just to mention that this plugin (filter_multilang2) is *not* related to Atto in any way wink This is a filter plugin, and works irrespective of the editor you use to produce your content (Atto, TinyMCE or any other).

    The Atto multi-language plugin ( which is available at https://moodle.org/plugins/atto_multilang2 ) is the one you seem to be having trouble with. That plugin produces the markup that is later processed by this plugin, but otherwise are completely independent.

    Anyhow, I also co-maintain the Atto multi language plugin so I can try to help you debug your issue. We can either move the discussion to the Atto multi language plugin page, or you can send me a direct message here in moodle.org.

    Saludos.
    Iñaki
  • Picture of Bert van der Hooft
    Fri, Jun 8, 2018, 4:35 PM
    Hi,

    Is it possible to automatic link to activities which names are multilingual? Now not working.

    Bert
  • Picture of Michael Milette
    Tue, Jul 31, 2018, 2:53 AM
    I haven't tried it Bert and there are a lot of dependencies however, I suspect that if you move the Multi-Language Content (v2) filter below the Activity names auto-linking filter, the activity names might get linked first and then the language filter will remove the extra languages. Be sure to only apply the {mlang} tags to the link's text, exactly as you specified it in the course's name. Don't put whole links in mlang tags. Let us know if it works.
  • Picture of Rheman Pessek
    Fri, Sep 14, 2018, 12:23 PM
    hi everyone,

    Great plugin,

    But how to translate course title ?

    best regard,

  • Picture of Jan Wohlgemuth
    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.

  • Picture of Стоян Дренски
    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.


  • Picture of Christian Putzenlechner
    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?

    Thank you in advance
    Best regards
    Christian
  • Picture of Iñaki Arenaza
    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).
  • Picture of Iñaki Arenaza
    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.
  • Picture of pierre REMY
    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 }
  • Picture of Brandon Jimenez
    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
  • Picture of Iñaki Arenaza
    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
  • Picture of Michael Milette
    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.
  • Picture of Michael Milette
    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
1 2 3 4
Please login to post comments