/// <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));
        }
Exemple #3
0
        private static Text CreateFromFilter(IQueryFilter filter, Database database = null)
        {
            Database db  = database ?? Db.For <Text>();
            var      dao = new Text();

            filter.Parameters.Each(p =>
            {
                dao.Property(p.ColumnName, p.Value);
            });
            dao.Save(db);
            return(dao);
        }
Exemple #4
0
 public ActionResult Update(Bam.Net.Translation.Text dao)
 {
     try
     {
         dao.Save();
         return(Json(new { Success = true, Message = "", Dao = dao.ToJsonSafe() }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }