How do I programmatically add a new language?
You can use below way:

 \Drupal::service('module_installer')-&gt;install(['language']);  
  $langcode = 'ca'; // get language from Your Form Input
    //print_r($langcode);       
  $language = ConfigurableLanguage::createFromLangcode($langcode);
  $language-&gt;save();