/// <summary>
        /// Determines the language direction of the delimited list file by
        /// reading the first line. Based upon this information it is determined
        /// whether the plug-in supports the language pair that was selected by
        /// the user.
        /// </summary>
        #region "SupportsLanguageDirection"
        public bool SupportsLanguageDirection(LanguagePair languageDirection)
        {
            if (Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
            {
                if (mstConnect == null) //construct ApiConnecter if necessary
                {
                    mstConnect = new MstTranslateConnect.ApiConnecter(Options);
                }
                else
                {
                    mstConnect.resetCrd(Options.ClientID, Options.ClientSecret); //reset in case changed since last time the class was constructed
                }

                return(mstConnect.isSupportedLangPair(languageDirection.SourceCulture.Name, languageDirection.TargetCulture.Name));
            }
            else if (Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
            {
                if (gtConnect == null) //instantiate GtApiConnecter if necessary
                {
                    gtConnect = new MtTranslationProviderGTApiConnecter(Options.apiKey);
                }
                else
                {
                    gtConnect.ApiKey = Options.apiKey; //reset in case it has been changed since last time GtApiConnecter was instantiated
                }
                return(gtConnect.isSupportedLangPair(languageDirection.SourceCulture, languageDirection.TargetCulture));
            }

            //not likely to get here but...
            return(true);
        }
Exemplo n.º 2
0
        private string LookupMST(string sourcetext, MtTranslationOptions options, string format)
        {
            string catId = "";

            if (options.UseCatID)
            {
                catId = _options.CatID;//only use specific category ID if the option is selected
            }
            string sourcelang = _languageDirection.SourceCulture.ToString();
            string targetlang = _languageDirection.TargetCulture.ToString();

            //instantiate ApiConnecter if necessary
            if (mstConnect == null)
            {
                mstConnect = new MstTranslateConnect.ApiConnecter(_options);
            }
            else
            {
                mstConnect.resetCrd(options.ClientID, options.ClientSecret); //reset key in case it has been changed in dialog since GtApiConnecter was instantiated
            }

            string translatedText = mstConnect.Translate(sourcelang, targetlang, sourcetext, catId, format);

            return(translatedText);
        }
        private string LookupMST(string sourcetext, MtTranslationOptions options, string format)
        {
            string catId = "";
            if (options.UseCatID)
                catId = _options.CatID;//only use specific category ID if the option is selected
            string sourcelang = _languageDirection.SourceCulture.ToString();
            string targetlang = _languageDirection.TargetCulture.ToString();

            //instantiate ApiConnecter if necessary
            if (mstConnect == null)
            {
                mstConnect = new MstTranslateConnect.ApiConnecter(_options);
            }
            else
            {
                mstConnect.resetCrd(options.ClientID, options.ClientSecret); //reset key in case it has been changed in dialog since GtApiConnecter was instantiated
            }

            string translatedText = mstConnect.Translate(sourcelang, targetlang, sourcetext, catId, format);
            return translatedText;
        }
        public bool SupportsLanguageDirection(LanguagePair languageDirection)
        {
            if (Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
            {
                if (mstConnect == null) //construct ApiConnecter if necessary
                {
                    mstConnect = new MstTranslateConnect.ApiConnecter(Options);
                }
                else
                {
                    mstConnect.resetCrd(Options.ClientID, Options.ClientSecret); //reset in case changed since last time the class was constructed
                }

                return mstConnect.isSupportedLangPair(languageDirection.SourceCulture.Name, languageDirection.TargetCulture.Name);
            }
            else if (Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
            {
                if (gtConnect == null) //instantiate GtApiConnecter if necessary
                {
                    gtConnect = new MtTranslationProviderGTApiConnecter(Options.apiKey);
                }
                else
                {
                    gtConnect.ApiKey = Options.apiKey; //reset in case it has been changed since last time GtApiConnecter was instantiated
                }
                return gtConnect.isSupportedLangPair(languageDirection.SourceCulture, languageDirection.TargetCulture);
            }

            //not likely to get here but...
            return true;
        }