When I login to the site, i always keep getting the English language.

When I login to the site, i always keep getting the English language.

by Salman Zaidi -
Number of replies: 5

Hello everyone,

I have a problem that i haven't found the answer for it in the forum.

I have 2 languages in my Moodle 3.1 site. English and French. I set a drop down menu of lang selection in login page

When I login to the site, i always keep getting the English lang. 

After i login, i always have to change the Lang in the drop down box. How can I fix that issue. I have more than 400 users and all are from external database.  I believe it would not be the good way to change their preferred language one by one since the things are in the hands of admin only. Student can only see their grades and course info and nothing is given to students for doing any profile administration etc.

I am using Lmbda theme, I check this issue with Moodle default clean theme as well, the same problem persists.


My Moodle version is 3.1

thank you in advance !


Average of ratings: -
In reply to Salman Zaidi

Re: When I login to the site, i always keep getting the English language.

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
  • For logged-in users, the language is set to the one they have set as their preferred language (Preferences > User account > Preferred language).
  • For logged-out visitors (before they log in) the situation depends on whether the language auto-detection is enabled. They can either get the language their browser claims to be the requested one, or the site default language.

I assume all your users have English set as their preferred language.

Average of ratings: Useful (1)
In reply to David Mudrák

Re: When I login to the site, i always keep getting the English language.

by Salman Zaidi -

Hi David,

Thanks for reply.

I have unchecked lang auto detection as I dont wanna use browser language.

I assume (and this is requirement) that if user selects language from login page,  the next page should be appeared in that language regardless of user preferred language or browser language.

I am not giving any access to users or student to set their own parameters. Usually, any student or user who wants to use his / her preferred language should be able to see 'selected language' in next page after selecting the same in login page.

I attempted some code hacks to get current language, but that changes to en after login page submit to next page. Another hook I tried to get the URL string by $PAGE->url and substr($PAGE->url,-2) to get the lang code, but it changes to en as well after next page appears.

But, I have successfully done it in reverse, like if user logout, he/she would see the same language on login page which was selected in after-login page. I achieved this by adding the code in logout.php

In logout.php file at ling 41, I added this code.

$currlang = current_language();
if ($login)
{ $redirect = get_login_url(); }
else
{ $redirect = $CFG->wwwroot.'/'; }
$redirect .= (isset($_POST['lang']) ? '?lang='.$_POST['lang'] : '');
$redirect .= "login/index.php?lang=".$currlang;


---------------------------------------------

Any help in this regard?  Thanks.


In reply to David Mudrák

Re: When I login to the site, i always keep getting the English language.

by Salman Zaidi -

Hi,


Is there any way I can get selected language variable from lang menu in login before redirection. I tried $SESSION->lang but its give error (property not set stdclass) before calling 

redirect(new moodle_url(get_login_url(), array('testsession'=>$USER->id)));

I want to add language e.g. en or fr character in URL string based on selected language from lang menu on login page.
But not succeeded as I dont have access to any session language variable.

I dont understand why moodle has given lang menu in login page, if language in next page depends on User preferred language or browser language. I dont want to use $USER->lang variable as always gives me en.

Any help?

In reply to Salman Zaidi

Re: When I login to the site, i always keep getting the English language.

by Robert Brenstein -
The current behavior actually makes sense. When user is at the login page, he may be sitting at any computer in any country, so he may need/want to display the login page in whatever language is suitable. Moodle rightfully assumes that after login, the user wants to have his preferred language shown.

You can check the language settings for all users by inspecting the user table in Moodle database. It is possible that English was set when the accounts were created. You can also change that setting there.

If you really want to allow users to select the language at login time, you can try to disable the code that sets the language based on user settings.
In reply to Robert Brenstein

Re: When I login to the site, i always keep getting the English language.

by Salman Zaidi -
Hi Robert,

Thank for reply.

Alternatively, I am working on redirecting url with lang parameter based on language selection. For this, I am trying to take option from a external html or php page i.e. English or French.

I have tried to get lang option variables into session and in login/index.php, I am trying to redirect the function based on lang session.

The problem is my session lang variable dies in login/index.php of moodle before redirecting.

Can you please mention, how can i sustain my session variable of lang into login/index.php.

I am trying to set condition as follows in index.php file:

if ($_SESSION['lng']) == 'fr'
 redirect(new moodle_url(get_login_url()."?lang=fr", array('testsession'=>$USER->id)));
else
 redirect(new moodle_url(get_login_url(), array('testsession'=>$USER->id)));


Any help? Thanks.