private string LookupMst(string sourcetext, MtTranslationOptions options, string format) { var catId = ""; if (options.UseCatID) { catId = _options.CatId; //only use specific category ID if the option is selected } var sourcelang = _languageDirection.SourceCulture.ToString(); var targetlang = _languageDirection.TargetCulture.ToString(); //instantiate ApiConnecter if necessary if (_mstConnect == null) { _mstConnect = new ApiConnecter(_options); } else { _mstConnect.resetCrd(options.ClientId, options.ClientSecret); //reset key in case it has been changed in dialog since GtApiConnecter was instantiated } var translatedText = _mstConnect.Translate(sourcelang, targetlang, sourcetext, catId, format); return(translatedText); }
/// <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> public bool SupportsLanguageDirection(LanguagePair languageDirection) { if (Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator) { if (mstConnect == null) //construct ApiConnecter if necessary { mstConnect = new 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)); } 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); }