22
Views
5
Comments
Solved
Server actions SetCurrentLocale / GetCurrentLocale: do they work?
Application Type
Reactive

Hello,

Just a simple question: do the pair of server actions: SetCurrentLocale / GetCurrentLocale work at all in Reactive applications? It seems to me that they just don't work...

If not - what is the way to change the current locale and use it server side?

Regards

Tomasz

Solution

Hello everyone,

I've done some investigations. The conclusions and the solutions are as follows.

The issue is, that in the Reactive Model the locale, set by the server SetCurrentLocale action, is persistent only within the same server call. Thus the following will not work:

The locale, set by SetLanguage (that calls the server SetCurrentLocale action; this action cannot be called directly from Client / Screen action) will not be visible in the next called AnyServerAction.

And the locale, set client side (e.g. by the client SetCurrentLocale action) is not reflected on the server side:

So, the current locale must be passed directly to the server action. This action can persist it using the server SetCurrentLocale that will change the locale that will be possible to read using the server GetCurrentLocale - but still only within this particular server call.

When we cannot add a parameter to the AnyServerAction, we must create a wrapper: a server action that gets the same parameters as AnyServerAction + Locale, sets the locale and calls AnyServerAction.

In a Screen Action we can pass locale directly using the client GetCurrentLocale action. In the cases when we cannot call the client GetCurrentLocale (e.g. in an aggregate or a Data Action) we must:

  • create a screen / block local variable (e.g. Locale)
  • initialize it in OnInitialize (using the client GetCurrentLocale)
  • use this variable instead of calling client GetCurrentLocale

Regards

Tomasz

Champion

Hello,

If you are in Reactive why you want to SetCurrentLocale in server side?

You should use the client action for that.

Regards, Paulo Torres

Hello.

I need server side actions because I have translations of transactional data, like names of client's products. Or I need to send the current locale to an external application via REST API.

So, I must be able to get the current locale server side. And the combination: client Set / server Get doesn't work as well.

Regards

Tomasz

Champion

If I'm not wrong the translations works only for client-side, not for server-side. To send this to the API I believe you need to create logic.

But let's wait for more inputs.

Regards, Paulo Torres

Hello,

Translations: I believe you mean the translation mechanism offered by OS. I mean any custom functionality allowing to enter language versions of a given name (by a users, runtime) and then - displaying them in views, regarding currently selected language. Nevertheless it requires that server side knows, what is the currently selected language.

Regards

Tomasz

Solution

Hello everyone,

I've done some investigations. The conclusions and the solutions are as follows.

The issue is, that in the Reactive Model the locale, set by the server SetCurrentLocale action, is persistent only within the same server call. Thus the following will not work:

The locale, set by SetLanguage (that calls the server SetCurrentLocale action; this action cannot be called directly from Client / Screen action) will not be visible in the next called AnyServerAction.

And the locale, set client side (e.g. by the client SetCurrentLocale action) is not reflected on the server side:

So, the current locale must be passed directly to the server action. This action can persist it using the server SetCurrentLocale that will change the locale that will be possible to read using the server GetCurrentLocale - but still only within this particular server call.

When we cannot add a parameter to the AnyServerAction, we must create a wrapper: a server action that gets the same parameters as AnyServerAction + Locale, sets the locale and calls AnyServerAction.

In a Screen Action we can pass locale directly using the client GetCurrentLocale action. In the cases when we cannot call the client GetCurrentLocale (e.g. in an aggregate or a Data Action) we must:

  • create a screen / block local variable (e.g. Locale)
  • initialize it in OnInitialize (using the client GetCurrentLocale)
  • use this variable instead of calling client GetCurrentLocale

Regards

Tomasz

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.