Multilanguage in Drag and Drop Question

Multilanguage in Drag and Drop Question

by John Gourlay -
Number of replies: 15
In the drag and drop into text question, neither the standard moodle <span lang="en" class="multilang"> or the multi-language content V2 plugin {mlang en} filters appear to work in the choices part of the question. They both work within the Question text.

The standard moodle filter shows both languages with a box around the currently chosen language (UI). Only the boxed version moves if dragged.

The V2 plugin show both languages and both move when dragged...

Moodle 4.1.1
multi-language content V2 plugin 2.0.1

Known issue, or am I missing something....?
 
Average of ratings: -
In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hello John. You might like to comment on this tracker issue MDL-61286 to push it along a bit?
In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello John,

Here is a simple workaround solution.

Language set to English

MoodleForum_20240209_0415.png

Language set to French

MoodleForum_20240209_0416.png?time=1707470975967

In reply to Dominique Bauer

Re: Multilanguage in Drag and Drop Question

by John Gourlay -
Thanks Dominique.

The multilang parts work fine in the question, just not in the choices. Try replacing London with {mlang en} English {mlang} {mlang fr} Français {mlang} and you will see what I mean.



Apparently this is a known issue, according to Mary Cooch.

On another note, I PM'd you a while ago about getting access to the year in the formula question type, and sent a copy of the exam. Not sure if you received it...

John
In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

John,

You're right, multilingual doesn't work in the choices, I'm aware of that. It's a known issue, and there's already Tracker MDL-61286➚ for it (as Mary mentioned), in which there were some discussions in 2018, then nothing until 2022, and nothing since then.

In the Tracker, the problem is classified as a minor bug. Clearly, fixing the issue doesn't seem to be a priority and could take several more years.

While waiting for the problem to be resolved, I propose a workaround solution that offers the advantages of being extremely simple to implement and working like a charm. It simply involves including a small JavaScript code that displays the choices, for example, in French when the course is set to French.

Here's a screenshot of my example question's settings:

MoodleForum_20240209_1758.png

Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Multilanguage in Drag and Drop Question

by John Gourlay -

Dominique:

 Thank you for the code. I am struggling to make it work…

 

Top of HTML:

<html dir="ltr" lang="fr-ca" xml:lang="fr-ca" class="yui3-js-enabled">

 

I have this set for javascript  in the header portion of additional HTML. Works for other Javascript code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

 

The question:


<span lang="en" class="multilang">Drag and drop the following in order of precedence:</span>

<span lang="fr" class="multilang">Faites glisser et déposez les éléments suivants par ordre de privilège :</span>

<br><br>

<p dir="ltr" style="text-align: left;">1. 1<br></p>

<p dir="ltr" style="text-align: left;">2. 2<br></p>

<p dir="ltr" style="text-align: left;">3. 3<br></p>

<p dir="ltr" style="text-align: left;">4. 4<br></p>

<p dir="ltr" style="text-align: left;">5. 5<br></p>

<hr>

 

<script>

    $(document).ready(function() {

        $("body.lang-fr span:contains('Vessel not answering the helm')").text("Navire dont la barre ne répond plus");

        $("body.lang-fr span:contains(Tug with a 200m tow)").text("Remorqueur avec remorque de 200 m");

        $("body.lang-fr span:contains(Freighter in a dredged channel)").text("Cargo dans un chenal dragué");

        $("body.lang-fr span:contains(Vessel casting nets)").text("Navire lançant des filets");

        $("body.lang-fr span:contains(Vessel under sail but using the engine to charge the batteries (transmission not engaged))").text("Navire à la voile qui utilise le moteur pour recharger les batteries (transmission non enclenchée)");

    });

</script>


 


My site default language is en_ca.

I have tried:

·        body.lang-fr

·        body.lang-fr_ca

·        body.lang-fr-ca

Is there something else I am missing?


John

In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello John,

Try instead with:

$("html[lang='fr-ca'] span:contains(Vessel not answering the helm)").text("Navire dont la barre ne répond plus");

etc.

In reply to Dominique Bauer

Re: Multilanguage in Drag and Drop Question

by John Gourlay -
No joy. I put a window.alert(document.body.id) in to ensure that the script was in fact running and to show me it was finding the right id. But I can't pull out the right attribute within it or the <html...> You can see all these in the attached xml copy of the question.

John
In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello John,

The issue stems from the fact that the "Drag and drop into text" question inserts non-breaking spaces between words when there are several words within the same choice. Removing them isn't too difficult, by adding a few lines of code, in order to easily spot the choices and translate them. Note that the space indicated in yellow in the code below is the invisible non-breaking space character that you must insert by pressing Alt+255 on a Windows computer.

Non-breaking spaces are intended to keep each choice on a single line even if it is long. In your case, the choices are not very long, so I did not insert non-breaking spaces between the translated words in order to keep the code as simple as possible. It would be easy to add them if necessary.

I've also added some code to translate the correct answer in case you need it.

I think that the French and French-Canadian language packs, "fr" and "fr-ca," are largely identical. I use the French language pack. If you're using the French-Canadian language pack, you'll need to change "fr" to "fr-ca" in the code. You'll also notice that I've used the "Multi-Language Content (v2)➚" plugin which I believe works better than the other version.

I have sent you by private email the XML file of your modified and working question. Don't forget to change "fr" to "fr-ca" and to restore the Alt-255 character if it did not survive the Moodel-XML-Moodle conversion.


