Note: You are currently viewing documentation for Moodle 3.8. Up-to-date documentation for the latest stable version of Moodle may be available here: Multi-language content filter.

Multi-language content filter: Difference between revisions

From MoodleDocs
m (re-wording, category)
(→‎Common problems: Headings aren't displaying correctly)
(46 intermediate revisions by 12 users not shown)
Line 1: Line 1:
The Multi-language content filter enables resources to be created in multiple languages. When turned on, it looks for <nowiki><span lang="xx" class="multilang"></nowiki> tags which indicate that a text contains multiple languages. Then it selects and outputs the best language for the current user. The language of the resource will change when the user changes their selected Moodle language.
{{Filters}}
==Displaying text in multiple languages==
The multi-language content filter enables resources to be created in multiple languages. When turned on, it looks for <nowiki><span lang="xx" class="multilang"></nowiki> tags which indicate that a text contains multiple languages. Then it selects and outputs the text in the user's language (as set in their browser or in their preferences).


The multilang syntax was changed in 1.8. <nowiki><lang></nowiki> is not supported any more. It is required to add ''class="multilang"'' into each <nowiki><span></nowiki> tag in multilang block. The new syntax is backwards compatible with old plugins, which means it can be used in older Moodle version.
==Enabling the multi-language content filter==
 
An admin can enable the multi-language content filter as follows:
 
# Go to ''Site administration > Plugins > Filters > Manage filters'' and in the dropdown menu for multi-language content select 'On'.
# If headings are to be shown in multiple languages too, select 'Content and headings' in the 'Apply to' column. Note that this may affect site performance.


== How to use in a course ==
== How to use in a course ==


To use this feature first create your contents in multiple languages (in the same resource). Then enclose each language block (aka multilang block) in the following tags:
To use this feature first create your content in multiple languages (in the same resource). Then enclose each language block (aka multilang block) in the following tags:


       <nowiki><span lang="XX" class="multilang">your_content_here</span>
       <nowiki><span lang="XX" class="multilang">your_content_here</span>
       <span lang="YY" class="multilang">your_content_in_other_language_here</span></nowiki>
       <span lang="YY" class="multilang">your_content_in_other_language_here</span></nowiki>


It is essential to be in '''the code editing mode''' (press <nowiki>[<>]</nowiki> in the HTML editor), when you enter these tags for them to work. Only spaces, tabs and enters can be used between the individual languages in the multilang block. Please note that ''class="multilang"'' is not required prior to 1.8.
It is essential to be in '''the code editing mode''' (press <nowiki>[<>]</nowiki> in the HTML editor), when you enter these tags for them to work. Only spaces, tabs and enters can be used between the individual languages in the multilang block.
 
Note: If your site uses a child language pack (see [[Language packs]] for the list), then the first span tag must be the parent language. Otherwise, when a user using the child language views the text, it will not be in the correct language for them (as reported in MDL-55197). For example, if your site uses en_us then the en span tag (as parent language) must be first i.e.


Following code
<nowiki><span lang="en" class="multilang">your_content_in English</span>
      <nowiki><lang="XX">your_content_here</lang>
       <span lang="de" class="multilang">your_content_in_German_here</span></nowiki>
       <lang="YY">your_content_in_other_language_here</lang></nowiki>
does NOT work.


The obsoleted HTML tagging
==How to use for assignment submission agreements==
      <nowiki><lang lang="XX">your_content_here</lang>
      <lang lang="YY">your_content_in_other_language_here</lang>


      <span lang="XX">your_content_here</span>
#With the filter enabled, go to ''Site administration > Plugins > Activity modules > Assignment > Assignment settings.
      <span lang="YY">your_content_in_other_language_here</span></nowiki>
#In the submission statement, add (for example)
will not work in 1.8 and later. In 1.8 the lang attribute without ''class="multilang"'' can be used to mark the language of the text - see http://www.w3.org/TR/html4/struct/dirlang.html
 
      <nowiki><span lang="en" class="multilang">This assignment is my own work, except where I have acknowledged the use of the works of other people.</span>
<span lang="fr" class="multilang">Ce devoir est le fruit de mon travail personnel, sauf aux endroits où l'utilisation d'oeuvre d'autres auteurs est clairement indiquée.</span> </nowiki>


== How it works internally ==
== How it works internally ==
Line 34: Line 41:
# Text outside of multilang blocks will be shown always
# Text outside of multilang blocks will be shown always


==Course summary and title tags==
== Common problems ==


To be able to change text such as resource titles and summaries, an administrator must choose ''Filter all strings'' in the site administration.
# The multi-lang filter is not enabled. It can be enabled in 'Manage filters' in the Site administration'.
# Headings aren't displaying correctly - the multi-lang filter should be set to apply to content and headings in 'Manage filters' in the Site administration'.
# Extra characters between language span tags - editor might add <nowiki><br /></nowiki> or other tags, please review the html in source view
# If the course setting is "force" some language, you won't be able to change the displayed language.
# Extra spaces in language span tag
# The multi-lang filter does not work with the course short name! A course's short name is meant as a unique course identifier, so it does not use the multi-lang filter.


<nowiki> <span lang="en" class="multilang">Matematically</span> <span lang="sv" class="multilang">Matematiskt (svenska)</span></nowiki>
==The 'Restriction by language' additional plugin==
functions as English or Swedish title.
[[File:Restriction by language.png|thumb|Restriction by language]]
Language filters are great, but sometimes they can make your resources and activities very complex.


It doesn't seem to work for course titles (neither long nor short version).
The [https://moodle.org/plugins/view.php?plugin=availability_language Restriction by language availability condition] is an additional plugin that makes it easy to show an English resource only to English users and an activity in French only to French speaking students.


In the course summary:
==The Multi-Language Content (v2) additional plugin and Multi-Language Content text editor plugins==
There is also an alternative multi-language content filter available called [https://moodle.org/plugins/filter_multilang2 Multi-language Content (v2)]. This filter uses very simple non-HTML tags to mark multi-language blocks (makes it easier to create multi-language content), and can be used together with the [https://moodle.org/plugins/atto_multilang2 Multi-Language Content Atto plugin] or the [https://github.com/iarenaza/moodle-tinymce_moodlelang2 Multi-Language Content TinyMCE plugin] to make it even easier to create multi-language content directly on the text editor without using the HTML view mode.


<nowiki><span lang="en" class="multilang">Growth is often a major concern in planning society.
==The Multi-Lingual Content additional plugin==
How can one avoid superficial conclusions? <br>
[https://moodle.org/plugins/filter_multilangsecond 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.
(Exists in Swedish too. Finns på svenska också)</span>
<span lang="sv" class="multilang">Tillväxt är ofta använt i samhällsdebatten.
Hur kan man undvika ytliga slutsatser?
(Finns på engelska också. Exists in English too.)
<br /></span> </nowiki>
 
Can show in the chosen language (and point out that the other language is there). Please note that ''class="multilang"'' is not required prior to Moodle 1.8.
 
== Translations with tags ==
If you wish to translate a word or phrase in an English text to another language:
 
<nowiki>If I want to include an explanation <span lang="en"> </span>
<span lang="sv" class="multilang">(sv: förklaring)</span> in a running text can I do it?
<br />
<br /><span lang="en" class="multilang>If I want to include an explanation in a running text
can I do it? </span>
<span lang="sv" class="multilang>If I want to include an explanation (sv: förklaring) in a
running text can I do it?</span></nowiki>
 
would both work, but not:
 
<nowiki>If I want to include an explanation <span lang="en" class="multilang></span>
<span lang="sv" class="multilang>(sv: förklaring)</span> in a running text can I do it?
<br />If I want to include an explanation <span lang="sv" class="multilang>(sv: förklaring)</span>
in a running text can I do it?<br /></nowiki>
which would show the Swedish even if English was the chosen language. NOTE that before 1.8 the "span lang=en" must contain something, at least a space.
 
== New multilang syntax ==
{{Moodle 1.8}}
* <nowiki><span lang="xx"> and <lang></nowiki> should not be used anymore
* Existing content can be upgraded using the admin/multilangupgrade.php script, there is a link in the admin notification page if a multilang upgrade is required.
* The multilang filter can be configured to use old syntax only - see ''Multi-Language Content Settings''; this setting may be removed in 1.9
* New syntax is forced during a new 1.8 installation, for upgraded sites the new syntax is enabled after the multilang upgrade
 
== Common problems ==


* The multilang filter is not enabled - go to filter settings and enable it
==Any questions?==
* ''Filter all strings'' not enabled on sites that need multilang in titles, navigation, headings, etc.
* Extra characters between language span tags - editor might add <nowiki><br /></nowiki> or other tags, please review the html in source view
* Extra spaces in language span tag


== See also ==
Please post in the [https://moodle.org/mod/forum/view.php?id=43 Languages forum] on moodle.org.


*[[Filters (administrator)]]
==See also==
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=51603 Multilanguage filter - does not work ...] forum discussion


*[[Language]]
*Custom menu items in [[Theme settings]]
*[https://moodle.org/mod/forum/discuss.php?d=320980 Translation of MOOC] forum discussion and solution
* [https://moodle.org/mod/forum/discuss.php?d=356318 language dropdown not displayed - Boots logon page] forum thread


[[Category:Administrator]]
[[Category:Language]]
[[Category:Teacher]]
[[Category:Filter]]


[[es:Filtros (Administrador)]]
[[de:Mehrsprachiger Inhalt]]
[[es:Filtro de contenido multi-idioma]]
[[fr:Contenu multilingue]]
[[fr:Contenu multilingue]]
[[ja:多言語シンタックス]]

Revision as of 11:57, 8 September 2017

Displaying text in multiple languages

The multi-language content filter enables resources to be created in multiple languages. When turned on, it looks for <span lang="xx" class="multilang"> tags which indicate that a text contains multiple languages. Then it selects and outputs the text in the user's language (as set in their browser or in their preferences).

Enabling the multi-language content filter

An admin can enable the multi-language content filter as follows:

  1. Go to Site administration > Plugins > Filters > Manage filters and in the dropdown menu for multi-language content select 'On'.
  2. If headings are to be shown in multiple languages too, select 'Content and headings' in the 'Apply to' column. Note that this may affect site performance.

How to use in a course

To use this feature first create your content in multiple languages (in the same resource). Then enclose each language block (aka multilang block) in the following tags:

      <span lang="XX" class="multilang">your_content_here</span>
      <span lang="YY" class="multilang">your_content_in_other_language_here</span>

It is essential to be in the code editing mode (press [<>] in the HTML editor), when you enter these tags for them to work. Only spaces, tabs and enters can be used between the individual languages in the multilang block.

Note: If your site uses a child language pack (see Language packs for the list), then the first span tag must be the parent language. Otherwise, when a user using the child language views the text, it will not be in the correct language for them (as reported in MDL-55197). For example, if your site uses en_us then the en span tag (as parent language) must be first i.e.

<span lang="en" class="multilang">your_content_in English</span>
      <span lang="de" class="multilang">your_content_in_German_here</span>

How to use for assignment submission agreements

  1. With the filter enabled, go to Site administration > Plugins > Activity modules > Assignment > Assignment settings.
  2. In the submission statement, add (for example)
      <span lang="en" class="multilang">This assignment is my own work, except where I have acknowledged the use of the works of other people.</span>
<span lang="fr" class="multilang">Ce devoir est le fruit de mon travail personnel, sauf aux endroits où l'utilisation d'oeuvre d'autres auteurs est clairement indiquée.</span> 

How it works internally

  1. Filter first looks for multilang blocks in the text
  2. For each multilang block:
    • If there are texts in the currently active language, print them
    • Else, if there exists texts in the current parent language, print them
    • Else, print the first language found in the text
  3. Text outside of multilang blocks will be shown always

Common problems

  1. The multi-lang filter is not enabled. It can be enabled in 'Manage filters' in the Site administration'.
  2. Headings aren't displaying correctly - the multi-lang filter should be set to apply to content and headings in 'Manage filters' in the Site administration'.
  3. Extra characters between language span tags - editor might add <br /> or other tags, please review the html in source view
  4. If the course setting is "force" some language, you won't be able to change the displayed language.
  5. Extra spaces in language span tag
  6. The multi-lang filter does not work with the course short name! A course's short name is meant as a unique course identifier, so it does not use the multi-lang filter.

The 'Restriction by language' additional plugin

Restriction by language

Language filters are great, but sometimes they can make your resources and activities very complex.

The Restriction by language availability condition is an additional plugin that makes it easy to show an English resource only to English users and an activity in French only to French speaking students.

The Multi-Language Content (v2) additional plugin and Multi-Language Content text editor plugins

There is also an alternative multi-language content filter available called Multi-language Content (v2). This filter uses very simple non-HTML tags to mark multi-language blocks (makes it easier to create multi-language content), and can be used together with the Multi-Language Content Atto plugin or the Multi-Language Content TinyMCE plugin to make it even easier to create multi-language content directly on the text editor without using the HTML view mode.

The Multi-Lingual Content additional plugin

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.

Any questions?

Please post in the Languages forum on moodle.org.

See also