Note: You are currently viewing documentation for Moodle 2.9. 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
(→‎How to use in a course: order of span tags (MDL-55197))
 
(56 intermediate revisions by 12 users not shown)
Line 1: Line 1:
Moodle will allow different resources to appear to users based upon their language. There  is a filter called Multi language content (see [[Filters_%28administrator%29]]) and it should be turned on.  This page goes into details of several ways of displaying resources to users based on 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).


== Overview multi language ==
==Enabling the multi-language content filter==


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.
An admin can enable the multi-language content filter as follows:


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.
# 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 ==
== 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 in the following tags:
 
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:


       <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>
       <span lang="YY" class="multilang">your_content_in_other_language_here</span></nowiki>
</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. 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.


The obsoleted HTML tagging
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.
      <nowiki><lang lang="XX" class="multilang">your_content_here</lang>
      <lang lang="YY" class="multilang">your_content_in_other_language_here</lang>
</nowiki>
will not work in 1.8 and later.  
      <nowiki><lang="XX">your_content_here</lang>
    <lang="YY">your_content_in_other_language_here</lang>
</nowiki>
does NOT work.


== How it works internally ==
<nowiki><span lang="en" class="multilang">your_content_in English</span>
      <span lang="de" class="multilang">your_content_in_German_here</span></nowiki>


# filter first looks for ''multilang blocks'' in the text
==How to use for assignment submission agreements==
# 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 showed always


==Course summary and title tags==
#With the filter enabled, go to ''Site administration > Plugins > Activity modules > Assignment > Assignment settings.
To be able to change even resource titles and summaries, you must chose "all strings" in the adminstration choices.
#In the submission statement, add (for example)
<nowiki> <span lang="en" class="multilang">Matematically</span> <span lang="sv" class="multilang">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).
      <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>


In the course summary:
== How it works internally ==


<nowiki><span lang="en" class="multilang">Growth is often a major concern in planning society.
# Filter first looks for ''multilang blocks'' in the text
How can one avoid superficial conclusions? <br>
# For each multilang block:
(Exists in Swedish too. Finns på svenska också)</span>
#* If there are texts in the currently active language, print them
<span lang="sv" class="multilang">Tillväxt är ofta använt i samhällsdebatten.
#* Else, if there exists texts in the current parent language, print them
Hur kan man undvika ytliga slutsatser?
#* Else, print the first language found in the text
(Finns på engelska också. Exists in English too.)
# Text outside of multilang blocks will be shown always
<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.
== Common problems ==
 
== Translations with tags ==
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" 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>
* The multilang filter is not enabled. It can be enabled by a site administrator in ''Settings > Site administration > Plugins > Filters > Manage filters''.
<span lang="sv" class="multilang>(sv: förklaring)</span> in a running text can I do it?
* Extra characters between language span tags - editor might add <nowiki><br /></nowiki> or other tags, please review the html in source view
<br />If I want to include an explanation <span lang="sv" class="multilang>(sv: förklaring)</span>
* If the course setting is "force" some language, you won't be able to change the displayed language.
in a running text can I do it?<br /></nowiki>
* Extra spaces in language span tag
which would show the Swedish even if English was the chosen language. NOTE the "span lang=en" must contain something, at least a space.
* 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


{{Moodle 1.8}}
==The 'Restriction by language' additional plugin==
== New multilang syntax ==
[[File:Restriction by language.png|thumb|Restriction by language]]
Language filters are great, but sometimes they can make your resources and activities very complex.


TODO: add docs and description - see http://tracker.moodle.org/browse/MDL-7887
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.


== Common problems ==
==Any questions?==
* Multilang filter is not enabled - go to filter settings and enable it
* ''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_%28administrator%29]]


Forum discussion  http://moodle.org/mod/forum/discuss.php?d=51603
==See also==


*[[Language]]
*Custom menu items in [[Theme settings]]
*[https://moodle.org/mod/forum/discuss.php?d=320980 Translation of MOOC] forum discussion


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


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

Latest revision as of 12:58, 28 September 2016

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

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

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.

Any questions?

Please post in the Languages forum on moodle.org.

See also