Ejemplo n.º 1
0
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            //throw new NotImplementedException();
            if (!SupportsTranslationProviderUri(translationProviderUri))
            {
                throw new Exception("Cannot handle URI.");
            }

            DeepLSamplerTranslationProvider tp = new DeepLSamplerTranslationProvider(new DeepLSamplerTranslationOptions(translationProviderUri));

            return(tp);
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            //throw new NotImplementedException();
            DeepLSamplerProviderConfDialog dialog = new DeepLSamplerProviderConfDialog(new DeepLSamplerTranslationOptions());

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                DeepLSamplerTranslationProvider testProvider = new DeepLSamplerTranslationProvider(dialog.Options);
                return(new ITranslationProvider[] { testProvider });
            }
            return(null);
        }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            //throw new NotImplementedException();
            DeepLSamplerTranslationProvider editProvider = translationProvider as DeepLSamplerTranslationProvider;

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

            DeepLSamplerProviderConfDialog dialog = new DeepLSamplerProviderConfDialog(editProvider.Options);

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                editProvider.Options = dialog.Options;
                return(true);
            }

            return(false);
        }
        //public static DeepLSpider deepL = null;

        public DeepLSamplerProviderConfDialog(DeepLSamplerTranslationOptions options)
        {
            Options = options;
            InitializeComponent();
            UpdateDialog(); // initialize form here!

            // attempt to open connection to DeepL if not yet established --> connection should already be opened in DeepLSamplerTranslationProvider
            DeepLSamplerTranslationProvider.OpenConnection();

            if (DeepLSamplerTranslationProvider.log != null)
            {
                DeepLSamplerTranslationProvider.log.WriteLine("DeepLSamplerProviderConfDialog instantiated", true);
            }

            // this code could go into UpdateDialog() or be deleted?
            string source_lang = "EN";
            string target_lang = "IT";

            DeepLSamplerTranslationProvider.deepL.setLanguages(source_lang, target_lang);

            textBox1.Text = "i think i hit the jackpot today";
            textBox2.Text = DeepLSamplerTranslationProvider.deepL.translateText("i think i hit the jackpot today");
        }
Ejemplo n.º 5
0
        public DeepLSamplerTranslationProviderLanguageDirection(DeepLSamplerTranslationProvider provider, LanguagePair languages)
        {
            // this gets instantiated hundreds of times
            // DeepLSamplerTranslationProvider.log.WriteLine("DeepLSamplerTranslationProviderLanguageDirection instantiated", true);

            _provider          = provider;
            _languageDirection = languages;
            _options           = _provider.Options;
            _visitor           = new DeepLSamplerTranslationProviderElementVisitor(_options);
            //_listOfTranslations = new Dictionary<string, string>();

            // examples
            //_languageDirection.SourceCultureName = "en-US";
            //_languageDirection.TargetCultureName = "de-DE";
            string _source_lang = _languageDirection.SourceCultureName.Substring(0, 2).ToUpper();
            string _target_lang = _languageDirection.TargetCultureName.Substring(0, 2).ToUpper();

            // TRY / CATCH !!!!
            // without the if statement, this was repeated many times!
            if (DeepLSamplerTranslationProvider.deepL.SrcLang != _source_lang || DeepLSamplerTranslationProvider.deepL.TgtLang != _target_lang)
            {
                DeepLSamplerTranslationProvider.deepL.setLanguages(_source_lang, _target_lang);
            }
        }