// REMOVE HARD SPACES FROM CHOICES

    $(".answercontainer span.draghome").each(function(){
        str = $(this).text();
        str = str.replaceAll(" "," ");
        $(this).text(str);
    });
In reply to Dominique Bauer

Re: Multilanguage in Drag and Drop Question

by John Gourlay -
Thank you Dominique.

I had installed the .xml file and was testing it by changing the language settings on my site. So I found it worked when I selected fr alone, and so then tried fr-ca with fr_ca language pack. So it works if I use the right search coupled with the right language setting.

Then I read your email...  wink

Anyway. Thank you for that. Will play some more. It is a lot more effective a question type for what I am trying to do than the drop down selection as it is immediately clear which choices they have used and they can easily change the order.

John
In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

John,

I'm not sure I understood you correctly. I hope it finally works for you. You will find the latest minor changes and an example where you can change the display language, at https://dynamiccourseware.org/course/view.php?id=119&section=4&lang=en➚.

In reply to Dominique Bauer

Re: Multilanguage in Drag and Drop Question

by John Gourlay -
Sorry Dominique. I should have been clearer. Yes it works. If I had read your email first I would have saved myself a couple of hours experimenting with language settings and purging caches. But I still learned something...  smile

Thank you again.

John
In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by John Gourlay -
About using {mlang en} and {mlang fr}, I make use of cloze questions a lot.

{mlang en_ca}{1:MULTICHOICE:~%100%One~Two}

{mlang}{mlang fr_ca}{1:MULTICHOICE:~%100%Un~Deux}{mlang}<br>

displays properly but as you can only answer one of the two questions, it says you are partially correct.


{1:MULTICHOICE:

~%100%{mlang en_ca}One{mlang}{mlang fr_ca}Un{mlang}

~{mlang en_ca}Two{mlang}{mlang fr_ca}Deux{mlang}

}<br>

{1:MULTICHOICE:

~{mlang en_ca}%100%One{mlang}{mlang fr_ca}Un{mlang}

~{mlang en_ca}Two{mlang}{mlang fr_ca}Deux{mlang}

}

both give Ce type de question requiert au moins 2 réponses.

When I started out I thought I would use the old style <span...> multilanguage format as it was native to Moodle (trying to avoid too many plugins). It seems to be more forgiving in that it accepts en or fr and displays properly, rather than requiring that I use en_ca and fr_ca. But I also am finding that it just works... I will probably start to use the {mlang} version in a number of areas, particularly when I run into the 255 string length limit, and it will be nice for allowing people, whose eyes will glaze over if confronted with html, to do some of the work on the site.

In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Good news! I just realized that there's a much simpler workaround!

  • Provide options like "[1]", "[2]", etc.
  • Add the following script to the HTML code of the question (see the attached question for more details):

    $("span:contains([1])").text("{mlang en}Text in English{mlang}{mlang fr}Texte en français{mlang}{mlang es}Texto en español{mlang}");
    $("span:contains([2])").text("{mlang en}Text in English{mlang}{mlang fr}Texte en français{mlang}{mlang es}Texto en español{mlang}");
    etc.

That's it! I tested it quickly and it seems to work like a charm! It should also be less daunting. (The simplicity of the workaround leads me to believe that the fix for the issue might not be so complicated after all, but I could easily be mistaken about that.)

You can try an example at https://dynamiccourseware.org/course/view.php?id=119&section=3➚.

In reply to Dominique Bauer

Re: Multilanguage in Drag and Drop Question

by John Gourlay -

Hi Dominique:

Thanks for your solutions.

I have been playing (always dangerous) and building on what you have sent me. I have been able to use snippets of your code to have the Drag and Drop on Text work with the question (almost) normally. I have attached it if you want to perhaps make it a little more elegant and add it to your collection.

As it is, you can complete the question using the normal Choices fields. The Choices and the feedback will be displayed in the language of the page (with a caveat, see below). So, course creators don't have to play with html and JavaScript if they don't want to.

The script will respect the language of the Choices if you code the {mlang} tag properly. In that respect, it is no different that the rest of Moodle. So, you should be able to use any supported language.

And I figured out  a workaround for the non-breaking space issue I think...

Things I have noticed about Drag and Drop:

  • The standard Moodle multilanguage tags are stripped out immediately, so you can't use them in the Choices. (<span lang="XX" class="multilang">) I spent a lot of time playing until I figured that out…

Caveats:

  • This script will only work with the Multi-language content V2 plugin in the Choices. It doesn’t seem to care in the questions.
  • This script is sensitive to the language setting you use in the question. I think it should probably match what is set on your site. On mine, which is currently using en_ca, if I code the question as {mlang en}, the feedback response is normal. If I code it as {mlang en_ca} it brings in the English version of the question in the form: The correct answer is: Question in English before it displays the correct answers.  If I code it as {mlang fr} or {mlang fr_ca} it always brings in the French version of the question before the answers. (I notice the same quirk with the solutions you provided…) I have not been able to find an elegant way to edit this out. I think that it is perhaps more of an irritant at this point. The (".feedback .rightanswer… area seems to include the script, so editing it is not trivial. As a bonus, the script area moves around within the feedback area depending on whether you put the script at the top or the bottom of your html.

(I think I had some more erudite things I was going to say, but it is late and they have leaked away…)

Anyway, thank you again for all your support.

John


In reply to John Gourlay

Re: Multilanguage in Drag and Drop Question

by John Gourlay -
Dominique:

An updated, commented version that looks for {mlang language-country} first, before looking for {mlang language} and fixes a coding error I missed... (that 4 should have been a 5, but it probably would have caused other problems....)

John