How to Translate a Private Application with Weglot

In this article, you’ll learn how to use Weglot on a private web application (like a SaaS), allowing each user’s preferred language to be stored and used, without relying on language-specific URLs.


How it works

By default, Weglot uses subdirectories to display translations:

  • Original page: https://www.example.com/about
  • French version: https://www.example.com/fr/about


However, for private applications like SaaS tools, you might want to switch languages based on the user’s preferences, without changing the URL.


This approach is commonly used by platforms such as Notion, Stripe, Facebook, and X (formerly Twitter), where the language is saved in the user profile.

Example: Stripe user profile page where a preferred language can be selected.

Weglot can support this setup via a custom configuration. Here’s how.

Prerequisites

To implement this, your application must be able to store and recall the preferred language for each user.


Follow these steps:

  1. Store the preferred language in user profiles

    Create a property in your user database (e.g., a column like language_code) to store the 2-letter language code selected by each user.

  2. Add a language switcher

    Let your users choose their preferred language via a dropdown menu—ideally on their account or profile page.

  3. Send a custom HTTP response header

    Each time a page is loaded for a logged-in user, include the following HTTP response header:

    Weglot-Language-Preference: fr

    (Replace fr with the relevant 2-letter code for the selected language.)


You can inspect the header using Chrome DevTools > Network tab. Here’s an example of what this header should look like:

Installation

Once your web application includes the Weglot-Language-Preference header, you can proceed with the Weglot installation.

  1. Set up Weglot using a subdirectory integration

    Follow the standard installation steps for Weglot using the “Subdirectory” method.

    👉 How to use subdirectories with Weglot

  2. Check that the language subdirectories are working

    Make sure your translations are accessible through URLs like /fr/, /de/, etc.

  3. Contact our support team

    Once everything is set up, send us a message at support@weglot.com.

    Ask us to enable Private Application mode on your project.

    Once activated, Weglot will use the Weglot-Language-Preference response header instead of the URL path to determine the language to display.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us