Esempio n. 1
0
        public ITranslationActualizer GetTranslationActualizer()
        {
            ITranslationProvider    translationProvider    = GetTranslationProvider();
            ISysCultureInfoProvider sysCultureInfoProvider = GetSysCultureInfoProvider();

            return(GetTranslationActualizer(translationProvider, sysCultureInfoProvider));
        }
Esempio n. 2
0
 private static void TestTranslation(ITranslationProvider provider, CultureInfo src, CultureInfo tgt)
 {
     if (provider.IsSupported(src, tgt))
     {
         provider.Initialize(src, tgt, null);
         var response = provider.Translate(new TranslationRequest {
             RequestId = "1", Source = "The dog is blue.", MinimumConfidence = 50
         });
         Console.WriteLine($"Translate from {src} to {tgt}");
         Console.WriteLine($"   {response.Source}");
         if (response.IsTranslated)
         {
             Console.WriteLine($"   {response.Target}");
         }
         else
         {
             foreach (var error in response?.Errors)
             {
                 Console.WriteLine($"   {error.Message}");
             }
         }
         var suggestions = provider.Suggest(new SuggestionRequest  {
             RequestId = "1", Source = "The dog is blue.", MinimumConfidence = 50
         });
     }
 }
        public void SetService(ITranslationProvider service)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            this.service = service;
        }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var controlledMTProvider = (ControlledMtProvidersProvider)translationProvider;

            List<ITranslationProvider> mtProviders = new List<ITranslationProvider>();

            //move this to mmtProvider
          
            using (MTProvidersDialog pd = new MTProvidersDialog(controlledMTProvider))
            {
                DialogResult result = pd.ShowDialog(owner);

                if (result != DialogResult.OK)
                {
                    return false;
                }

                var mtProvidersUi = pd.SelectedTranslationProvidersWinformsUI;
                if (mtProvidersUi.Count == 0) return false;

                foreach (var mtProviderUi in mtProvidersUi)
                {
                    var innerProviders = mtProviderUi.Browse(owner, languagePairs, credentialStore);
                    if (innerProviders != null && innerProviders.All(x => x.TranslationMethod == TranslationMethod.MachineTranslation))
                    {
                        mtProviders.AddRange(innerProviders);
                    }
                }
            }
            controlledMTProvider.MtProviders = mtProviders;
            return true;
        }
