private function checkLanguage($environment, $resetToFallback)
    {
        $sessionStorage = $environment->getSessionStorage();
        $dataProvider   = $environment->getDataProvider();
        $providerName   = $environment->getDataDefinition()->getName();
        $modelId        = $this->modelIdFromInput($environment->getInputProvider());
        $languages      = $environment->getController()->getSupportedLanguages($modelId);

        if (!$languages) {
            return;
        }

        // Exit out when not a multi language provider.
        if (!($dataProvider instanceof MultiLanguageDataProviderInterface)) {
            return;
        }

        // If a new item, we MUST reset to the fallback as that is the first language that has to be stored
        // and set this language to session.
        if ((null === $modelId) && $resetToFallback) {
            $dataProvider->setCurrentLanguage($dataProvider->getFallbackLanguage(null)->getLocale());
            $session['ml_support'][$providerName] = $dataProvider->getCurrentLanguage();
            $sessionStorage->set('dc_general', $session);
            return;
        }

        $this->checkLanguageSubmit($environment, $languages);

        // Load language from Session.
        $session = (array) $sessionStorage->get('dc_general');

        // Try to get the language from session.
        $currentLanguage = ($session['ml_support'][$providerName] ?? $GLOBALS['TL_LANGUAGE']);

        if (!\array_key_exists($currentLanguage, $languages)) {
            $currentLanguage = $dataProvider->getFallbackLanguage($modelId)->getLocale();
        }

        $session['ml_support'][$providerName] = $currentLanguage;
        $sessionStorage->set('dc_general', $session);

        $dataProvider->setCurrentLanguage($currentLanguage);
    }