Note: This documentation is for Moodle 2.7. For up-to-date documentation see Multi-language content filter.

Multi-language content filter: Difference between revisions

From MoodleDocs
(Transfered entire section from Filters (admin))
(→‎How to use in a course: order of span tags (MDL-55197))
 
(76 intermediate revisions by 12 users not shown)
Line 1: Line 1:
Moodle will allow different resources to appear to users based upon their language. This is a filter called Multi language content. This page goes into details of several ways of displaying resources to users based on language.
{{Filters}}
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.


This is the information that was in Filters (Administration).
== How to use in a course ==


==Multi-language content==
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:


This filter enables resources to be created in multiple languages. It looks for <lang> 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.  More information about using this feature can be found in the MoodleDoc page [[Multi_language_content]]
      <nowiki><span lang="XX" class="multilang">your_content_here</span>
      <span lang="YY" class="multilang">your_content_in_other_language_here</span></nowiki>


To use this feature first create your contents in multiple languages (in the same resource). Then enclose each language block in the following tags:
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.


      <nowiki><span lang="XX">your_content_here</span>
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="YY">your_content_in_other_language_here</span>
</nowiki>


It is essential to be in the "code" editing (press <nowiki>[<>]</nowiki> in the HTML editor), when you enter these tags for them to work.
<nowiki><span lang="en" class="multilang">your_content_in English</span>
      <span lang="de" class="multilang">your_content_in_German_here</span></nowiki>


Even the HTML tagging
==How to use for assignment submission agreements==
      <nowiki><lang lang="XX">your_content_here</lang>
#Since Moodle 2.7.4 it's possible to have assignment submission statements in different languages.
      <lang lang="YY">your_content_in_other_language_here</lang>
#With the filter enabled, go to Site administration>Plugins>Activity modules>Assignment>Assignment settings.
</nowiki>
#In the submission statement, add (for example)
works, but may be unsupported from 1.7.  
      <nowiki><lang="XX">your_content_here</lang>
    <lang="YY">your_content_in_other_language_here</lang>
</nowiki>
does NOT work.


      <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>


To be able to change even resource titles and summaries, you must chose "all strings" in the adminstration choices.
== How it works internally ==
<nowiki> <span lang="en">Matematically</span> <span lang="sv">Matematiskt (svenska)</span></nowiki>
would function as English or Swedish title.


It doesn't seem to work for course titles (neither long nor short version).
# Filter first looks for ''multilang blocks'' in the text
# 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
# Text outside of multilang blocks will be shown always


In the course summary:
== Common problems ==


<nowiki><span lang="en">Growth is often a major concern in planning society.
* The multilang filter is not enabled. It can be enabled by a site administrator in ''Settings > Site administration > Plugins > Filters > Manage filters''.
How can one avoid superficial conclusions? <br>
* Extra characters between language span tags - editor might add <nowiki><br /></nowiki> or other tags, please review the html in source view
(Exists in Swedish too. Finns på svenska också)</span>
* If the course setting is "force" some language, you won't be able to change the displayed language.
<span lang="sv">Tillväxt är ofta använt i samhällsdebatten.  
* Extra spaces in language span tag
Hur kan man undvika ytliga slutsatser?
* Can not easily access language choice dropdown! Unfortunately you must go to the site homepage or your own profile to change the displayed language. It is possible to manually quickly change displayed lang by editing the URL in the browsers address bar. See Tips and tricks below!
(Finns på engelska också. Exists in English too.)
* The multilang 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 multilang filter
<br /></span> </nowiki>


Can show in the chosen language (and point out that the other language is there).
==Tips and tricks==


That the filter works on multilanguage blocks is important, see forum: http://moodle.org/mod/forum/discuss.php?d=51603 :
===Changing language displayed without going to front page===
From which this is copied (and ought to be shortened):
It is possible to change the displayed language by manually changing the link. 
<nowiki>
*Here is the default language page at id=2306. This link is in English, the default language:
... how the multilang filter works:
:http://moodle.org/mod/resource/view.php?id=2306
*The link to change the page display to Spanish is
:http://moodle.org/mod/resource/view.php?id=2306&lang=es ,
*When the default language is an other language, to change the page to an English version, the link would be:
:http://moodle.org/mod/resource/view.php?id=2306&lang=en


