Page 1 of 1

change language by user

Posted: Sat Jul 30, 2022 2:02 am
by mavel

hi,

1st step:
I add field on user table: AppLang

2nd step:
Added this code in: Server Events > Global Codes

function AppLanguage() {
    $applang = ExecuteScalar("SELECT AppLang FROM employees");
    return $applang;
}

3th step:
Added this code in: Other > Login Page > User LoggedIn

function User_LoggedIn($usr)
{
    //Log("User Logged In");

    if AppLanguage() == "1") { // french language value 
    $_SESSION[SESSION_LANGUAGE_ID] = "fr-FR";
    }
    else {
    $_SESSION[SESSION_LANGUAGE_ID] = "en-US"; 
    }
}

It doesn't work this way.
I can only change the language on a per-user basis with the CurrentUserID() value. When the user logs into the application, I want him to have the default language that I defined in the user table. I can't find where I went wrong.


Re: change language by user

Posted: Sat Jul 30, 2022 3:28 am
by mavel

I solved.

2nd step:
Added this code in: Server Events > Global Codes

function AppLanguage() {
    $applang = ExecuteScalar("SELECT AppLang FROM employees WHERE EmployeeID =". CurrentUserID() ."");
    return $applang;
}