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

Multi-language content filter: Difference between revisions

From MoodleDocs
(see also)
 
(44 intermediate revisions by 9 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}}
 
== Overview multi language ==
 
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.
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.


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.
== How to use in a course ==


== How to use ==
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 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. Only spaces, tabs and enters can be used between the individual languages in the mulitang block. Please note that ''class="multilang"'' is not required prior to 1.8.


The obsoleted HTML tagging
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><lang lang="XX">your_content_here</lang>
      <lang lang="YY">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 ==
== How it works internally ==


# filter first looks for ''multilang blocks'' in the text
# Filter first looks for ''multilang blocks'' in the text
# for each multilang block:
# For each multilang block:
## if there are texts in the currently active language, print them
#* If there are texts in the currently active language, print them
## else, if there exists texts in the current parent language, print them
#* Else, if there exists texts in the current parent language, print them
## else, print the first language found in the text
#* Else, print the first language found in the text
# text outside of multilang blocks will be showed always
# Text outside of multilang blocks will be shown always


==Course summary and title tags==
== Common problems ==
To be able to change even resource titles and summaries, you must chose "all strings" in the adminstration choices.
<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).
* 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 <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
* 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!


In the course summary:
==Tips and tricks==


<nowiki><span lang="en" class="multilang">Growth is often a major concern in planning society.
===Changing language displayed without going to front page===
How can one avoid superficial conclusions? <br>
It is possible to change the displayed language by manually changing the link.  
(Exists in Swedish too. Finns på svenska också)</span>
*Here is the default language page at id=2306. This link is in English, the default language:
<span lang="sv" class="multilang">Tillväxt är ofta använt i samhällsdebatten.
:http://moodle.org/mod/resource/view.php?id=2306
Hur kan man undvika ytliga slutsatser?
*The link to change the page display to Spanish is
(Finns på engelska också. Exists in English too.)
:http://moodle.org/mod/resource/view.php?id=2306&lang=es ,
<br /></span> </nowiki>
*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
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 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>
<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 the "span lang=en" must contain something, at least a space.
 
{{Moodle 1.8}}
== New multilang syntax ==
 
TODO: add docs and description - see http://tracker.moodle.org/browse/MDL-7887
 
== Common problems ==
* 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 ==
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.
[[Filters_%28administrator%29]]


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


*[[Language]]
*Custom menu items in [[Theme settings]]


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


[[es:Filtros (Administrador)]]
[[es:Filtros (Administrador)]]
[[fr:Filtres (administrateur)]]
[[fr:Contenu multilingue]]
[[ja:多言語シンタックス]]

Latest revision as of 07:31, 20 December 2011

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.

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!

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.

See also