How to programmatically add Termbase to a project with optimal language mapping

Dear All

When attaching a termbase to a project, the languages of the termbase needs to be mapped to the source- and targetlanguage of the project. Often the mapping is not perfect, so French (FR) has to be mapped to French Switzerland (fr-CH) or French France (fr-FR).

http://producthelp.sdl.com/SDK/ProjectAutomationApi/2017/html/7a0aa922-1aa2-4976-afd3-7637104f2def.htm

string[] termbaseIndex = { "English", "German", "French" };

Language projSourceLang = new Language(CultureInfo.GetCultureInfo("en-US"));
Language projTargetLang1 = new Language(CultureInfo.GetCultureInfo("de-DE"));
Language projTargetLang2 = new Language(CultureInfo.GetCultureInfo("fr-FR"));

Here they only show a simple example, where the language is hardcoded, however, i am interested in a general approach for an arbitrary termbase where the languages are extracted from the termbase.

The final touch would be to programmatically add the language to the termbase if it does not contain the project language parent, so if the sourcelanguage is de-CH and the termbase only has FR and IT then add DE.

Best
Marco