Problems with multilang filter and SPAN tags

Problems with multilang filter and SPAN tags

by Tom Hogan -
Number of replies: 4
We need to use the multilang filter to have content in both English and Korean. However, it seems that some SPAN tags break the filter somehow.

Just one SPAN tag seems fine. For example,
<span lang="en" class="multilang">
English text in <span style="font-weight: bold;">bold</span>.
</span>
<span lang="ko" class="multilang"> Korean text in <span style="font-weight: bold;">bold</span>.
</span>
Prints English text in bold and Korean text in bold respectively.

This was problematic. I tried it first and it did not work. Then, as I copied it here and re-tested, I may have removed a space somewhere and suddenly it worked...!

<span lang="en" class="multilang">
English text in <span style="font-weight: bold;">bold</span>
and then some <span style="color: rgb(255, 0, 0);">red</span>.
</span>
<span lang="ko" class="multilang">
Korean text in <span style="font-weight: bold;">bold</span>
and then some <span style="color: rgb(255, 0, 0);">red</span>.
</span>

However, this does not work at all:

<span lang="en" class="multilang">
<span class="nolink">
<h1>Help</h1>
</span>
Help in English
<h2>Classroom Basics</h2>
</span>
<span lang="ko" class="multilang">
<span class="nolink">
<h1>Help</h1>
</span>
Help in Korean
<h2>Classroom Basics</h2>
</span>

This only prints the Korean text, even when the English interface is chosen.

Is this a bug?
More importantly: is there a workaround for this in the interim while the bug is being fixed? Some of our content does not work very well now, especially where we try to avoid autolinking by using <nolink>, because Moodle automatically turns it into <span class="nolink">

Thanks,
Tore
Average of ratings: -
In reply to Tom Hogan

Re: Problems with multilang filter and SPAN tags

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Hi Tore,
your problems are caused because you nested <span>...</span> tags.

When the multilang filter finds the first <span lang="xxx" class="multilang"> it tried to find the next </span> tag, and assumes t his is the end of that "multilang" block. When you have nested <span> ... </span> tags, then the "multilang" filter will assume the "multilang" block finishes before you want it to.

To work around this, you can specify the outer tags as something else, for example <lang lang="en" class="multilang"> ... </lang> would work on Moodle 1.7, and I think <lang lang="en"> ... </lang> will work on Moodle 1.8.

I while back I suggested a modification to Moodle to allow "smarter" detection of the start and end tags. I encourage you to vote for, because it will help you with what you are trying to do. Please see MDL-8357.

all the best
Gordon


Average of ratings: Useful (2)
In reply to Gordon Bateson

Re: Problems with multilang filter and SPAN tags

by Tom Hogan -
Hi Gordon,

Thanks for a speedy and useful reply! I am a bit confused, because the problem seems so inconsistent. All the three examples I mentioned have equally nested tags, so why does it break in the third, intermittently in the second, and not at all in the first?

I tried your 1.8 workaround, but it did not work. When I enter this:
<lang lang="en">
<span class="nolink">
<h1>Help</h1>
</span>
Help in English
<h2>Classroom Basics</h2>
</lang>
<lang lang="ko">
<span class="nolink">
<h1>Help</h1>
</span>
Help in Korean
<h2>Classroom Basics</h2>
</lang>

Moodle saves it as this:
<lang lang="en">
<span class="nolink">
<h1>Help</h1>
</span>
Help in English
</lang>
<h2>Classroom Basics</h2>
<lang lang="ko">
<span class="nolink">
<h1>Help</h1>
</span>
Help in Korean
</lang>
<h2>Classroom Basics</h2>
For some reason, it wants the </lang> tag before a <h2>. As a result, the display breaks again dead

In the interim I have found that the filter also breaks with Wiki links.
If you have text between the multilang span tags that contain Wiki links to an as-yet uncreated wiki page, the filter breaks. If you actually make the pages, the filter works again. surprise

I have voted in the tracker, so fingers crossed!
In reply to Tom Hogan

Re: Problems with multilang filter and SPAN tags

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I think the <lang> tag gets moved by the HTML editor, before it sends everything off to Moodle.

You can switch off the HTML editor in your user profile by setting "When editing text" to "Use standard web forms". Then you can go back to edit the multilang block and put the <lang> tags where you want them.

all the best
Gordon
In reply to Gordon Bateson

Tárgy: Re: Problems with multilang filter and SPAN tags

by Deni Nagy -
Hello Gordon,

I know this is a quite old topic here so I hope it has already been already solved. Unfortunately selecting standard web forms doesn't help either... sad

It daesn't matter if I use lang or span, both stop at a higher or same level tag (div, p or span) whatever I do to them. I also tried to make the hack described in MDL-8357. But even that didn't work out.

Do you have any ideas to solve this problem? I use 1.9 B2 version.

Thanks in advance!

Deni