0

Is there a way to programmatically get the language of the admin user that is logged in?

2 Answers 2

0

To acheive this you would need to do something like this

namespace Vendor\Extension\Block;

use Magento\Backend\Model\Auth\Session
use Magento\Framework\View\Element\Template;

class View extends Template
{
    protected $authSession;
    public function __construct(Session $authSession)
    {
        $this->authSession = $authSession;
    }

    public function getCurrentUser()
    {
        return $this->authSession->getUser();
    }
    /** 
     * This should return back the users locale 
     */
    public function getUserLocale()
    {
        return $this->getCurrentUser()->getInterfaceLocale();
    }
}
0

Please follow this-

<?php
namespace VendorName\ModuleName\Helper;
class LocaleLanguage extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $customerRepoInfterface;
    protected $authSession;
    public function __construct(
        \Magento\Framework\App\Helper\Context  $context,
        \Magento\Backend\Model\Auth\Session $authSession
    )
    {
        $this->authSession = $authSession;
        parent::__construct($context);
    }

   

    public function getAdminUserLocale()
    {
        return $this->getCurrentAdminUser()->getInterfaceLocale();
    }

    public function getCurrentAdminUser()
    {
        return $this->authSession->getUser();
    }

  


}

May be it is helping you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.