-
Improvement
-
Resolution: Fixed
-
Major
-
3.5.18, 3.7.3, 3.8, 3.8.9, 3.9.2, 3.9.7, 3.10.4, 3.11.17, Future Dev, 4.1.9, 4.2.7, 4.3, 4.3.6, 4.4.2, 4.5
-
MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_35_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE, MOODLE_405_STABLE
-
MOODLE_405_STABLE
-
MDL-67554-master -
-
I work on multi-language Moodle sites (mostly English/French) and have a requirement to pass the current Moodle UI language as part of the OAuth2 login request so that the login page matches the language in Moodle. At the moment, this is not possible in Moodle.
To address this issue, I would like to add support for a small filter that would replace a plaintext tag in the Additional Parameters field with the desired language code. For example:
lang={lang}
Note that, depending on your OAuth2 server, "lang" may be hl" (HL in lowercase).
hl={lang}
Consult your server's documentation for more information on the correct parameter name.
The proposed solution accomplishes this by adding the following lines to the get_additional_login_parameters() function located in the lib/classes/oauth2/client.php file:
// Replace the language tag if it appears in the string.
|
$lang = current_language();$tags = ["{lang}", "{LANG}", "{language}", "{LANGUAGE}", '{lan-guage}', '{LAN-GUAGE}']; |
$langcode = [ |
strtolower(substr($lang, 0, 2)), |
strtoupper(substr($lang, 0, 2)), |
strtolower($lang), |
strtoupper($lang), |
str_replace('_', '-', strtolower($lang)), |
str_replace('_', '-', strtoupper($lang)), |
];
|
$params = str_replace($tags, $langcode, $params); |
This solution includes several forms of the tag to meet the needs of various OAuth2 system requirements. Supported tags include the following list. The value shown assumes that the current language is fr_ca but it would work for any other language:
Tag format table
Tag | Example value |
---|---|
{lang} | fr |
{LANG} | FR |
{language} | fr_ca |
{LANGUAGE} | FR_CA |
{lan-guage} | fr-ca |
{LAN-GUAGE} | FR-CA |
Notes:
- If there is no tag in the field, the specified string is returned unaltered.
- If the core current_language() function only returns two letters, all forms of the tag will also only return two letters.
Let me know if you have any questions or concerns.
Best regards,
Michael Milette
- has been marked as being related by
-
MDL-82266 PR only: MDL-67554 - Add support for language on OAuth2's "Additional Parameters Included in a Login Request" field
- Closed