Change language of a JS element when language has been changed from Drupal language switcher? First of all, sorry for the really confusing title, but I have no idea how to make it more reader friendly.
On my website, there are three languages: English, Finnish and Swedish. The user can change between these languages from the default Drupal language switcher.
Now the key part of the website comes from an API that I think is in JS. That JS element has its own language changing parameter.


  src="//www.websiteofapi.com/alpportal/oa_head.js?proj=api-of-our-company&amp;key=api-key-goes-here&amp;lang=sv&amp;leaflet_gshim=1">


So in order to change the language of the JS element I would need to change that "lang=" part to what language I want.
I have that script with the address to the API in my page.html.twig file to make the API call to work all across the site.

Is there a way to change the lang=sv to lang=en and lang=fi when the user changes the language through Druapl language switcher?

From the companys API support they said:


  you have different pages for different languages:
  website.fi/drupal/ (englisch)
  website.fi/drupal/sv 
  website.fi/drupal/fi 
  This means that you should have a different script tag for each of these
  paths. I guess Drupal allows that with help of a language variable
  that is accessible in your page template. (But I really know little
  about Drupal, so that's just a guess)


I am sorry for a long and confusing post, but it is really crucial to get this to work and I am losing my mind.
PS! I am really new to Drupal.
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