Hello,
My application has 3 locales and a menu where the end-user can choose one of these languages.
However, I want all modules of the application to open up on a specific language. This specific language is stored in an external DB and varies with the user.
If I do this on the "OnInitialize" screen action (read language from DB + set current locale to that language), I get the warning "OnInitialize contains access to the local storage or server".
Is there any alternative on how I can do this?
Thank you.
Hi Cute Bear,
You can also set the language on the layout and use the same layout on the different modules.
In this case, you don't have to set it up on each screen, but you just code it once in the layout and will affect all the screens using that layout.
Kind Regards,João
Hi CuteBear,
There are variations to do this.
One possibility is to use a client variable HaveTheLanguageBeenSet which starts at False.
Your logic would be if the client variable is set to True, do nothing. Otherwise, get the language, set the current locale and set the client variable to True. In this way, you only run it once.
It's not a good practice to call things on the OnInitialize indeed, but in this way, the consequence is minimum given it will only run the server action once and your server action should be a very simple query which should be very fast, hardly noticeable on performance (which is the consequence of using server actions in the OnInitialize event).
Hi,
Have you tried to run this logic (set locale) on the OnApplicationReady action? That would be my suggestion.
You will need to take into consideration also the scenario when the user has changed the locale on that logic, you might want the application to remain with the locale that the user selected.
Regards,
PZ
Hello @Paulo Zacarias,
I have but the OnApplicationReady only runs in the Home module, and I have end-user screens in several modules...
In that case, you can, for instance, develop a server action in one of your bottom layers and then reuse this action on the OnApplicationReady of each UI module.
You just need to add the system event:
However, I agree with João when he says that the locale should be placed immediately after login.
This is just an alternative.
I would suggest to set the default language, immediately after login.
You would have your login server action which would retrieve the default language and then use the SetCurrentLocale built-in client action to set it up.
Hello @João Marques,
Even though the screens are registered, I don't really have a login action. There is single sign-on set up by my company... So it automatically gets the credentials from Active Directory, I guess, no need for the end-user to do any kind of login.
Hello @João Marques ,
That would be good, I do have a layout that is being used in all modules. But where should I place these actions? Once again, it's not a good practice to call a server action in an "OnInitialize" event... but the language should be set before the screens render for the 1st time...
Indeed. Note that we're talking about a warning here, but not all warning are valid. I'd say in this case it's perfectly fine calling a server action.