Esempio n. 5
0
 private ITranslationActualizer GetTranslationActualizer(ITranslationProvider translationProvider,
                                                         ISysCultureInfoProvider sysCultureInfoProvider)
 {
     return(TranslationsCount > 0
                         ? CreateTranslationActualizer <TranslationActualizer>(translationProvider, sysCultureInfoProvider)
                         : CreateTranslationActualizer <TranslationBatchActualizer>(translationProvider, sysCultureInfoProvider));
 }
        /// <summary>
        /// If the plug-in settings can be changed by the user,
        /// SDL Trados Studio will display a Settings button.
        /// By clicking this button, users raise the plug-in user interface,
        /// in which they can modify any applicable settings, in our implementation
        /// the delimiter character and the list file name.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProvider"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>
        #region "Edit"
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var editProvider = translationProvider as MtTranslationProvider;

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

            //get saved key if there is one and put it into options
            //get google credentials
            var getCredGt = GetMyCredentials(credentialStore, "mtenhancedprovidergt:///");

            if (getCredGt != null)
            {
                editProvider.Options.ApiKey           = getCredGt.Credential;
                editProvider.Options.PersistGoogleKey = getCredGt.Persist;
            }

            //get microsoft credentials
            var getCredMt = GetMyCredentials(credentialStore, "mtenhancedprovidermst:///");

            if (getCredMt != null)
            {
                try
                {
                    var creds = new GenericCredentials(getCredMt.Credential); //parse credential into username and password
                    editProvider.Options.ClientId              = creds.UserName;
                    editProvider.Options.ClientSecret          = creds.Password;
                    editProvider.Options.PersistMicrosoftCreds = getCredMt.Persist;
                }
                catch { }//swallow b/c it will just fail to fill in instead of crashing the whole program
            }

            var dialog = new MtProviderConfDialog(editProvider.Options, credentialStore);

            //we are letting user delete creds but after testing it seems that it's ok if the individual credentials are null, b/c our method will re-add them to the credstore based on the uri
            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                editProvider.Options = dialog.Options;

                var apiKey = editProvider.Options.ApiKey;

                //we are setting credentials selectively based on the chosen provider to avoid saving the other if it is blank
                if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.PersistGoogleKey);
                }
                else if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    var creds2 = new GenericCredentials(dialog.Options.ClientId, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.PersistMicrosoftCreds);
                }
                return(true);
            }

            return(false);
        }
 public CommunicationsService(ICommunicationsRepository communicationsRepository,
                              IStudentRepository studentRepository,
                              IParentRepository parentRepository,
                              ITeacherRepository teacherRepository,
                              IImageProvider imageProvider,
                              IPushNotificationProvider pushNotificationProvider,
                              IMessagingProvider messagingProvider,
                              ISMSProvider smsProvider,
                              ITranslationProvider translationProvider,
                              ICustomParametersProvider customParametersProvider,
                              IDateProvider dateProvider,
                              ICollection <IMessageProvider> messageProviders,
                              IStaffRepository staffRepository)
 {
     _communicationsRepository = communicationsRepository;
     _studentRepository        = studentRepository;
     _parentRepository         = parentRepository;
     _teacherRepository        = teacherRepository;
     _imageProvider            = imageProvider;
     _pushNotificationProvider = pushNotificationProvider;
     _messagingProvider        = messagingProvider;
     _smsProvider              = smsProvider;
     _translationProvider      = translationProvider;
     _customParametersProvider = customParametersProvider;
     _dateProvider             = dateProvider;
     _messageProviders         = messageProviders;
     _staffRepository          = staffRepository;
 }
Esempio n. 8
0
        /// <summary>
        /// If the plug-in settings can be changed by the user, SDL Trados Studio will display a Settings button.
        /// By clicking this button, users raise the plug-in user interface, in which they can modify any applicable settings, in our implementation
        /// the delimiter character and the list file name.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProvider"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            LetsMTTranslationProvider editProvider = translationProvider as LetsMTTranslationProvider;

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

            editProvider.DownloadProfileList(true);

            SettingsForm settings = new SettingsForm(ref editProvider, languagePairs, credentialStore);

            if (!settings.TranslationProviderInitialized)
            {
                return(false);
            }

            DialogResult dResult = settings.ShowDialog(owner);

            if (dResult == DialogResult.OK)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 9
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            try
            {
                if (!(translationProvider is SdlMTCloudTranslationProvider provider))
                {
                    return(false);
                }

                provider.TranslationService.ConnectionService.Owner = owner;
                var connectionResult = provider.TranslationService.ConnectionService.EnsureSignedIn(provider.TranslationService.ConnectionService.Credential);

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

                provider.TranslationService.ConnectionService.SaveCredential(credentialStore);

                var optionsWindow = GetOptionsWindow(owner, languagePairs, provider);

                optionsWindow.ShowDialog();
                if (optionsWindow.DialogResult.HasValue && optionsWindow.DialogResult.Value)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                _logger.Error($"{Constants.EditWindow} {e.Message}\n {e.StackTrace}");
            }

            return(false);
        }
        public async Task ListenAudio(string providerName, string phrase)
        {
            ITranslationProvider provider = _translationProviders.Providers.SingleOrDefault(s => s.ProviderName == providerName);


            await provider.ListenAudio(phrase).ConfigureAwait(false);;
        }
