I
I
Igor2017-10-10 07:31:08
Drupal
Igor, 2017-10-10 07:31:08

How to programmatically switch language in DRUPAL8?

There is a multilingual site. How to switch language programmatically?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2017-10-10
@nimfai

$lang_code = 'en';     
\Drupal::configFactory()->getEditable('system.site')->set('default_langcode', $lang_code)->save();

A
afi13, 2017-10-10
@afi13

From the description of the question it is not very clear why you need it and what the problem is. If you described the problem in more detail, it would be easier for you to advise something.
Especially for this, there is a Language field in the user profile. And in the language detection settings, you can enable the use of the user's language (and even several detection methods and determine their order).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question