get the text according to user lang

get the text according to user lang

by Daniele Cordella -
Number of replies: 6
Picture of Core developers Picture of Plugin developers

Hello moodlers.
I am looking for the function (method) extracting the text from a string like

'<span lang="it" class="multilang">Buongiorno mondo</span><span lang="en" class="multilang">Hello world</span>'

according to the user language.

Where can I find it into MOODLE_311_STABLE and MOODLE_400_STABLE code?


As usual, thank you in advance.

Average of ratings: -
In reply to Daniele Cordella

Re: get the text according to user lang

by Farhan Karmali -
Picture of Core developers Picture of Plugin developers Picture of Testers
Average of ratings: Useful (2)
In reply to Farhan Karmali

Ri: Re: get the text according to user lang

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers

Thanks Farhan. 

I am looking for the php routine in the code that get the text from the string. I am looking at the code as developer not at the way to use multi lang strings as admin or manager. Maybe the page you pointed me to explains this detail too. I go to look in detail. Anyway, thank, thanks s lot. 

In reply to Daniele Cordella

Re: Ri: Re: get the text according to user lang

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Farhan is correct that it is the multilang filter that you are looking for information about - the code for it is in filter/multilang/ - https://github.com/moodle/moodle/blob/master/filter/multilang/filter.php
Average of ratings: Useful (3)
In reply to Davo Smith

Ri: Re: Ri: Re: get the text according to user lang

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers

Thanks Davo and Farhan too. You both fixed my problem. Thank you. 

In reply to Daniele Cordella

Re: get the text according to user lang

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Daniele,

The Moodle API functions to extract the text in the correct language are listed on the following page of the Moodle Output API:

https://moodledev.io/docs/apis/subsystems/output#output-functions

Note that this is not specific to language but to processing content through Moodle filters.

If you happen to have a language filter installed AND enabled for content AND headings, it will process multi-language content through the language filter.

If you are just getting started with muti-language content, I recommend that you take a look at the Multi-Language Content (v2) filter available from:

https://moodle.org/plugins/filter_multilang2

There are many advantages to using this plugin over the one that comes bundled with Moodle including:

  • It uses plain text tags like: {mlang en}In English{mlang}{mlang fr}En Français{mlang} instead of having to edit more complex HTML.
  • It is easy to see where the tags are since they are just plain text. No more having to guess or view the HTML codes to see where the span tags start and end.
  • The {mlang} tags are much shorter leaving more room for your content which is great when dealing with fields like course names which have length limitations.
  • Plain text tags also work in more places in Moodle than the HTML span tags because some fields in Moodle don't allow HTML tags.
  • There is a plugin available for the Atto editor to make life easier for content creators. See: https://moodle.org/plugins/atto_multilang2
  • Unlike span tags, you can put several paragraphs of content inside sets of {mlang} tags and still end up with valid HTML. You just need to format on multiple lines as follows:
{mlang en}
Multiple paragraphs in English.
{mlang}{mlang fr}
Plusieur paragraphe de texte en Français.
{mlang}

Hope you find this information useful.

Best regards,

Michael Milette

Average of ratings: Useful (3)
In reply to Michael Milette

Ri: Re: get the text according to user lang

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Thanks Michael.
Your answer is explaining the topic in very good detail.
I need to refresh my knowledge.
Thank, thanks a lot.