get language on form alter
The code to get the entity language is present in language_form_alter(), which you can take as an example to write your code.

  $form_object = $form_state-&gt;getFormObject();
  if ($form_object instanceof ContentEntityFormInterface &amp;&amp; $form_object-&gt;getEntity()-&gt;getEntityType()-&gt;hasKey('langcode')) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $form_object-&gt;getEntity();
    $entity_type = $entity-&gt;getEntityType();
    $langcode_key = $entity_type-&gt;getKey('langcode');

    // Your code goes here.

  }


If you are sure the edit form is for a content entity (such as a node), you could remove the part verifying that $form_object is a content entity object. I would leave it, but that is my personal preference.