Set language for context

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?
3 answers


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?


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.




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

    return enumeration.getCaption(language.getCode());

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!