Calling TM Providers via the API

Hi,

We have two questions related to the use of TM Providers in Trados Studio:

  1. Is it possible to download via API only information about plugins that are of the "TMs engine plugin" type that can be used in the translation resource (as in the screenshot)? We would like to download a list of tms engine plugins installed in trados. Is there any special method for this? If not, then how can we determine if a given plugin is of the "TMs engine" type? The method IPluginRegistry DefaultPluginRegistry returns all installed plugins, unfortunately it does not specify the type, e.g. TMS engine


  2. How should we use the API, that the project uses a given TM engine? Should we use fileBasedProject.UpdateTranslationProviderConfiguration?

Top Replies

  •  

    For some reason I cannot add links to the documentation in the comments so I'll just have to point you to what to search on google:

    1. TranslationProviderManager.GetTranslationProviderFactories…

  •  

    For some reason I cannot add links to the documentation in the comments so I'll just have to point you to what to search on google:

    1. TranslationProviderManager.GetTranslationProviderFactories() method which should give you a list of all TPs.

    2. "Adding the TM to the Project producthelp" and this Code Sample.

  • Thank you Emanuel, your answer is great help to us!


  • During next steps another issue related to the topic came up, would you be able to help us this time as well?

    In words of our developer it presents as below:
    If i used TranslationProviderManager.GetTranslationProviderFactories() then i get specific translation provider. Good. But if i need to add tm plugin engine to project, i need URi of this translation provider. So how can i get it? Is there any method to it? Can I use the selected engine without knowing its uri?

  • Hi ,

    Is it possible to download via API only information about plugins that are of the "TMs engine plugin" type that can be used in the translation resource (as in the screenshot)? We would like to download a list of tms engine plugins installed in trados. Is there any special method for this? If not, then how can we determine if a given plugin is of the "TMs engine" type? The method IPluginRegistry DefaultPluginRegistry returns all installed plugins, unfortunately it does not specify the type, e.g. TMS engine

    It is possible to get a list of extensions from the plugin manager by attribute type (e.g. TranslationProviderFactoryAttribute) and validate whether it supports a uri scheme and/or host:

    Example:

    var extensionPoint = PluginManager.DefaultPluginRegistry.GetExtensionPoint<TranslationProviderFactoryAttribute>();
    if (extensionPoint == null)
    {
    	return;
    }
    foreach (var extension in extensionPoint.Extensions)
    {
    	// 1. identify if the provider is enabled
    	if (!extension.Enabled)
    	{
    		continue;
    	}
    
    	// 2. identify if the extension is a provider of interest to you
    	// from here you can identify the type
    	// extension.ExtensionType == etc..
    	// extension.Plugin.Id == etc...
    
    	// 3. create an instance of the providers factory
    	var factory = (ITranslationProviderFactory)extension.CreateInstance();
    	if (factory == null)
    	{
    		continue;
    	}
    
    	// 4. check if a specific uri is supported by the provider
    	var supported = factory.SupportsTranslationProviderUri(new Uri("scheme://my.domain.com"));
    }    


    How should we use the API, that the project uses a given TM engine? Should we use fileBasedProject.UpdateTranslationProviderConfiguration?

    Yes, correct, please make reference to the example from 

  • Hi ,  the uri needs to be known in order to add a provider to a project, but seeing as it is part of the provider that is eventually created by the factory it is not exposed from the factory instance.

    You could however recover the uri from the cascade entries (e.g. providers) that are added to a project.

    Example:

    var projects = projectsController.GetAllProjects();
    foreach (var project in projects)
    {
        var translationProviderConfiguration = project.GetTranslationProviderConfiguration();
        foreach (var cascadeEntry in translationProviderConfiguration.Entries)
        {
            // TODO: add to a distinct list of providers
            var uri = cascadeEntry.MainTranslationProvider.Uri;
        }
    }
  • Hi
    Thank you for your explanation,
    Could you please also advise what in case when specific TM plugin is not yet added to any project?
    Can we get it's URI in this case?
    Kind Regards,
    Tomasz

  • You can recover the uri of the providers from the project instances or project files (xml), but not possible to identify the uri before hand, as it is assigned when the provider is created (via the factory as explained earlier); + how developers code the provoder is entirely at their own discretion as long as they fully implement the ITranslationProvider interface.

    You could attempt to load the providers via reflection, but I wouldn't advise it as best practice assumes that data is injected via the constructor, which brings you right back to the initial problem!

    If you need to obtain a list of the URI for all providers, why not simply create a project (or template) with all providers, and then either parse that data from the project xml or via the API if its loaded in the project container.  Make sense?

  • Thank you again for your help. Considering all of the information we aquired we have yet another question.
    Is it possible to aquire while using previously discussed method credentials for said plugins?

    If you need to obtain a list of the URI for all providers, why not simply create a project (or template) with all providers, and then either parse that data from the project xml or via the API if its loaded in the project container.  Make sense?

    We want to implement a solution where user can configure all of the plugins in one project in Trados and then our product could use them in integration.

    We found a post about similar case on community under https://community.sdl.com/developers-more/developers/language-developers/f/sdk_qa/4392/how-can-i-access-stored-groupshare-credentials-from-sdl-sdk however it was 6 years ago and we wonder if maybe something has changed?
    Kind regards,
    Tomasz

  • Hi , I understand.

    Unfortunately it is not possible to recover the users credentials via the API and for good reason!

    How the the credentials are managed is at the discretion of the developer that architected the provider; it can be different for each provider... some chose to save a physical settings file (encrypted), most use the integrated credential store from the API (which is also encrypted).

    To access a provider, the credentials need to be known; what I can recommend in your case is manage your own cache or access point (API) to recover those credentials given each provider.