public TemplateLoader() { var studio = new Toolkit.Core.Studio().GetStudioVersion().ExecutableVersion; _path = studio.Major == 15 ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SDL\SDL Trados Studio\15.0.0.0\UserSettings.xml") : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SDL\SDL Trados Studio\14.0.0.0\UserSettings.xml"); }
/// <summary> /// Get installed version for Studio 2019 /// </summary> /// <returns>studio version</returns> public static string GetStudioVersion() { var studioVersion = new Toolkit.Core.Studio().GetInstalledStudioVersion()?.FirstOrDefault(v => v.Version.Equals("Studio15")); if (studioVersion != null) { return($"{studioVersion?.PublicVersion}-{studioVersion?.ExecutableVersion.ToString()}"); } return(string.Empty); }
/// <summary> /// Get installed version for Studio 2019 /// </summary> /// <returns></returns> public static string GetInstalledStudioPath() { var studio = new Toolkit.Core.Studio().GetInstalledStudioVersion().Where(v => v.Version.Equals("Studio15")).FirstOrDefault(); if (studio != null) { return(studio.InstallPath); } else { MessageBox.Show(Constants.Studio2019ErrorMessage, Constants.InformativeMessage, MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }
public string Translate(LanguagePair languageDirection, string sourceText) { var targetLanguage = languageDirection.TargetCulture.TwoLetterISOLanguageName; var sourceLanguage = languageDirection.SourceCulture.TwoLetterISOLanguageName; var translatedText = string.Empty; var normalizeHelper = new NormalizeSourceTextHelper(); try { sourceText = normalizeHelper.NormalizeText(sourceText); using (var httpClient = new HttpClient()) { var content = new StringContent($"text={sourceText}" + $"&source_lang={sourceLanguage}" + $"&target_lang={targetLanguage}" + "&preserve_formatting=1" + $"&tag_handling=xml&auth_key={ApiKey}", Encoding.UTF8, "application/x-www-form-urlencoded"); var studioVersion = new Toolkit.Core.Studio().GetStudioVersion().ExecutableVersion; httpClient.DefaultRequestHeaders.Add("Trace-ID", $"SDL Trados Studio 2019 {studioVersion}/plugin {_pluginVersion}"); var response = httpClient.PostAsync("https://api.deepl.com/v1/translate", content).Result; if (response.IsSuccessStatusCode) { var translationResponse = response.Content?.ReadAsStringAsync().Result; var translatedObject = JsonConvert.DeserializeObject <TranslationResponse>(translationResponse); if (translatedObject != null && translatedObject.Translations.Any()) { translatedText = translatedObject.Translations[0].Text; translatedText = DecodeWhenNeeded(translatedText); } } else { MessageBox.Show(response.ReasonPhrase, string.Empty, MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } catch (Exception e) { Log.Logger.Error($"{e.Message}\n {e.StackTrace}"); } return(translatedText); }
/// <summary> /// Get installed version for Studio 2019 /// </summary> /// <returns>studio version</returns> public string GetStudioVersion() { try { var studioVersion = new Toolkit.Core.Studio().GetInstalledStudioVersion()?.FirstOrDefault(v => v.Version.Equals("Studio15")); if (studioVersion != null) { return($"{studioVersion.PublicVersion}-{studioVersion.ExecutableVersion}"); } } catch { // catch all; ignore } return(string.Empty); }
/// <summary> /// Get installed version for Studio 2019 /// </summary> /// <returns></returns> public static string GetInstalledStudioPath() { try { var studio = new Toolkit.Core.Studio().GetInstalledStudioVersion()?.Where(v => v.Version.Equals("Studio15")).FirstOrDefault(); if (studio != null) { return(studio.InstallPath); } else { MessageBox.Show(Constants.Studio2019ErrorMessage, Constants.InformativeMessage, MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { Log.Logger.Error($"{Constants.GetInstalledStudioPath}: {ex.Message}\n {ex.StackTrace}"); } return(string.Empty); }
public string Translate(LanguagePair languageDirection, string sourceText) { var targetLanguage = languageDirection.TargetCulture.TwoLetterISOLanguageName; var sourceLanguage = languageDirection.SourceCulture.TwoLetterISOLanguageName; var translatedText = string.Empty; var normalizeHelper = new NormalizeSourceTextHelper(); try { sourceText = normalizeHelper.NormalizeText(sourceText); using (var httpClient = new HttpClient()) { var content = new StringContent($"text={sourceText}" + $"&source_lang={sourceLanguage}" + $"&target_lang={targetLanguage}" + "&preserve_formatting=1" + $"&tag_handling=xml&auth_key={ApiKey}", Encoding.UTF8, "application/x-www-form-urlencoded"); var studioVersion = new Toolkit.Core.Studio().GetStudioVersion().ExecutableVersion; httpClient.DefaultRequestHeaders.Add("Trace-ID", $"SDL Trados Studio 2019 {studioVersion}/plugin 4.8.7"); var response = httpClient.PostAsync("https://api.deepl.com/v1/translate", content).Result.Content.ReadAsStringAsync().Result; var translatedObject = JsonConvert.DeserializeObject <TranslationResponse>(response); if (translatedObject != null) { translatedText = translatedObject.Translations[0].Text; translatedText = DecodeWhenNeeded(translatedText); } } } catch (WebException e) { var eReason = Helpers.ProcessWebException(e); throw new Exception(eReason); } return(translatedText); }