Change the default language of an anonymous user

0
Is there a way to change anonymous users who are viewing your application default language from the default one you set in the Modeler persistently? I've tried the obvious https://community.mendix.com/questions/4902/Change-language-of-anonymous-user#9168, but it did not work. I'm currently trying to modify the Deeplink module StartDeepLinkJava and change the createGuestSession method to have it add a different language, but it doesn't seem to be working. final IMendixObject role = query(context, UserRole.getType(), UserRole.MemberNames.Name, Core.getConfiguration().getGuestUserRoleName()); User guestUser = User.create(context); final IMendixObject l = Core.retrieveXPathQueryEscaped(context, "//%s[%s='%s']", "System.Language", "Code", "en_US").get(0); Language lan = new Language(context); lan.setCode(context, l.getMember(context, "Code").getName()); lan.setDescription(context, l.getMember(context, "Description").getName()); guestUser.setUser_Language(lan); guestUser.setName("Guest_" + UUID.randomUUID()); guestUser.setIsAnonymous(true); guestUser.setPassword(UUID.randomUUID().toString()); guestUser.setUserRoles(Arrays.asList(new UserRole[]{ UserRole.initialize(context, role) })); Core.commit(context, guestUser.getMendixObject()); ISession session = Core.initializeSession(context, Core.getUser(context, guestUser.getName()), null, ""); setCookies(response, session); return session; My code is indented. If I set the guestUser language the deeplink requests to login into the system. Maybe this is not even the way to do it? Where exactly is the default language set for the anonymous user, is it the session or the user variable? If you try to retrieve the guestUser language it returns null.
asked
2 answers
2

In your code you are creating a new language and assigning it to the user. This won't work, because there are no texts in the model assigned to your new language. I think the way to go is to assign the language you retrieved ("IMendixObject l") to the user. Something like:

 Language lan = Language.initialize(context, l);
 guestUser.setUser_Language(lan);

I also think the way it's done in the forum post you linked should work, as long as you make sure you refresh the whole page in the browser, so that the client is fully reloaded.

From your comment it seems you want to do this based on the location of the user. How are you determining this location?

answered
0

Could you not solve it to create language buttons on the default anonymous landing page? So that when a anonymous user clicks on this button that you set the language off the current anonymous user and do a page refresh?

Regards,

Ronald

answered