5
Views
4
Comments
Solved
Dynamically load a translation from the dictionary
Question
Application Type
Reactive
Service Studio Version
11.10.3 (Build 36711)

Hello, 


I'm trying to implement the "new" translation method (as described here : https://success.outsystems.com/Documentation/11/Developing_an_Application/Design_UI/Technical_Preview_-_Multilingual_Reactive_Web_and_Mobile_Apps ) and I don't understand if and how I can dynamically use a translation from the dictionary. 


Let's say I have a list of elements retrieved from the database, each element has a property "message_key" which should be linked to an entry in the dictionary. I was expecting to find a function or action like getTranslation(key, locale) I can use in an expression but I can't find anything like that. 


I also don't understand how I can manage variables in the translated expression: I was also expecting to be able to replace a key in the translated text but I don't see how I can do it without being able to retrieve an expression from the dictionary. 


Finally I can't find how to manually add an entry in the dictionary. 


Is there any way to solve this ? 

Thanks 


Ben

Rank: #70
Solution

Hi Benw,


I imagine you have an expression with something like: "You have " + amount + " on your " + accounttype + " account".

You can have the French translation like this:

  • "You have "  - empty
  • " on your " - disponibles sur votre
  • " account" - empty


If your account type is a static entity and you're using a label attribute, you can translate it also using Multilingual, so your field "savings account" would translate to compte épargne.

If your account type is a not-static entity, you will need to have a correspondent "AccountType_Translation" where you have the locale to filter and know which translation you want to pick from the Database.


I can understand it is a bit tricky as the translations I presented above are a workaround for your scenario. In that regard, you might want to create an application where you can save in the database the translations in a more dynamic way (see for instance the Message Forge component which handles translations in this fashion). You should think about the scenario that best fits your needs. If you opt to follow this route think about caching mechanism as you'll be relying heavily on the database for translations and you want to avoid performance hits.

Rank: #70

Hi Ben,


Using the "new" translation method, translations are defined on design time.

You just need to change the locale to have the application using the translations you defined. No need to use translation keys or any other added complexity.

In order to set the Locale, you can use SetCurrentLocale actions from System:


They are usually placed right after Login, on the OnSessionStart system event or when you toggle your language.


Hope it helps.


Regards,
João

Rank: #3760

Hello João, 

Thanks for your answer, however I'm not sure it helps me to solve my issue. 

I understand how to change the locale, however I don't understand how I can manipulate or retrieve translation strings at runtime.

A quick fictional example below : 

My application needs to show the following text: 

In English : 

You have 250,00 € on your savings account 

In French : 

250,00 € disponibles sur votre compte épargne 


At design time I don't know neither the amount nor the account type

In a non-outsystems application I would define an input like

EN : account_amnt   |  You have {amount} on your {acnt_type} account
FR : account_amn | {amount} disponibles sur votre compte {acnt_type}

An other example would be a dynamic value received from an external system like an error message key. 

Do you think I'll be able to achieve this with the built-in translation method or do I need to implement my own ? 


Thanks 


Rank: #70
Solution

Hi Benw,


I imagine you have an expression with something like: "You have " + amount + " on your " + accounttype + " account".

You can have the French translation like this:

  • "You have "  - empty
  • " on your " - disponibles sur votre
  • " account" - empty


If your account type is a static entity and you're using a label attribute, you can translate it also using Multilingual, so your field "savings account" would translate to compte épargne.

If your account type is a not-static entity, you will need to have a correspondent "AccountType_Translation" where you have the locale to filter and know which translation you want to pick from the Database.


I can understand it is a bit tricky as the translations I presented above are a workaround for your scenario. In that regard, you might want to create an application where you can save in the database the translations in a more dynamic way (see for instance the Message Forge component which handles translations in this fashion). You should think about the scenario that best fits your needs. If you opt to follow this route think about caching mechanism as you'll be relying heavily on the database for translations and you want to avoid performance hits.

Rank: #3760

Ok I'll try that. 

Thanks for your help !