How to read project attributes from MT Provider plugin?

Hi SDL Community,

We want to handle the following use case scenario in our MT Plugin (https://appstore.sdl.com/language/app/alexa-translations-a-i/1066/).

Users have created some Projects on our system, let's say Project-A uses set A of Translation Memories, and Project-B uses set B of Translation Memories. Now a user wants to start translating two Projects from SDL Studio 2019 at same time by linking one SDL Project with Project-A, and the second SDL Project with Project-B on our system. When we add a field in our MT Plugin to let users add Project ID from our system, it gets updated for all SDL projects. Which means, our plugin object in SDL is kind of Singleton.

The quick solution could be, by accessing SDL Project's Description in our plugin and asking users to add Project ID generated by our system in SDL Project's Description. Is there a way to read Project Description from MT Plugin? From Project, I mean, the project which contains that document being translated by MT Plugin.

Any other way to support this requirement?

Thank you very much for the help.

  • Hi , you can access or update the project information via the ProjectInfo class of the current project; the current project can be retrieved from the Projects Controller.

    Example:

    using System; using System.ComponentModel;
    using System.Linq; using System.Runtime.CompilerServices;
    using Sdl.ProjectAutomation.Core;
    using Sdl.TranslationStudioAutomation.IntegrationApi;

    namespace Rws.Community.Example
    {
       public class CurrentProjectHelper: INotifyPropertyChanged
       {
          private readonly ProjectsController _projectsController;
      
       private IProject _currentProject;
          public CurrentProjectHelper(ProjectsController projectsController)
          {
             if (_projectsController == null)
             {
                return;
             }

             _projectsController = projectsController;
             _projectsController.CurrentProjectChanged += ProjectsController_CurrentProjectChanged;
             SetCurrentProject();
          }  

          public IProject CurrentProject
          {
             get
             {
                return _currentProject;
             }
             set
             {
                _currentProject = value;
                OnPropertyChanged(nameof(CurrentProject));
             }
          }

          public void UpdateProjectInfo(ProjectInfo projectInfo)
          {
             CurrentProject?.UpdateProject(projectInfo);
             CurrentProject?.Save();
          }

          public ProjectInfo GetProjectInfo()
         {
            return CurrentProject?.GetProjectInfo();
         }

         private void SetCurrentProject()
         {
            CurrentProject = _projectsController?.CurrentProject ??
                              _projectsController?.SelectedProjects.FirstOrDefault();
          }

          private void ProjectsController_CurrentProjectChanged(object sender, EventArgs e)
         {
            SetCurrentProject();
         }

         public event PropertyChangedEventHandler PropertyChanged;

         protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
          {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
          }
       }


       private void ExampleImplementation()
       {
          var projectHelper = new CurrentProjectHelper(SdlTradosStudio.Application?
                                              .GetController<ProjectsController>());
         
          var projectInfo = projectHelper.GetProjectInfo();
          if (projectInfo != null)
          {
             projectInfo.Description = "My description";  
             projectHelper.UpdateProjectInfo(projectInfo);
          }
       }
    }