Change language of a JS element when language has been changed from Drupal language switcher?
Something like this is what you're looking for I think.

theme_js_alter($js) {
  $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
  foreach ($js as $key =&gt; $value) {
    if (strpos($value['data'], 'www.websiteofapi.com/alpportal/oa_head.js') !== 0) {
      $value['data'] = "//www.websiteofapi.com/alpportal/oa_head.js?proj=api-of-our-company&amp;key=api-key-goes-here&amp;lang=$language&amp;leaflet_gshim=1"
    }
  }
}


Also see Get current language in template