1) First of all it looks for multilang Blocks.
Thus, with a bit of editing, you can manually change the displayed language by adding "&lang=xx" to the URL in the location bar of the browser. Where xx is the abbreviation for the language you want.
One Multilang block of text is defined as one group of <span lang="XX">
tags together, without anything between them.


2) After this detection of Blocks, for each of them, Moodle selects
==The 'Restriction by language' additional plugin==
the best language for the user displaying the info, showing its info
Language filters are great, but sometimes they can make your resources and activities very complex.
and discarding the rest of lang tags in the block.


So, applying this behaviour to the example you wrote above, we have:
The 'Restriction by language' availability condition is an additional plugin for Moodle 2.7, available in the [https://moodle.org/plugins/view.php?plugin=availability_language Moodle plugins database], that makes it easy to show an English resource only to English users and an activity in French only to French speaking students.


1) Moodle looks for Blocks and it finds TWO blocks:
[[File:Restriction by language.png]]


Block A: <span lang="de">von links</span>
==See also==  
Block B:<span lang="en"><span="en"><font size="3"> </font></span>from the left</span>


2) For each block, Moodle display the better language. As Both blocks
*[[Language]]
only contain ONE lang tag, it's returned, so results are:
*Custom menu items in [[Theme settings]]
*[https://moodle.org/mod/forum/discuss.php?d=320980 this forum thread] about translating a MOOC


For Block A: von links
[[Category:Language]]
For Block B: <span="en"><font size="3"> </font></span>from the left


Then obviously, in one web page, those results are showed as:
[[de:Mehrsprachiger Inhalt]]
 
[[es:Contenido multilingüe]]
von links
[[fr:Contenu multilingue]]
from the left
[[ja:多言語シンタックス]]
 
The key concept here is the Block of lang. Once you get it, everything is easily to understand.
 
Also note that the HTMLEditor seems to introduce an excess of "noisy" tags
under some circumstances and, if it does so between lang tags, it will be,
in fact, breaking your blocks of langs! It's always recommended to check the
final HTML generated by the HTML Editor in order to verify that the lang tags
(and their grouping together is conforming blocks of langs) are properly
written.</nowiki>
 
If I were to want to translate a word or phrase to a chosen language in an English text:
 
<nowiki>If I want to include an explanation <span lang="en"> </span>
<span lang="sv">(sv: förklaring)</span> in a running text can I do it?
<br />
<br /><span lang="en">If I want to include an explanation in a running text
can I do it? </span>
<span lang="sv">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"></span>
<span lang="sv">(sv: förklaring)</span> in a running text can I do it?
<br />If I want to include an explanation <span lang="sv">(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 the "span lang=en" must contain something, at least a space.

Latest revision as of 12:59, 28 September 2016

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 best language for the current user. The language of the resource will change when the user changes their selected Moodle language.

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:

      <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. Since Moodle 2.7.4 it's possible to have assignment submission statements in different languages.
  2. With the filter enabled, go to Site administration>Plugins>Activity modules>Assignment>Assignment settings.
  3. 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

  • The multilang filter is not enabled. It can be enabled by a site administrator in Settings > Site administration > Plugins > Filters > Manage filters.
  • Extra characters between language span tags - editor might add <br /> 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
  • Can not easily access language choice dropdown! Unfortunately you must go to the site homepage or your own profile to change the displayed language. It is possible to manually quickly change displayed lang by editing the URL in the browsers address bar. See Tips and tricks below!
  • The multilang 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 multilang filter

Tips and tricks

Changing language displayed without going to front page

It is possible to change the displayed language by manually changing the link.

  • Here is the default language page at id=2306. This link is in English, the default language:
http://moodle.org/mod/resource/view.php?id=2306
  • The link to change the page display to Spanish is
http://moodle.org/mod/resource/view.php?id=2306&lang=es ,
  • When the default language is an other language, to change the page to an English version, the link would be:
http://moodle.org/mod/resource/view.php?id=2306&lang=en

Thus, with a bit of editing, you can manually change the displayed language by adding "&lang=xx" to the URL in the location bar of the browser. Where xx is the abbreviation for the language you want.

The 'Restriction by language' additional plugin

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 for Moodle 2.7, available in the Moodle plugins database, that makes it easy to show an English resource only to English users and an activity in French only to French speaking students.

Restriction by language.png

See also