Your Moodle version

Filters: Multi-lingual Content

filter_multilangsecond
Maintained by Picture of Vanyo Georgiev Vanyo Georgiev
This filter is a more flexible version of multilang filter. One of three possible choices can be selected by the filter admin setting: HTML syntax, Non HTML syntax or Both. If the non html syntax is chosen language block looks like: {mlang en}English{mlang}{mlang bg}Bulgarian{mlang}. In case of Html syntax, language block is a sequence of identical html tags with lang="XX" attributes span or div or any other.
Moodle 2.3, 2.4, 2.5, 2.6

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>

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.

Contributors

Picture of Vanyo Georgiev
Vanyo Georgiev (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Vanyo Georgiev
    Sun, Dec 8, 2013, 1:10 AM
    Hi Michael,
    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.
  • Picture of Michael Milette
    Fri, Feb 14, 2014, 7:05 AM
    Hi Vanyo,

    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
  • Picture of Vanyo Georgiev
    Sun, Feb 23, 2014, 10:15 PM
    Hi, 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.

  • Picture of Michael Buchanan
    Wed, Feb 26, 2014, 5:19 AM

    Great Filter!  Thank you for your work smile  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?

  • Picture of Vanyo Georgiev
    Wed, Feb 26, 2014, 4:20 PM
    This happens because of the logic in multilingual block definition which the filter follows. A multilingual block is a sequence of identical html tags all with different lang=”xx” attributes. There are repeating lang attributes in this sequence:

    <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.
  • Picture of Michael Milette
    Thu, Mar 6, 2014, 10:29 PM
    Hi Vanyo, just noticed your reply. Thank you!

    Your suggestion worked. As long as the {mlang}{mlang fr} are together and not on separate lines, it works perfectly!

    Thanks again!

    Michael
  • Picture of Michael Milette
    Tue, Mar 18, 2014, 3:44 AM
    Hi Vanyo, still loving this plugin!

    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
  • Picture of Vanyo Georgiev
    Sun, Mar 30, 2014, 12:01 AM
    Hi 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
  • Picture of Michael Milette
    Mon, Mar 31, 2014, 9:28 PM
    Thanks Vanyo, you're the best!
  • Picture of Michael Milette
    Mon, Mar 31, 2014, 10:12 PM
    Hi Vanyo,

    I was very excited to try out your most recently enhancements. However when I tried it, I got an error message. I've posted details in the bug tracker:

    Notice: Undefined index: en in filter.php on line 106 #1
    https://github.com/vanyog/moodle-filter_multilangsecond/issues/1

    Please let me know when you are ready for me to try it again as I am currently in the process of putting several Moodle plugins including yours through some quality assurance testing.

    Looking forward to hearing from you.

    Best regards,

    Michael
  • Picture of Vanyo Georgiev
    Tue, Apr 1, 2014, 3:20 AM
    Hi Michael,

    Thank you for paying attention on this issue!

    I made a correction: https://github.com/vanyog/moodle-filter_multilangsecond/commit/f0de99d4802d1e93949a2622d934efc3fd913fa3#diff-955a72e7e562f79fa8be7715bf5319a4

    Now there are no warning messages any more.
    The file for download here was updated too.


    Best regards.
    Vanyo
  • Picture of Michael Milette
    Tue, Apr 1, 2014, 4:42 AM
    Well done Vanyo!

    Thank you very much for the fix and the quick solution Looks good so far. I'll let you know if I come across anything else.

    Best regards,

    Michael
  • Picture of Michael Milette
    Wed, Apr 2, 2014, 3:50 AM
    Hi Vanyo,

    Would it be possible to add a new feature to your already excellent plugin?

    The new tag called {lang} would allow people entering information to easily tag text as being an a particular language when no alternative language is provided.

    For example, lets assume that I am entering information on an otherwise French page but want to put a link to a company with an English company name. Since the editor doesn't currently have an option to tag text in a particular language, the {lang} tag could be typed in plain text such as:

    [a href="http://www.gm.com"]{lang en}General Motors{lang}[/a]

    The filter would simply convert this into:

    [a href="http://www.gm.com"][span lang="en"]General Motors{lang}[/span][/a]

    (sorry, had to replace < and > characters with [ and ] or they would be filtered out of this message.)

    This would enable screen readers to properly read the tagged text in the correct language (if available).

    I think it would be very easy to implement as it amounts to little more than a simple search and replace of the opening and closing tags. The only thing I haven't thought out yet is how to make it support larger blocks of text. But then again, large blocks should probably be translated and inserted using mlang tags anyway.

    Let me know if this is something you would be interested in adding to your plugin. Otherwise I might try my hand at it.

    Best regards,

    Michael Milette
  • Picture of Vanyo Georgiev
    Sat, Apr 5, 2014, 2:16 PM
    Hi Michael,
    The problem is that the search pattern in the present version of multilansecond filter is made to find multilingual blocks and to skip individual {mlang xx}…{mlang} elements. At the moment I have no Idea how to integrate the feature you like in the present filter. My be It would be easier to make a separate filter for your need first, and after setting it up and running to think how to combine multilansecond filter with this new filter.
    Best regards
    Vanyo
  • Picture of Michael Milette
    Wed, Apr 9, 2014, 9:23 PM
    Hi Vanyo, thank you for your response.

    I am suggesting that you could used {lang xx}, not {mlang xx}. It would be {lang} because it is for specifying the language of text, not specifying multi-language text.

    The tag would specifically be used for tagging text in a specific language. That way it would not interfere with existing functionality or code.

    The code would search for {lang xx} tag and replace it with: < span lang="xx" >.

    The only complicated part of this is parsing the {lang} tags to extract the specified language which your plugin already does.

    The closing {lang} tag would get replaced with the closing for the span tag, a simple search and replace.

    Best regards,

    Michael
1 2
Please login to post comments