Moodle plugins directory: Multi-lingual Content | Moodle.org
Multi-lingual Content
This filter is a more flexible version of Moodle multilang filter.
It has an admin setting filter_multilangsecond_mode.
One of three possible choices can be selected by this setting:
* HTML syntax
* Non HTML syntax or
* Both
In case of HTML syntax the language block is a sequence of identical
html tags with lang="XX" attributes:
<h1 lang="en" xml:lang="en">Heading in English</h1>
<h1 lang="bg" xml:lang="bg">Heading in Bulgarian</h1>
or
<p lang="en" xml:lang="en">Paragraph in English</p>
<p lang="bg" class="..." xml:lang="bg">Paragraph in Bulgarian</p>
<p lang="ro" xml:lang="ro">Paragraph in Romanian</p>
Note: In headings only the "official" multilang HTML syntax with <span class="multilang" lang="xx"> tags works. Example:
<span class="multilang" lang="en">English Title</span><span class="multilang" lang="bg">Заглавие на български</span>
This is because of removing of other html tags by format_string function.
The old syntax with <lang> tags is valid too.
In case of Non HTML syntax the language block looks like this:
{mlang en}English{mlang}{mlang bg}Bulgarian{mlang}
Each language dependent string is enclosed by {mlang xx} and {mlang}
elements. Between closing {mlang} element and the next opening
{mlang yy} element must not be any other symbols, or html tags. Avoid
to insert spaces, line or paragraph brakes between {mlang}{mlang yy}
elements in language blocks.
When the Both option is chosen for filter_multilangsecond_mode setting,
the filter processes the strings twice. First time to replace the non
HTML language blocks and second time to replace the HTML language
blocks. For performance reasons choose Both option only if you really
need both syntaxes.
If you find that this filter is not working with some string, check in the source code if this string is processed with format_string or format_text function before it is displayed. In not, correct the source code.
I want to use your new filter on an existing site that is currently using the default multilang filter included with Moodle.
When I tried it, I could not have it filter both my old HTML syntax and the new non-HTML syntax at the same time.
To support for both the old multilang syntax,for existing content and the new non-HTML syntax, I have to keep the old multilang and the new multilansecond filters enabled. Is this by design?
If by design, could you please add an option to have both ways of filtering enabled at the same time so that I don't have to enable both multilang and multilangsecond at the same time?
It is difficult to create a filter to support 2 completely different syntaxes. That is why I decided to make multilangsecond with an option to choose only one of them. So you have to keep 2 filters for, one for HTML syntax and one non-HTML syntax.
I've been using your plugin exclusively and have been delighted with how well it works.
However today I tried the following and discovered that it didn't work much to my disappointment. I was really hoping to be able to have just large language blocks one after the other.
{mlang en}
This is a test
{mlang}
{mlang fr}
Ceci est un test.
{mlang}
The tags are ignored and everything displays.
Is there anything you can do to make it work in this situation?
Best regards,
Michael
Sorry for my late answer!
Remove the paragraph break and any white space between {mlang} and {mlang fr}.
Try:
{mlang en}
This is a test
{mlang}{mlang fr}
Ceci est un test.
{mlang}
This works.
Great Filter! Thank you for your work I've noticed that when I use the following syntax - everything works perfectly.
<h1 lang="en" style="background-color: #0066cc; color: #ffffff;">English header</h1>
<h1 lang="fr" style="background-color: #0066cc; color: #ffffff;">French header</h1>
<h2 lang="en"></h2>
<h2 lang="fr"></h2>
<p lang="en">English Paragraph1.</p>
<p lang="fr">French Paragraph1.</p>
<h2 lang="en"></h2>
<h2 lang="fr"></h2>
<p lang="en">English Paragraph2</p>
<p lang="fr">French Paragraph2</p>
<h2 lang="en"></h2>
<h2 lang="fr"></h2>
<p lang="en">English Paragraph3</p>
<p lang="fr">French Paragraph3</p>
But, if I use this syntax - the filter does not work - both languages show.
<h1 lang="en" style="background-color: #0066cc; color: #ffffff;">English header</h1>
<h1 lang="fr" style="background-color: #0066cc; color: #ffffff;">French header</h1>
<p lang="en">English Paragraph1.</p>
<p lang="fr">French Paragraph1.</p>
<p lang="en">English Paragraph2</p>
<p lang="fr">French Paragraph2</p>
<p lang="en">English Paragraph3</p>
<p lang="fr">French Paragraph3</p>
Is this to be expected? I'm happy to be using the first method. Or perhaps it would it be better to use <br /> tags to create the paragraph breaks?
<p lang="en">English Paragraph1.</p>
<p lang="fr">French Paragraph1.</p>
<p lang="en">English Paragraph2</p>
<p lang="fr">French Paragraph2</p>
<p lang="en">English Paragraph3</p>
<p lang="fr">French Paragraph3</p>
so it is not identified as a multilingual block by the filter.
You can change this to:
<div lang=”en”>
<p>English Paragraph1.</p>
<p>English Paragraph2</p>
<p>English Paragraph3</p>
</div>
<div lang=”fr”>
<p>French Paragraph1.</p>
<p>French Paragraph2</p>
<p>French Paragraph3</p>
</div>
and the filter will work.
Your suggestion worked. As long as the {mlang}{mlang fr} are together and not on separate lines, it works perfectly!
Thanks again!
Michael
I have another challenge for your plugin. I have text that is being generated from PHP. Unfortunately two text sequences of {mlang} appear immediately one after the other on the same line. As a result, they don't get filtered. Here is my test text which demonstrates the problem:
{mlang en}Testing{mlang}{mlang fr}Essais{mlang}{mlang en}: Completed.{mlang}{mlang fr} : Complété.{mlang}
If there was a space of a line-break between {mlang}{mlang en}, it works but unfortunately I don't have control over that. Any suggestions you might have would be much appreciated.
Best regards,
Michael
I made a new release 1.1 of this filter.
The main new feature of this release is the support of both html and non html syntaxes.
And another change makes the filter to work in cases that the previous version did not work, for example with a language block like:
{mlang en}Testing{mlang}{mlang fr}Essais{mlang}{mlang en}: Completed.{mlang}{mlang fr} : Complété.{mlang}
or:
<p lang="en">English Paragraph1.</p>
<p lang="fr">French Paragraph1.</p>
<p lang="en">English Paragraph2</p>
<p lang="fr">French Paragraph2</p>
<p lang="en">English Paragraph3</p>
<p lang="fr">French Paragraph3</p>
Best regards!
Vanyo