/// <summary> /// Translate the specified input from the specified fromLanguage to the specified /// toLanguage /// </summary> /// <param name="fromLanguage"></param> /// <param name="toLanguage"></param> /// <param name="input"></param> /// <returns></returns> public virtual string Translate(Language fromLanguage, Language toLanguage, string input) { Text text = Text.OneWhere(c => c.Value == input, TranslationDatabase); if (text == null) { text = new Text(); text.Value = input; text.LanguageId = fromLanguage.Id; text.Save(TranslationDatabase); } Translation translation = text.TranslationsByTextId.FirstOrDefault(t => t.LanguageId == toLanguage.Id); if (translation == null) { string from = fromLanguage.ISO6391.Or(fromLanguage.ISO6392.First(2)); string to = toLanguage.ISO6391.Or(toLanguage.ISO6392.First(2)); translation = new Translation(); translation.Value = GetTranslationFromService(from, to, input); translation.LanguageId = toLanguage.Id; translation.TextId = text.Id; translation.Translator = this.GetType().Name; translation.Save(TranslationDatabase); } return(translation.Value); }
public string Translate(string input, Language toLanguage) { Text text = Text.OneWhere(t => t.Value == input, TranslationDatabase); Language fromLanguage = null; if (text != null && text.LanguageOfLanguageId != null) { fromLanguage = text.LanguageOfLanguageId; } else { fromLanguage = DetectLanguage(input); LanguageDetection detection = new LanguageDetection(); detection.LanguageId = fromLanguage.Id; text = new Text(); text.Value = input; text.LanguageId = fromLanguage.Id; text.Save(TranslationDatabase); detection.TextId = text.Id; detection.Detector = this.GetType().FullName; detection.Save(TranslationDatabase); } return(Translate(fromLanguage, toLanguage, input)); }