Esempio n. 11
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);
        }
        /// <summary>
        /// If the plug-in settings can be changed by the user,
        /// SDL Trados Studio will display a Settings button.
        /// By clicking this button, users raise the plug-in user interface,
        /// in which they can modify any applicable settings, in our implementation
        /// the delimiter character and the list file name.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProvider"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>

        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var editProvider = translationProvider as MtTranslationProvider;

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

            // Implement error display
            if (languagePairs.Length > 1)
            {
                return(false);
            }

            //get credentials
            var getCred = GetMyCredentials(credentialStore, "argostranslateprovider:///");

            if (getCred != null)
            {
                editProvider.Options.ApiKey       = getCred.Credential;
                editProvider.Options.PersistCreds = getCred.Persist;
            }

            var dialog = new MtProviderConfDialog(editProvider.Options, credentialStore, languagePairs[0]);

            //we are letting user delete creds but after testing it seems that it's ok if the individual credentials are null, b/c our method will re-add them to the credstore based on the uri
            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                SetCredentials(credentialStore, dialog.Options.ApiKey, dialog.Options.PersistCreds);
                return(true);
            }

            return(false);
        }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var googleTranslationProvider = translationProvider as GoogleTranslationProviderPlugin;

            if (googleTranslationProvider != null)
            {
                var       oldSettings = googleTranslationProvider.Settings;
                DlgBrowse dlg         = new DlgBrowse(oldSettings, credentialStore, DlgBrowse.DialogMode.Edit);

                if (dlg.ShowDialog(owner) == DialogResult.OK)
                {
                    Settings googleSettings = dlg.GetSettings();
                    if (googleSettings == null)
                    {
                        return(false);
                    }

                    googleTranslationProvider.UpdateSettings(googleSettings);

                    // Store API Key in main credential store
                    if (!string.IsNullOrEmpty(googleSettings.ApiKey))
                    {
                        credentialStore.AddCredential(googleSettings.CredentialsUri, new TranslationProviderCredential(googleSettings.ApiKey, true));
                    }

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 14
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var editProvider = translationProvider as MyMtTranslationProvider;

            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;
            }

            MyMtDialog dialog = new MyMtDialog(editProvider.Options, credentialStore);

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                editProvider.Options = dialog.Options;
                var apiKey = editProvider.Options.ApiKey;
                SetDeeplCredentials(credentialStore, apiKey, true);
                return(true);
            }
            return(false);
        }
Esempio n. 15
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var controlledMTProvider = (ControlledMtProvidersProvider)translationProvider;

            List <ITranslationProvider> mtProviders = new List <ITranslationProvider>();

            //move this to mmtProvider

            using (MTProvidersDialog pd = new MTProvidersDialog(controlledMTProvider))
            {
                DialogResult result = pd.ShowDialog(owner);

                if (result != DialogResult.OK)
                {
                    return(false);
                }

                var mtProvidersUi = pd.SelectedTranslationProvidersWinformsUI;
                if (mtProvidersUi.Count == 0)
                {
                    return(false);
                }

                foreach (var mtProviderUi in mtProvidersUi)
                {
                    var innerProviders = mtProviderUi.Browse(owner, languagePairs, credentialStore);
                    if (innerProviders != null && innerProviders.All(x => x.TranslationMethod == TranslationMethod.MachineTranslation))
                    {
                        mtProviders.AddRange(innerProviders);
                    }
                }
            }
            controlledMTProvider.MtProviders = mtProviders;
            return(true);
        }
        public async Task <TranslationResult> TranslateProvider(string ProviderName, string phrase)
        {
            ITranslationProvider provider = _translationProviders.Providers.SingleOrDefault(s => s.ProviderName == ProviderName);


            return(await provider.Translate(phrase).ConfigureAwait(false));;
        }
Esempio n. 17
0
 public MainViewModel(ITranslationProvider mtProvider)
 {
     _mtProvider       = mtProvider;
     _translateCommand = new DelegateCommand(Translate);
     // we asume this ctor is called from the UI thread
     _syncContext = SynchronizationContext.Current;
 }
        public StrongMapleMessageSubscription(ITranslationProvider translationProvider, SubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter)
        {
            SubscriptionToken = subscriptionToken ?? throw new ArgumentNullException(nameof(subscriptionToken), $"{nameof(subscriptionToken)} {Resources.IsRequired}");
            DeliveryAction    = deliveryAction ?? throw new ArgumentNullException(nameof(deliveryAction), $"{nameof(deliveryAction)} {Resources.IsRequired}");
            MessageFilter     = messageFilter ?? throw new ArgumentNullException(nameof(messageFilter), $"{nameof(messageFilter)} {Resources.IsRequired}");

            _translationProvider = translationProvider ?? throw new ArgumentNullException(nameof(translationProvider), $"{nameof(translationProvider)} {Resources.IsRequired}");
        }
