Score:0

How get the language the current language for a REST request considering detection\selection settings?

br flag

I'm on D.9.4.x.

I'm writing a custom REST resource and I'd need to get the "current language id", in compliance with the "Detection and selection" site's settings (screenshot below).

I can't find a service\method that gives this information. I could e.g.

$user_language = $this->currentUser->getPreferredAdminLangcode();

and that would work with the current settings, but would be not anymore correct if at some point those change.

How can I get that info?

For reference,

$language = $this->languageManager->getCurrentLanguage()->getId();

isn't a working solution, if e.g. the url of the request is www.site.com/it/my-rest-end-point the result is it even if the user "preferred langcode" is en

settings

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.