Use hook to get the domain configuration from language We have enabled English, Spanish, and French on our site. On Regional and language >> Languages detection we selected URL for Content language detection >> Detection Method. For Part of the URL that determines language, we selected Domain. We then set the following domains.


English: example.com
Spanish: es.example.com
French: fr.example.com


How can we programmatically obtain the domain associated to each language? What code should we use in a preprocess function?
Using the following code, we obtained the list of the language, but we are far
 from getting the domain that has been associated with each language.

function mymodule_preprocess_html(&amp;$variables) {
  // to get all enabled languages
  $languages = \Drupal::languageManager()-&gt;getLanguages();

  // Did not find method to retrieve the domain configuration.
  foreach($languages as $key =&gt; $value) {
    ksm($languages[$key]);
    //stuck here on how to get domain configuration per language.
  }
}
The domain associated with each language is stored as configuration. Using the following code, $prefix will contain the prefix, and $domain the domain used.

  $config = \Drupal::configFactory()-&gt;get('language.negotiation');
  $languages = \Drupal::languageManager()-&gt;getLanguages();
  $prefixes = $config-&gt;get('url.prefixes');
  $domains = $config-&gt;get('url.domains');
  foreach ($languages as $langcode =&gt; $language) {
    $prefix = $prefixes[$langcode];
    $domain = $domains[$langcode];
  }


I wrote the code basing on NegotiationUrlForm::buildForm(), which is the form builder for the form that sets the negotiation URL for each language.