Esempio n. 19
0
        public static BaseResponse CreateNotFoundResponse(long id, ITranslationProvider translationProvider)
        {
            BaseResponse response = new BaseResponse();

            response.Success = false;
            response.Message = string.Format(translationProvider.GetTranslation(Translations.ItemWithIdXNotFound).Text, id);
            return(response);
        }
Esempio n. 20
0
 public static BaseResponse CreateOkResponse(ITranslationProvider translationProvider)
 {
     return(new BaseResponse
     {
         Message = translationProvider.GetTranslation(Translations.EverythingOk).Text,
         Success = true
     });
 }
 public TranslationActualizer(ITranslationProvider translationProvider,
                              ISysCultureInfoProvider sysCultureInfoProvider, ITranslationLogger translationLogger)
 {
     TranslationProvider     = translationProvider;
     SysCultureInfoProvider  = sysCultureInfoProvider;
     TranslationLogger       = translationLogger;
     TranslationErrorHandler = translationProvider as ITranslationErrorHandler;
 }
Esempio n. 22
0
 private ITranslationActualizer CreateTranslationActualizer <T>(ITranslationProvider translationProvider,
                                                                ISysCultureInfoProvider sysCultureInfoProvider) where T : class, ITranslationActualizer
 {
     return(ClassFactory.Get <T>(new ConstructorArgument("resourceProvider", null),
                                 new ConstructorArgument("translationProvider", translationProvider),
                                 new ConstructorArgument("sysCultureInfoProvider", sysCultureInfoProvider),
                                 new ConstructorArgument("translationLogger", TranslationLogger)));
 }
 public TranslationFilter(Stream output, ITranslationProvider translationProvider,
     string sourceLanguage, string targetLanguage)
 {
     _outputStream = output;
     _translationProvider = translationProvider;
     _sourceLanguage = sourceLanguage.ToLower();
     _targetLanguage = targetLanguage.ToLower();
     _responseHtml = new StringBuilder();
 }
Esempio n. 24
0
        private void SetupTranslation()
        {
            var factory = new TranslationProviderFactory();

            _provider = factory.CreateTranslationProvider(_uri, null, _store);
            var vm = new MainViewModel(_provider);

            DataContext = vm;
        }
Esempio n. 25
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var persistenceService = new PersistenceService();
            var settings           = persistenceService.GetProviderSettings();

            SetTranslationProvider((DtSearch4StudioProvider)translationProvider, settings);

            return(true);
        }
Esempio n. 26
0
        public static BaseResponseWithItem <T> CreateOkResponse(T item, ITranslationProvider translationProvider)
        {
            BaseResponseWithItem <T> response = new BaseResponseWithItem <T>();

            response.Success = true;
            response.Message = translationProvider.GetTranslation(Translations.EverythingOk).Text;
            response.Item    = item;
            return(response);
        }
Esempio n. 27
0
        public void SetService(ITranslationProvider service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service = service;
        }
Esempio n. 28
0
 public LocalizationManager(
     IEnumerable <IPluralRuleProvider> pluralRuleProviders,
     ITranslationProvider translationProvider,
     IMemoryCache cache)
 {
     _pluralRuleProviders = pluralRuleProviders.OrderBy(o => o.Order).ToArray();
     _translationProvider = translationProvider;
     _cache = cache;
 }
