public static MicrosoftTranslationService Init(bool showError = false) { if (string.IsNullOrEmpty(Configuration.Settings.Tools.MicrosoftTranslatorApiKey)) { if (showError) { MessageBox.Show(LanguageSettings.Current.GoogleTranslate.MsClientSecretNeeded, "MicrosoftTranslationService"); } return(null); } MicrosoftTranslationService microsoftTranslationService = null; try { microsoftTranslationService = new MicrosoftTranslationService(Configuration.Settings.Tools.MicrosoftTranslatorApiKey, Configuration.Settings.Tools.MicrosoftTranslatorTokenEndpoint, Configuration.Settings.Tools.MicrosoftTranslatorCategory); } catch (Exception e) { if (showError) { MessageBox.Show(e.Message + Environment.NewLine + e.InnerException?.Source + ": " + e.InnerException?.Message, "MicrosoftTranslationService"); } } return(microsoftTranslationService); }
private void GoogleOrMicrosoftTranslate_Shown(object sender, EventArgs e) { _googleTranslationService = GoogleTranslationInitializer.Init(); _microsoftTranslationService = MicrosoftTranslationInitializer.Init(true); InitLanguageComboboxes(); Refresh(); Translate(); }