private function getLanguage($language, $defaultLanguage = null)
    {
        $languageEntity = null;
        if ($language !== null && $language !== '') {
            if ($language instanceof \Newscoop\Entity\Language) {
                $languageEntity = $language;
            } elseif (strpos($language, '-') !== false && count($language) === 2) {
                $languageEntity = $this
                    ->em->getRepository('\Newscoop\Entity\Language')
                    ->findByCode($language);
            } else {
                try {
                    $languageEntity = $this
                        ->em->getRepository('\Newscoop\Entity\Language')
                        ->findByRFC3066bis($language);
                } catch(Exception $e) {
                    $languageEntity = null;
                    $this->logger->info(__METHOD__ . ': Language for entry could not be found. Reverting to default language.');
                }
            }
        }

        // Use default language if no language is set or if the found
        // languages are not allowed in our selected languages
        if (!in_array($languageEntity, $this->allowedLanguages)) {
            $languageEntity = $defaultLanguage;
        }

        return $languageEntity;
    }