This module does three things differently from Drupal core:

  1. Automatically saves the user's preferred language when they switch languages.
  2. Displays language names in their native translations ("Español" instead of "Spanish"). What this means is visible in the picture to the right.
  3. Seamlessly transitions to the user's previously preferred language during login.

You need this module only if your multilingual site has users that are typically logged in.

Requirements

  • PHP 7.0 or higher
  • Drupal core version 8 - 12
  • A Drupal site with more than one language enabled

Installation

  1. Download the module. I suggest using Composer: composer require 'drupal/user_account_language_negotiation:^1.0'
  2. Enable the module, e.g. using drush en user_account_language_negotiation

Configuration

  1. Go to Detection and selection (/admin/config/regional/language/detection).
  2. Uncheck all plugins except this module's User account saver. Only if User account saver is the only enabled plugin we can be sure we manage the transition to the user's previously preferred language during their login.
  3. Make sure your users have a way of switching the language. If you haven't set up anything yet, you can visit the block list page (/admin/structure/block) and add Drupal Core's "Language switcher" block.

Inner workings

Technically speaking, this module just supplies a LanguageNegotiation plugin. It leaves the visual part of picking a language to other modules. A typical setup is to use Core's "Language switcher" block, optionally in conjunction with the Language Icons module. The picture above is from this setup.

This module acts in 3 situations:

  1. When the user opens a page, Drupal needs to know which language the page should be rendered in. If you are curious, see the getLangcode() function in the code.
  2. When the user just switched the language: save it in his or her account (processInbound()).
  3. When the language switcher block needs to know which languages exist (getLanguageSwitchLinks()).

Similar modules

  • Language Cookie remembers the visitor's language choice in a browser cookie instead of the user account. This also works for anonymous visitors, but the preference doesn't follow the user to a different browser or device the way an account-based preference does.

Maintainer

Support

To submit bug reports and feature suggestions, or to track changes, use the issue queue.

To say "thank you" or financially support development of this module, you can send a few Euros via PayPal: paypal@blaeul.de or various other means.

Project information

Releases