//function that will be called to attempt to determine the from languange if none is given. private void DetectLanguage(string input) { try { Regex reg = new Regex(@"language"".""(?<languageCode>[^""]+)"); string url = String.Format("http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q={0}", input); WebGrabber webGrabber = new WebGrabber(url); webGrabber.GetResponse(); string result = webGrabber.GetString(); Match match = reg.Match(result); string matched = match.Groups["languageCode"].Value; _fromLanguage = LanguageUtility.GetLanguage(matched); if (_debug) { logger.Debug("Translation tool: Detect Language: Source: {0} : Detected Language: {1}", result, LanguageUtility.ToString(_fromLanguage)); } } catch (Exception e) { if (e is ThreadAbortException) { throw e; } _fromLanguage = LanguageUtility.GetLanguage("en"); } }
public void Translate(TranslatorLanguage language) { Translator tr = new Translator(); tr.ToLanguage = language; bioSummary = tr.Translate(bioSummary); bioContent = tr.Translate(bioContent); }
/// <summary> /// Get the language code of a language. /// </summary> /// <param name="language">The language</param> /// <returns>The language code of this language or code for unknown language.</returns> public static string GetLanguageCode(TranslatorLanguage language) { string code; if (!LanguageCodeDict.TryGetValue(language, out code)) { code = LanguageCodeDict[TranslatorLanguage.Unknown]; } return(code); }
/// <summary> /// Returns the proper encoding type for language given. /// </summary> /// <param name="language"></param> /// <returns></returns> public static System.Text.Encoding GetEncoding(TranslatorLanguage language) { if (s_LanguangeEncoderList.ContainsKey(language)) { return(s_LanguangeEncoderList[language]); } else { return(System.Text.Encoding.Default); } }
public void Translate(TranslatorLanguage language) { Translator tr = new Translator(); tr.ToLanguage = language; Summary = tr.Translate(Summary); Tagline = tr.Translate(Tagline); string tmp = tr.Translate(Genres.ToString()); Genres.Clear(); foreach (string currGenre in tmp.Split('|')) { if (currGenre.Trim().Length > 0) { Genres.Add(currGenre.Trim()); } } }
public static string ToString(TranslatorLanguage language) { return(language.ToString()); }
/// <summary> /// Whether this language is translatable. /// </summary> /// <param name="language">The language.</param> /// <returns>Return true if the language is translatable.</returns> public static bool IsTranslatable(TranslatorLanguage language) { return(TranslatableCollection.Contains(language)); }
//function that will be called to attempt to determine the from languange if none is given. private void DetectLanguage(string input) { try { Regex reg = new Regex(@"language"".""(?<languageCode>[^""]+)"); string url = String.Format("http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q={0}", input); WebGrabber webGrabber = new WebGrabber(url); webGrabber.GetResponse(); string result = webGrabber.GetString(); Match match = reg.Match(result); string matched = match.Groups["languageCode"].Value; _fromLanguage = LanguageUtility.GetLanguage(matched); if (_debug) logger.Debug("Translation tool: Detect Language: Source: {0} : Detected Language: {1}", result, LanguageUtility.ToString(_fromLanguage)); } catch (Exception e) { if (e is ThreadAbortException) throw e; _fromLanguage = LanguageUtility.GetLanguage("en"); } }
/// <summary> /// Insert file to project /// </summary> /// <param name="projectId"></param> /// <param name="importPath"></param> /// <param name="lstFile"></param> /// <returns>true/false</returns> public virtual Boolean InsertProjectFile(int projectId, string importPath, List <HttpPostedFile> lstFile) { try { bool bSuccess = true; using (var dbContextTransaction = this.Database.BeginTransaction()) { try { string sTargetLang = "vi"; TranslatorLanguage oTranslatorLanguage = GetTranslateLanguage(projectId); if (oTranslatorLanguage != null && !String.IsNullOrEmpty(oTranslatorLanguage.LanguagePair)) { var arrLang = oTranslatorLanguage.LanguagePair.Split('|'); if (arrLang.Length == 2 && !String.IsNullOrEmpty(arrLang[1])) { sTargetLang = arrLang[1]; } } foreach (var file in lstFile) { int fileType = 1;//default excel var ext = Path.GetExtension(file.FileName); switch (ext) { case ".xls": case ".xlsx": fileType = (int)FileTypes.EXCEL; break; case ".doc": case ".docx": fileType = (int)FileTypes.WORD; break; case ".ppt": case ".pptx": fileType = (int)FileTypes.POWERPOINT; break; case ".pdf": fileType = (int)FileTypes.PDF; break; } this.Database.ExecuteSqlCommand("Proc_InsertFileToProject @projectId, @FileName, @FilePath, @FileType, @IsLoadText ,@LastUpdate,@TargetLang", new SqlParameter("@projectId", projectId), new SqlParameter("@FileName", file.FileName), new SqlParameter("@FilePath", importPath), new SqlParameter("@FileType", fileType), new SqlParameter("@IsLoadText", false), new SqlParameter("@LastUpdate", DateTime.Now), new SqlParameter("@TargetLang", sTargetLang)); } this.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { bSuccess = false; dbContextTransaction.Rollback(); } } return(bSuccess); } catch (Exception) { throw; } }
public void Translate(TranslatorLanguage language) { Translator tr = new Translator(); tr.ToLanguage = language; Summary = tr.Translate(Summary); Tagline = tr.Translate(Tagline); string tmp = tr.Translate(Genres.ToString()); Genres.Clear(); foreach (string currGenre in tmp.Split('|')) if (currGenre.Trim().Length > 0) Genres.Add(currGenre.Trim()); }
public void Translate(TranslatorLanguage language) { Translator tr = new Translator(); tr.ToLanguage = language; bioSummary = tr.Translate(bioSummary); bioContent = tr.Translate(bioContent); }
public static string ToString(TranslatorLanguage language) { return language.ToString(); }
/// <summary> /// Whether this language is translatable. /// </summary> /// <param name="language">The language.</param> /// <returns>Return true if the language is translatable.</returns> public static bool IsTranslatable(TranslatorLanguage language) { return TranslatableCollection.Contains(language); }
/// <summary> /// Get the language code of a language. /// </summary> /// <param name="language">The language</param> /// <returns>The language code of this language or code for unknown language.</returns> public static string GetLanguageCode(TranslatorLanguage language) { string code; if (!LanguageCodeDict.TryGetValue(language, out code)) { code = LanguageCodeDict[TranslatorLanguage.Unknown]; } return code; }
/// <summary> /// Returns the proper encoding type for language given. /// </summary> /// <param name="language"></param> /// <returns></returns> public static System.Text.Encoding GetEncoding(TranslatorLanguage language) { if (s_LanguangeEncoderList.ContainsKey(language)) { return s_LanguangeEncoderList[language]; } else { return System.Text.Encoding.Default; } }