<-- Back

How to set application language for anonymous end-users

Introduction

The application language is set based on the default language configured in the project.

As stated in our documentation, Setting the End-User's Language, if the end-user is not associated with a language, for example, they are an anonymous user, the language used depends on the user's browser or operating system settings. If the language requested is not present up in the app, then the app's default language will be used

Enforcing a specific language for anonymous users in a Mendix application involves configuring the application settings and potentially adding some custom logic to ensure that the desired language is applied.
This article will demonstrate how to enforce a specific language setting for anonymous end-users.

Environment/Prerequisites

Web application

Instructions/Procedure

Here is a step-by-step guide to help to achieve this:

Step 1: Configure Language Settings

  1. Add Languages to Your Project:

    • Open your Mendix project in Mendix Studio Pro.

    • Go to Project > Settings.

    • Navigate to the Languages tab.

    • Add the languages to support by clicking the Add button and selecting the desired languages.

  2. Set a Default Language:

    • In the same Languages tab, set the default language for your application. This will be the language used if no other language is specified.

Step 2: Enforce Language for Anonymous Users

  1. Create a Microflow to Set Language:

    • Create a new microflow that will be used to set the language for anonymous users.

    • In the microflow, use the Change Language activity to set the desired language. Find this activity under the Misc section in the toolbox.

    • Configure the Change Language activity to set the language to your desired language (e.g., en_US for English). See all locale codes in the documentation link List of Supported Languages

  2. Call the Microflow on Startup:

    • Go to Project > Navigation.

    • Open the Anonymous users tab.

    • Set the Home page for anonymous users to a page that will call the microflow you created.

    • Alternatively, call the microflow directly from the Home page's On enter event.

Example Microflow

Here is a simple example of what the microflow might look like:

  1. Create a new microflow and name it SetLanguageForAnonymous.

  2. Add a Change Language activity:

    • Drag the Change Language activity from the toolbox into the microflow.

    • Set the language parameter to the desired language code (e.g., en_US).

    • End the microflow with an End Event.

Step 3: Test The Configuration

  1. Deploy and Run Your Application:

    • Deploy your Mendix application to your environment (local, test, or production).

    • Access the application as an anonymous user (e.g., by opening the application in an incognito window).

  2. Verify Language Enforcement:

    • Ensure that the user interface is displayed in the language you configured for anonymous users.

Additional Considerations

User Preferences: If the application allows users to select their language preferences after logging in, make sure that the language set for anonymous users does not interfere with logged-in users' settings.
Localization: Ensure that all elements of the application are properly localized for the languages supported. This includes text, date formats, number formats, etc.

Outcome

By following these steps, can be enforced a specific language for anonymous users in the Mendix application, ensuring a consistent user experience for all visitors.

Internal information related

  • 230939
  • CJZ85RLTA/p1729589231343049

Additional information

Have more questions? Submit a request

0 Comments

Article is closed for comments.

To provide feedback, please open a ticket here. Don't forget to include the article's URL along with the feedback you would like to provide.