user_account_language_negotiation
403 sites
Security covered
This module does three things differently from Drupal core:
- Automatically saves the user's preferred language when they switch languages.
- Displays language names in their native translations ("Español" instead of "Spanish"). What this means is visible in the picture to the right.
- Seamlessly transitions to the user's previously preferred language during login.
Recommended installation
- Download and install the module in your usual way (I suggest using Composer and Drush).
- Go to Detection and selection (/admin/config/regional/language/detection).
- 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.
- 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:
- 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. - When the user just switched the language: save it in his or her account (
processInbound()). - When the language switcher block needs to know which languages exist (
getLanguageSwitchLinks()).
Supporting this module
To say “thank you” or financially support development of this module, you can send a few Euros via PayPal: [email protected]