public SdlMTCloudLanguageDirection(SdlMTCloudTranslationProvider translationProvider, LanguagePair languageDirection, EditorController editorController)
 {
     _translationProvider = translationProvider;
     _languageDirection   = languageDirection;
     _translationUnits    = new List <TranslationUnit>();
     _editorController    = editorController;
 }
Beispiel #2
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            try
            {
                var options     = new SdlMTCloudTranslationOptions();
                var credentials = SplitCredentials(credentialStore, options);
                var window      = new OptionsWindow();
                var languages   = new Languages.Provider.Languages();

                var model = new OptionsWindowModel(window, options, credentials, languagePairs, languages);

                window.DataContext = model;

                window.ShowDialog();
                if (window.DialogResult.HasValue && window.DialogResult.Value)
                {
                    var clientId     = model.Options.ClientId;
                    var clientSecret = model.Options.ClientSecret;
                    var resendDraft  = model.Options.ResendDrafts;

                    var provider = new SdlMTCloudTranslationProvider(options)
                    {
                        Options = model.Options
                    };

                    SetCredentials(credentialStore, clientId, clientSecret, resendDraft, true);
                    return(new ITranslationProvider[] { provider });
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error($"{Constants.Browse} {e.Message}\n {e.StackTrace}");
            }
            return(null);
        }
Beispiel #3
0
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState,
                                                              ITranslationProviderCredentialStore credentialStore)
        {
            var connectionService = new ConnectionService(StudioInstance.GetActiveForm(), new VersionService(),
                                                          StudioInstance.GetLanguageCloudIdentityApi());

            var credential       = connectionService.GetCredential(credentialStore);
            var connectionResult = connectionService.EnsureSignedIn(credential);

            if (!connectionResult.Item1)
            {
                throw new TranslationProviderAuthenticationException(PluginResources.Message_Invalid_credentials);
            }
            connectionService.SaveCredential(credentialStore);

            var editorController   = StudioInstance.GetEditorController();
            var translationService = new TranslationService(connectionService);
            var languageProvider   = new LanguageProvider();
            var projectsController = StudioInstance.GetProjectsController();

            var provider = new SdlMTCloudTranslationProvider(translationProviderUri, translationProviderState,
                                                             translationService, languageProvider, editorController, projectsController);

            return(provider);
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            try
            {
                var uri = new Uri($"{Constants.MTCloudUriScheme}://");
                var connectionService = new ConnectionService(owner, new VersionService(), LanguageCloudIdentityApi.Instance);

                var credential       = connectionService.GetCredential(credentialStore);
                var connectionResult = connectionService.EnsureSignedIn(credential, true);

                if (!connectionResult.Item1)
                {
                    throw new TranslationProviderAuthenticationException(PluginResources.Message_Invalid_credentials);
                }

                connectionService.SaveCredential(credentialStore);


                var translationService = new TranslationService(connectionService);
                var langaugeProvider   = new LanguageProvider();
                var editorController   = SdlTradosStudio.Application?.GetController <EditorController>();

                var provider = new SdlMTCloudTranslationProvider(uri, string.Empty, translationService, langaugeProvider, editorController);

                return(new ITranslationProvider[] { provider });
            }
            catch (Exception e)
            {
                Log.Logger.Error($"{Constants.Browse} {e.Message}\n {e.StackTrace}");
            }

            return(null);
        }
Beispiel #5
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            //TODO: Instantiate the new Rate it View part
            try
            {
                var uri = new Uri($"{Constants.MTCloudUriScheme}://");
                var connectionService = new ConnectionService(owner, new VersionService(), StudioInstance.GetLanguageCloudIdentityApi(), MtCloudApplicationInitializer.Client);

                var credential       = connectionService.GetCredential(credentialStore);
                var connectionResult = connectionService.EnsureSignedIn(credential, true);

                if (!connectionResult.Item1)
                {
                    throw new TranslationProviderAuthenticationException(PluginResources.Message_Invalid_credentials);
                }

                MtCloudApplicationInitializer.PublishEvent(new TranslationProviderAdded());

                connectionService.SaveCredential(credentialStore);

                MtCloudApplicationInitializer.SetTranslationService(connectionService);

                var languageProvider = new LanguageProvider();
                var provider         = new SdlMTCloudTranslationProvider(uri, string.Empty, MtCloudApplicationInitializer.TranslationService,
                                                                         languageProvider);

                return(new ITranslationProvider[] { provider });
            }
            catch (Exception e)
            {
                _logger.Error($"{Constants.Browse} {e.Message}\n {e.StackTrace}");
            }

            return(null);
        }
Beispiel #6
0
 public SdlMTCloudLanguageDirection(SdlMTCloudTranslationProvider beGlobalTranslationProvider, LanguagePair languageDirection)
 {
     _beGlobalTranslationProvider = beGlobalTranslationProvider;
     _languageDirection           = languageDirection;
     _options          = beGlobalTranslationProvider.Options;
     _translationUnits = new List <TranslationUnit>();
     _editorController = AppInitializer.GetEditorController();
 }