Set language for context

1
Our system sends email that are triggered by different types of triggers and that are configured in multiple languages. An English user might for instance trigger an email that will be sent to a French user. So what I would like to be able to do is create a new context which uses a specified language, and execute whatever creates the email within this context. Having the context in the correct language ensures that whenever caption for an enum is retrieved or whatever, that the correct language will always be used. I cannot find a clean way to do this however. The only way I can think of is horrible, and would be: Create a new user, set their language to French Create a new session for this user get context from this session Looking around at the Mendix Java API, I only see a method to retrieve language from a session. Does anyone have an idea?
asked
3 answers
0

Nikel,

If you know the user that should receive the mail, you know the language of the recipient. Based on this you could simply implement microflow/data logic to select the correct template to send to this user. For example add a language enum to the template and search for the templatetype with the specific language. Or am I missing something here?

answered
0

Erwin is right. This is what we did in our application. Create a string. Check the user language of the recipient. For each language that you will support use a split. In this split change the string with the right getCaptions from the different enumerations. Pass the resulting string to the next step. We also have a default language when the user has a language that is not supported. So it first checks all the supported languages and then defaults to the default language.

Regards,

Ronald

https://modelshare.mendix.com/models/1846f09f-fdae-4b83-b259-7ff86a087cae/change-string-based-on-language.

answered
0

Yes, this is a pain. We created a Java action for each enumeration (three) that had to be supported. Inputs: Enumeration, System.Language. Output: String

    // BEGIN USER CODE
    return enumeration.getCaption(language.getCode());
    // END USER CODE

I toyed with the user idea, but I found it too inelegant. Perhaps you could extend the Java code to accept String (which would have to be the getKey(enumeration) value) and System.Language inputs, and try to find the enumeration value of the string by iterating over enumerations and their values? Let me know your solution!

answered