- Unzip the plugin in the moodle .../filter/ directory.
- Go to "Site Administration >> Plugins >> Filters >> Manage filters" and enable the plugin there.
- 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} {mlang other}content for other languages{mlang}
- where XX and YY are the Moodle short names for the language packs (i.e., en, fr, de, etc.) or the special language name 'other'.
- Version 1.1.1 and later: a new enhanced syntax to be able to specify multiple languages for a single tag is now available. Just specify the list of the languages separated by commas:
{mlang XX,YY,ZZ}Text displayed if current lang is XX, YY or ZZ, or one of their parent laguages.{mlang}
- Test it (by changing your browsing language in Moodle).
- Look for "lang blocks" in the text to be filtered.
- For each "lang block":
- If there are texts in the currently active language, print them.
- Else, if there exist texts in the current parent language, print them.
- Else, as fallback, print the text with language 'other' if such one is set.
- Text outside of "lang blocks" will always be shown.
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,es_mx,es_co} 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}
This text:
{mlang other}Hello!{mlang}{mlang es,es_mx}¡Hola!{mlang} This text is common for all languages because it's outside of all lang blocks. {mlang other}Bye!{mlang}{mlang it}Ciao!{mlang}
- If the current language is any language except "Spanish International", "Spanish - Mexico" or Italian, it will print:
Hello! This text is common for all languages because it's outside of all lang blocks. Bye!
- If the current language is "Spanish International" or "Spanish - Mexico", it will print:
¡Hola! This text is common for all languages because it's outside of all lang blocks.
- Notice the final 'Bye!' / 'Ciao!' is not printed.
- If the current language is Italian, it will print:
This text is common for all languages because it's outside of all lang blocks. Ciao!
- Notice the leading 'Hello!' / '¡Hola!' and the final 'Bye!' are not printed.
We create a label with the content shown in the following image:
The "lang block" tags are highlighted using blue boxes. You can see that 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):
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):