Allow to change the current language

Created on 20 January 2015, almost 10 years ago
Updated 12 December 2023, about 1 year ago

Problem/Motivation

The language manager has the ability to set a configuration override language. That works for example for user_mail(), where we just need to load configuration in the language of the user.

However, more advanced cases need to be able to change the current language completely. For example Simplenews, where we are building newsletter issues, that includes viewing entities, t() calls in e.g. templates, views queries that use the language context.. all kinds of things.

This is what we used to do in 7.x: https://github.com/iwanfux/simplenews/blob/7.x-2.x/includes/simplenews.s...

Proposed resolution

Add a setCurrentLanguage($type, Language $language), that returns the current language for that type, so it can be set back again.

Thought about something as fancy as the account switcher service/API, but I don't think that is needed. This s not security critical (forgetting to set the language back would be a bug, but not something that gives a user accidently super admin permission for the rest of his request, or something like that).

Remaining tasks

User interface changes

API changes

New methods on the LanguageManagerInterface.

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated 1 day ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024