97
Views
12
Comments
Solved
Reactive application - Some translations do not appear when switching languages

Hi everyone,

when i change the language of my application the common blocks are not translated correctly. Attached you will find various screenshots that may be useful to you.

Do you happen to know what the problem could be?


A thousand thanks

Giacomo

translation.PNG
en.PNG
it.PNG
structure.PNG
2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

ok,

these are the players in the game :

1) so the switcher block is just an example, you don't need it, whatever logic you already have in place to allow the user to choose a locale, or your application to choose a locale at start, IN THAT PLACE, you should update the client variable.  So whenever the locale changes, update client variable.

2) that small OnChange block is a smart little helper to allow other screens or blocks to react to changes in any data inside their scope they are interested in.  How it works is : It has an input, and whenever the value of that input changes, it detects that in it's OnParametersChanged, and it fires the Changed event to notify it's parent block that that particular variable has changed.

3) So the Listener has as only content that OnChange block (2), passing into it that client variable(1).  The only logic it has : it passes the change event of that OnChange block up as a CurrentLocaleChanged event to it's own parent.

4) Any block or screen that uses text from a static entity to display, can put this listener block(3) on it's canvas, and handle the CurrentLocaleChanged event by refreshing the aggregate or DataAction retrieving the static entity.

here's how it unfolds in action :

  • your user chooses another language
  • in the action that changes the current locale, the client variable also is changed
  • each instance of the OnChange block runs it's OnParametersChanged, fires the Changed event (x)
  • each instance of the CurrentLocaleListener block handles that event (x) by firing the CurrentLocaleChanged event (y)
  • each block or screen that has a CurrentLocaleListener handles the event (y) in it's own action, doing what needs to be done (for example refreshing an aggregate)

Dorine

2021-09-06 15-09-53
Dorine Boudry
 
MVP

are you talking about the steps 1 - 2 - 3 - 4 at the left of the screen ?

maybe these are coming from a static entity ?  In that case, you need to refresh your data everytime the language changes.

Dorine

2023-05-12 11-01-41
Giacomo Socini

Hi Dorine,

The step on the left come from static entity.

How can I refresh it every time? The change language happened into another block..


Thanks

Giacomo

step-entity.PNG
change-language.PNG
2021-09-06 15-09-53
Dorine Boudry
 
MVP

Ok,

so that's the reason.

You'll have to make sure that all blocks (or at least those showing labels of static entities) currently visible in the screen get notified of a change in locale, and react to it by refreshing their static entity aggregates/dataactions.  

With the normal event triggering of Outsystems (you already have an OnLanguageChange trigger defined for that)  passing up with events to the screen level, then passing down with OnParametersChanged to all underlying blocks.

Or if that's too much of a hassle because of the complexity of your screen and all it's parts, some DIY eventing / listening system.  

Dorine

2021-09-06 15-09-53
Dorine Boudry
 
MVP

See as a possible example how you could brew your own listening pattern for locale changes, look at blocks CurrentLocaleSwitcher, CurrentLocaleListener and OnChange, in combination with a CurrentLocale client variable.

This means you have to put a listener block in every scope (screen or block) that retrieves static entities, so you can go ahead and refresh those in the handler of that block's CurrentLocaleChanged event.

Dorine

CanvasBugReactiveChanged.oml
2023-05-12 11-01-41
Giacomo Socini


Hi Dorine, sorry but I'm having a hard time understanding how it works...

In the CurrentLocalSwitcher block I change the variable with the selected language.

I don't understand how CurrentLocaleChanged inside a CurrentLocaleListner can intercept the change... and why local listener have inside only OnChange block


A thousand thanks

Giacomo

exemple.PNG
2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

ok,

these are the players in the game :

1) so the switcher block is just an example, you don't need it, whatever logic you already have in place to allow the user to choose a locale, or your application to choose a locale at start, IN THAT PLACE, you should update the client variable.  So whenever the locale changes, update client variable.

2) that small OnChange block is a smart little helper to allow other screens or blocks to react to changes in any data inside their scope they are interested in.  How it works is : It has an input, and whenever the value of that input changes, it detects that in it's OnParametersChanged, and it fires the Changed event to notify it's parent block that that particular variable has changed.

3) So the Listener has as only content that OnChange block (2), passing into it that client variable(1).  The only logic it has : it passes the change event of that OnChange block up as a CurrentLocaleChanged event to it's own parent.

4) Any block or screen that uses text from a static entity to display, can put this listener block(3) on it's canvas, and handle the CurrentLocaleChanged event by refreshing the aggregate or DataAction retrieving the static entity.

here's how it unfolds in action :

  • your user chooses another language
  • in the action that changes the current locale, the client variable also is changed
  • each instance of the OnChange block runs it's OnParametersChanged, fires the Changed event (x)
  • each instance of the CurrentLocaleListener block handles that event (x) by firing the CurrentLocaleChanged event (y)
  • each block or screen that has a CurrentLocaleListener handles the event (y) in it's own action, doing what needs to be done (for example refreshing an aggregate)

Dorine

2023-05-12 11-01-41
Giacomo Socini

I tried to follow the instructions and this is the result. I don't know what to put in the handler, see the attachment.

handelr-missing.PNG
error.PNG
2021-09-06 15-09-53
Dorine Boudry
 
MVP


so you are going with the option to use the normal eventing system of Outsystems ?  Yes ?

In that case, if your event is mandatory, all the parents of that menu block (i.e. all screens) will need to define a handler.  I would not set it mandatory, you only need to handle it on those screens that have static entities somewhere.

I think you just added the DataChanged event for it, I don't understand, you already had the LanguagesChanged event ??

So on the screen with your wizard, you will add a handler for the event (i.e. attach an (existing or new) action to the event)

If your aggregate is in the screen, just refresh it in that handler action you just created.

If your actual aggregate is not in the screen, but in a block holding that wizard, you will need a way to pass the information that language has changed, into that block.  Unfortunately, you can't use events for that, but the OnParametersChanged action of that block.

So one possibility : 

  • in the event of the menu saying that language has changed, also have an input parameter with the currentlocale.  
  • In the screen also have a local variable with the currentlocale. 
  • In the handler of the menu's event on the screen, update that local variable of the screen.  
  • In the wizard block, have as input, the currentlocale, and pass into that, the local variable of the screen.
  • In the wizard block, also have a local variable, with the previous currentlocale
  • In the OnParametersChanged of the block, check if the input variable currentlocale is different from the local variable currentlocale, and if so, update the local variable and refresh the aggregate.

You can see that the normal mechanism of Outsystems is a bit worthy / messy, especially if you have blocks several levels deep, I prefer to use my own.

Dorine

2023-05-12 11-01-41
Giacomo Socini


As for the errors that were shown, it was because I had confused and created two identical events. Now the event propagates to all screens but I can't get it to the blocks used in the different screens. Is there a way or not? 

A thousand thanks 

leftmenu.PNG
2021-09-06 15-09-53
Dorine Boudry
 
MVP

yes, see all the bullet points under "So one possibility"

2021-09-06 15-09-53
Dorine Boudry
 
MVP

also, if this is overwhelming, make sure to (re)visit learning material on OnParametersChanged

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