trados2019、2021 bug

I had some issues with my plugin code on trados2019. When I added the translation plugin in the project Settings, clicking OK failed to trigger the CurrentProjectChanged event, 

Trados Studio 2019 interface showing project settings with a red box highlighting the OK button which fails to trigger the CurrentProjectChanged event.

my code:

public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, 
			ITranslationProviderCredentialStore credentialStore)
        {
            string version = TradosUtils.GetStudioVersionFriendly();  // 获取当前trados版本,例如17.1.6

            IOLTranslationOptions Options = new IOLTranslationOptions(MtTranslationProviderFactory.transnProviderUri);

            var provider = new MtTranslationProvider(Options);

            if (m_setForm != null)
            {
                // 二次挂载,清空数据
                m_setForm.Dispose();
                m_setForm = null;
            }

            Logger.Debug("加载翻译插件,ITranslationProvider[] Browse");

            var projectController = SdlTradosStudio.Application.GetController<ProjectsController>();

            projectController.CurrentProjectChanged += (s, e) =>
            {
                if (m_setForm == null)
                {
                    return;
                }

                if (m_setForm != null && m_setForm.DialogResult != DialogResult.OK)
                {
                    return;
                }

                // 创建项目完成,点击关闭时,触发该事件
                // 在左下角,从编辑器转到项目视图时,也触发该事件
                if (projectController.CurrentProject == null)
                    return;

                string filePath = projectController.CurrentProject.FilePath;
                Logger.Info($"current project path = {filePath}");

                string fullPath = Path.GetFullPath(filePath);

                // 解析文件所在的目录
                string directory = Path.GetDirectoryName(filePath);
                string fileName = Path.GetFileName(filePath);

                // 保存术语库语料库信息
                directory += "/transn_plugin/transn.ini";
                SaveConfig(directory, fileName);

                m_setForm.Dispose();
                m_setForm = null;

                CommonParas.Instance.ClearData();  // 保存后,清空全局的数据,项目切换后,这些全局数据就无效了
            };

            projectController.CurrentProjectChanging2 += (s, e) =>
            {
                int a = 1;
            };

            // 创建项目时关闭,恢复相关static值
            CommonParas.Instance.ClearData();
            
            ActionHelper.IsClickedGetMT = true;

            CommonParas.Instance.tgc = "";

            var loadOptions = new IOLTranslationOptions();
			var firstDialog = new TransnLoginForm(loadOptions);

            // 根据原文译文,确定语种方向,例如中文zh,德文de, 匹配后台接口中的iso6391字段
            foreach (var languagePair in languagePairs)
            {
                var originLanguage = languagePair.SourceCultureName.Substring(0, 2).ToLower();
                var targetLanguage = languagePair.TargetCultureName.Substring(0, 2).ToLower();

                CommonParas.Instance.originLanguage_iso6391 = originLanguage;
                CommonParas.Instance.targetLanguage_iso6391 = targetLanguage;  // 目标语言可能有多个, 翻译时取第0个
                break;
            }

            // 检查token
            string token = CConfigFileOperator.GetIniPrivateValue("PluginConfig", "token");
            SetSupportedLanguages(languagePairs, loadOptions);

            string response = string.Empty;
            int tokenResult = ApiConnecter.IsEffectiveToken(token, ref response);

            // 解析json
            if (tokenResult == 0)
            {
                CTokenCheckResp result = JsonConvert.DeserializeObject<CTokenCheckResp>(response);
                CommonParas.Instance.NickName = result.nickname;
            }
            else 
            {
                if(tokenResult == -1)
                {
                    MessageBox.Show("服务请求超时,请检查电脑是否连接网络");
                    return null;
                }
                else
                {
                    if (firstDialog.ShowDialog(owner) != DialogResult.OK)
                    {
                        return null;
                    }
                }
            }

            m_setForm = new SetForm();
            if(m_setForm.ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            //projectController.RefreshProjects();

            return new ITranslationProvider[] { provider };
        }

In trados2022, when the plug-in is mounted, clicking OK (in red) will trigger CurrentProjectChanged event, but in trados2019, CurrentProjectChanged event will not be triggered. Due to the requirements of our project, I need to save some configurations by clicking OK (red box in the picture above), but it cannot be triggered, resulting in my configuration failing to be saved. Is there a solution.



Generated Image Alt-Text
[edited by: Trados AI at 1:41 PM (GMT 0) on 5 Mar 2024]