Beispiel #1
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var editProvider = translationProvider as DeepLMtTranslationProvider;

            if (editProvider == null)
            {
                return(false);
            }

            //get saved key if there is one and put it into options
            var savedCredentials = GetCredentials(credentialStore, "deeplprovider:///");

            if (savedCredentials != null)
            {
                editProvider.Options.ApiKey = savedCredentials.Credential;
            }

            var dialog = new DeepLWindow(editProvider.Options, savedCredentials, languagePairs);

            ElementHost.EnableModelessKeyboardInterop(dialog);
            dialog.ShowDialog();
            if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
            {
                editProvider.Options = dialog.Options;
                var apiKey = editProvider.Options.ApiKey;
                SetDeeplCredentials(credentialStore, apiKey, true);
                return(true);
            }
            return(false);
        }
        public override void Execute()
        {
            var currentProject = SdlTradosStudio.Application.GetController <ProjectsController>().CurrentProject;

            if (currentProject == null)
            {
                MessageBox.Show(@"No project is set as active");
            }
            else
            {
                var settings = currentProject.GetTranslationProviderConfiguration();

                if (!settings.Entries.Any(entry =>
                                          entry.MainTranslationProvider.Uri.OriginalString.Contains("deepltranslationprovider")))
                {
                    MessageBox.Show(
                        @"DeepL is not set on this project\nPlease set it in project settings before using TellMe to access it");
                }
                else
                {
                    var translationProvider = settings.Entries.FirstOrDefault(entry =>
                                                                              entry.MainTranslationProvider.Uri.OriginalString.Contains("deepltranslationprovider"));
                    if (translationProvider != null)
                    {
                        var uri     = translationProvider.MainTranslationProvider.Uri;
                        var options = new DeepLTranslationOptions(uri);
                        var dialog  = new DeepLWindow(options, true);
                        dialog.ShowDialog();
                        if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                        {
                            settings.Entries
                            .Find(entry =>
                                  entry.MainTranslationProvider.Uri.OriginalString.Contains(
                                      "deepltranslationprovider"))
                            .MainTranslationProvider.Uri = options.Uri;

                            currentProject.UpdateTranslationProviderConfiguration(settings);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var options = new DeepLTranslationOptions();

            //get credentials
            var credentials = GetCredentials(credentialStore, "deeplprovider:///");

            var dialog = new DeepLWindow(options, credentials, languagePairs);

            ElementHost.EnableModelessKeyboardInterop(dialog);
            dialog.ShowDialog();
            if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
            {
                var provider = new DeepLMtTranslationProvider(options)
                {
                    Options = dialog.Options
                };
                var apiKey = dialog.Options.ApiKey;
                SetDeeplCredentials(credentialStore, apiKey, true);
                return(new ITranslationProvider[] { provider });
            }
            return(null);
        }