Drupal 8 - Check if language prefix is present in url or not Is there a way in the drupal 8 api to figure out if a language prefix is present in the url or not? Cause I need this information in order to display a custom language switcher if no prefix exists in the url. So for language detection I only have the prefix enabled. 

Unfortunately this code is not working for me:

$languagecode = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();


Cause it always returns me a language. When no prefix is present in the url it returns me (as excepted) the fallback language.

Has someone a similar situation or can help me here?
There might be something more elegant, but doing it the dirty way is pretty simple:

$languagecode = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
$parts = array_filter(explode('/', \Drupal::request()-&gt;getRequestUri()));

$has_prefix = count($parts) &amp;&amp; $parts[0] == $languagecode;