Esempio n. 29
0
 /// <summary>
 /// Notice factory constructor.
 /// </summary>
 /// <param name="notice">The notice</param>
 /// <param name="parent">The parent notice</param>
 /// <param name="tedSenderOrganisationName">Sender organisation name of TED eSender</param>
 /// <param name="tedContactEmail">The TED contact email</param>
 /// <param name="eSenderLogin">eSenderLogin</param>
 /// <param name="translationProvider">Remote translations (Loco)</param>
 public TedNoticeFactory(NoticeContract notice, NoticeContract parent, string tedSenderOrganisationName,
                         string tedContactEmail, string eSenderLogin, ITranslationProvider translationProvider = null)
 {
     _notice                = notice;
     _parent                = parent;
     _tedContactEmail       = tedContactEmail;
     _tedSenderOrganisation = tedSenderOrganisationName;
     _eSenderLogin          = eSenderLogin;
     _translationProvider   = translationProvider;
 }
 /// <summary>
 /// F06 Contract Award Utilities factory constructor.
 /// </summary>
 /// <param name="notice">The notice</param>
 /// <param name="eSenderLogin">The TED esender login</param>
 /// <param name="tedContactEmail"></param>
 /// <param name="translationProvider"></param>
 /// <param name="tedSenderOrganisation"></param>
 public F06Factory(NoticeContract notice, string eSenderLogin, string tedSenderOrganisation, string tedContactEmail, ITranslationProvider translationProvider)
 {
     _notice                = notice;
     _eSenderLogin          = eSenderLogin;
     _tedContactEmail       = tedContactEmail;
     _tedSenderOrganisation = tedSenderOrganisation;
     _configuration         = NoticeConfigurationFactory.CreateConfiguration(notice);
     _translationProvider   = translationProvider;
     _helper                = new SectionHelper(_notice, _configuration, eSenderLogin, _translationProvider);
 }
Esempio n. 31
0
        public static new BaseResponseWithItem <T> CreateNotFoundResponse(long id, ITranslationProvider translationProvider)
        {
            BaseResponse baseResponse = BaseResponse.CreateNotFoundResponse(id, translationProvider);

            return(new BaseResponseWithItem <T>
            {
                Message = baseResponse.Message,
                Success = baseResponse.Success
            });
        }
Esempio n. 32
0
 public TranslationService(
     IRepository genericRepo,
     DaoRepository daoRepo,
     AppConf appConf,
     ILanguageDetector languageDetector,
     ITranslationProvider translationProvider,
     IIsoLanguageTranslationProvider isoLanguageTranslationProvider) : base(genericRepo, daoRepo, appConf)
 {
     LanguageDetector               = languageDetector;
     TranslationProvider            = translationProvider;
     IsoLanguageTranslationProvider = isoLanguageTranslationProvider;
 }
Esempio n. 33
0
 public NotificationsService(INotificationsRepository notificationsRepository,
                             IPushNotificationProvider pushNotificationProvider,
                             IStaffRepository staffRepository,
                             IStudentRepository studentRepository,
                             ITranslationProvider translationProvider)
 {
     _notificationsRepository  = notificationsRepository;
     _pushNotificationProvider = pushNotificationProvider;
     _studentRepository        = studentRepository;
     _staffRepository          = staffRepository;
     _translationProvider      = translationProvider;
 }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var tProvider = translationProvider as AddSourceTmTranslationProvider;
            bool result = false;
            if (tProvider != null)
            {
                result = FileBasedTranslationProviderUi.Edit(owner, tProvider.FileBasedTranslationProvider, languagePairs, credentialStore);
            }

            using (var sourceConfigurationForm = new SourceTmConfiguration(translationProvider.Uri))
            {
                sourceConfigurationForm.ShowDialog();
            }

            return result;
        }
Esempio n. 35
0
 public IContextBundle Copy(IPermissionsProvider permissionsProvider = null,
                            IImmutableErrorContext errorContext = null,
                            ITypeAccessProvider accessProvider = null,
                            ITranslationProvider translationProvider = null,
                            IValidationProvider validationProvider = null,
                            ILogProvider logProvider = null,
                            Visibility? visibility  = null,
                            Visibility? timingVisibility = null)
 {
     return new ContextBundle(permissionsProvider ?? this.permissionsProvider,
                              errorContext ?? this.errorContext,
                              accessProvider ?? this.accessProvider,
                              translationProvider ?? this.translationProvider,
                              validationProvider ?? this.validationProvider,
                              logProvider ?? this.logProvider,
                              visibility ?? this.visibility,
                              timingVisibility ?? this.timingVisibility);
 }
