Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-60931

Multilang filter should not default to the language of logged in user

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.2.6, 3.3.3, 3.4
    • Fix Version/s: None
    • Component/s: Filters
    • Labels:
      None
    • Affected Branches:
      MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE

      Description

      I have a plugin that the teacher can use to send automatically generated emails to the students of a course. The emails contains the name of a course, and the name has been entered using the multilang filter syntax:

      <span lang="en" class="multilang">Example</span><span lang="fi" class="multilang">Esimerkki</span>

      The expectation is that when a user receives the email, the course name will be in the language of the recipient. This is however not the case, but the course name is always in the language of the person who sent the messages.

      This is caused by false assumption in the filter_multilang plugin. The code assumes the language should always be the one used by the logged in user: https://github.com/moodle/moodle/blob/master/filter/multilang/filter.php#L76

      A fix for this is to allow entering the desired language as a parameter to the format_string() function. For example:

      format_string($course->fullname, true, ['lang' => $user->lang]);

      This way it is possible to make sure the multilang tags get translated to the correct language.

      If the argument is not entered, the plugin will fall back to using the language of the logged in user.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            juho.jaakkola Juho Jaakkola
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: