How to get the language code when a language name is given?
You can do it with this code.

// Language to search.
$find = 'French';

// Getting all the available languages.
$languages = \Drupal::service('language_manager')-&gt;getStandardLanguageList();

$key = key(array_filter($languages, function ($array) use ($find) {
  if (array_search($find, $array) === FALSE) {
    return FALSE;
  }
  return TRUE;
}));

// If you have the devel module installed you can use the dpm function.
dpm($key);