Esempio n. 36
0
 public ContextBundle(IPermissionsProvider permissionsProvider = null, 
                      IImmutableErrorContext errorContext = null, 
                      ITypeAccessProvider accessProvider = null,
                      ITranslationProvider translationProvider = null, 
                      IValidationProvider validationProvider = null,
                      ILogProvider logProvider = null,
                      Visibility visibility = Visibility.None,
                      Visibility timingVisibility = Visibility.None)
 {
     this.permissionsProvider = permissionsProvider ?? PermissionsProvider.Default;
     this.errorContext = errorContext ?? ImmutableErrorContext.Empty;
     this.accessProvider = accessProvider ?? TypeAccessProvider.Empty;
     this.translationProvider = translationProvider ?? TranslationProvider.Empty;
     this.validationProvider = validationProvider ?? ValidationProvider.Empty;
     this.logProvider = logProvider ?? LogProvider.Default;
     this.visibility = visibility;
     this.timingVisibility = timingVisibility;
 }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            MtTranslationProvider editProvider = translationProvider as MtTranslationProvider;
            if (editProvider == null)
            {
                return false;
            }

            //get saved key if there is one and put it into options
            //get google credentials
            TranslationProviderCredential getCredGt = GetMyCredentials(credentialStore, "mtenhancedprovidergt:///");
            if (getCredGt != null)
            {
                editProvider.Options.apiKey = getCredGt.Credential;
                editProvider.Options.persistGoogleKey = getCredGt.Persist;
            }

            //get microsoft credentials
            TranslationProviderCredential getCredMt = GetMyCredentials(credentialStore, "mtenhancedprovidermst:///");
            if (getCredMt != null)
            {
                try
                {
                    GenericCredentials creds = new GenericCredentials(getCredMt.Credential); //parse credential into username and password
                    editProvider.Options.ClientID = creds.UserName;
                    editProvider.Options.ClientSecret = creds.Password;
                    editProvider.Options.persistMicrosoftCreds = getCredMt.Persist;
                }
                catch { }//swallow b/c it will just fail to fill in instead of crashing the whole program
            }

            MtProviderConfDialog dialog = new MtProviderConfDialog(editProvider.Options, credentialStore);
            //we are letting user delete creds but after testing it seems that it's ok if the individual credentials are null, b/c our method will re-add them to the credstore based on the uri
            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                editProvider.Options = dialog.Options;

                string apiKey = editProvider.Options.apiKey;

                //we are setting credentials selectively based on the chosen provider to avoid saving the other if it is blank
                if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.persistGoogleKey);
                }
                else if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    GenericCredentials creds2 = new GenericCredentials(dialog.Options.ClientID, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.persistMicrosoftCreds);
                }
                return true;
            }

            return false;
        }
        private bool SearchShouldExecute(ITranslationProvider translationProvider, SearchSettings searchSettings)
        {
            if (!searchSettings.IsConcordanceSearch && !translationProvider.SupportsTranslation)
            {
                return false;
            }
            if (searchSettings.IsConcordanceSearch && !translationProvider.SupportsConcordanceSearch)
            {
                return false;
            }
          
            if (searchSettings.Mode == SearchMode.ConcordanceSearch && !translationProvider.SupportsSourceConcordanceSearch)
            {
                return false;
            }
            if (searchSettings.Mode == SearchMode.TargetConcordanceSearch && !translationProvider.SupportsTargetConcordanceSearch)
            {
                return false;
            }

            return true;
        }
 public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
 {
     var tProvider = translationProvider as AddSourceTmTranslationProvider;
     return tProvider != null && FileBasedTranslationProviderUi.Edit(owner, tProvider.FileBasedTranslationProvider, languagePairs, credentialStore);
 }
 public RecordSourceTuTmTranslationProvider(ITranslationProvider provider)
 {
     _fileBasedTranslationProvider = provider;
 }
Esempio n. 41
0
 public void Initialize()
 {
     var functionGenerator = new FunctionGenerator();
     this.provider = new TranslationProvider(functionGenerator, shouldThrowExceptions: true);
 }
 public AddSourceTmTranslationProvider(ITranslationProvider provider)
 {
     _fileBasedTranslationProvider = provider;
 }