Passing a variable as parameter to sc_set_language

Hi.
The sc_set_language is to define the application language dynamically.

Here is a couple of examples:

  • sc_set_language(‘en_us’);
  • sc_set_language(‘es’);

But is it possible to use a variable instead of the text for the language, like this:

$lang = ‘en_us’;
sc_set_language($lang);

The “sc_set_language($lang);” line does not work, but is it a different way of doing it using a variable for language?

I don’t know in what scenario you want to use this, but maybe I can help you with advice.
I added a language field to the sec_user table. Already when creating a user, he is assigned his default language.
And so it has an app in its own language every time you log in.

In particular, I added an option in the user settings so that he can change the language after logging in. But this only applies to the current login.
The next time you log in, the application has it back in its default language, which I read from the sec_user table.

Is this what you are looking for?

i don try it with languages, but What event are you executing the macro?
did you tried with a global variable [my_lang] = ‘en_us’;

Thank you for your response.

Here is how I am going to use this:

My system is generating an email with a link to the login page. When the user click the link and come to the login page, the system do not know the users language, because he/she has not logged in yet. Therfore I want to detect the default language in the browser and use this value to set the language for the system (sc_set_language).

Here is the code:

if (substr($_SERVER[“HTTP_ACCEPT_LANGUAGE”], 2, 1) ==’-’){
$nchar=5;
}
else{
$nchar=2;
}
$lang_id = substr($_SERVER[“HTTP_ACCEPT_LANGUAGE”], 0, $nchar);
sc_set_language($lang_id);

I found the problem.

It is nothing wrong with the code. The problem is that the language-id in Scriptcase is a bit different as the language-id in the browser.
F.ex: It is named “en-gb” in the browser, but “en_gb” in Scriptcase. So I have to find a different way of doing this.
Anyway: Thank you for your response.