示例#1
0
 /// <summary>
 /// Aktualizuje lookup pro sentenci
 /// </summary>
 public void finish(TradosDT.Sentence srcSent) {
   finish(srcSent.SrcText, (Langs)srcSent.SrcLang, srcSent.TransText, (Langs)srcSent.TransLang);
 }
示例#2
0
    public static TradosDT.Sentence insertTrans(int id, TradosDT.Sentence dummySent, string oldSrcText, string newSrcText, string transText, StringBuilder log, StringBuilder sb) {
      if (!checkTrans(id, ref newSrcText, ref transText, sb, log)) return null; //kontrola stejnych NOTRANS 
      TradosDT.TradosDB db = TradosDT.TradosDB.getTradosContext();
      TradosDT.Sentence sent = null;
      try {
        sent = db.Sentences.Where(s => s.Id == id).Single();
      } catch (Exception exp) {
        if (dummySent != null) {
          sent = dummySent;
          oldSrcText = null;
        } else
          throw new Exception(string.Format("Sentence {0}", id), exp);
      }
      string oldTransText = sent.TransText;

      sent.SrcText = newSrcText;
      sent.TransText = normalizeXmlText(transText, sb);
      sent.finish();

      RefreshLookup(db, sent, excelTextToXmlText(oldSrcText, log), oldTransText, sb, log);
      db.SaveChanges();
      return sent;
    }
示例#3
0
    /// <summary>
    /// vrati vety k prekladu, v excel kodovani
    /// </summary>
    public static IEnumerable<exportCmlItem> ExportXmlItems(TradosDT.TradosDB db, TradosDT.Page pg, Langs srcLang, Langs transLang, List<LocCommand> filter) {
      StringBuilder sb = new StringBuilder();

      /*var s1 =
        (from Trados.Sentence s in db.Sentences.Where(s => s.PageId == pg.Id && s.TransLang == (short)transLang)
         let newSrc = db.Sentences.Where(s2 => s2.PageId == s.PageId && s2.TransLang == s.SrcLang && s2.Name == s.Name).Select(s2 => new { s2.TransText, s2.TransHash, s2.Id }).Single()
         select new {
           sent = s,
           newSrcText = newSrc.TransText,
           newSrcId = newSrc==null ? -1 : newSrc.Id,
           lookups = db.Lookups.Where(l => l.SrcLang == (short)srcLang && l.TransLang == (short)transLang && l.SrcHash == newSrc.TransHash).
             Select(l => new { l.SrcText, l.TransText })
         }).ToArray();
      if (s1 == null) yield break;*/

      var sentSrcTexts =
        (from TradosDT.Sentence s in db.Sentences.Where(s => s.PageId == pg.Id && s.TransLang == (short)transLang)
         //let newSrc = db.Sentences.Where(s2 => s2.PageId == s.PageId && s2.TransLang == s.SrcLang && s2.Name == s.Name).Select(s2 => new { s2.TransText, s2.TransHash, s2.Id }).Single()
         let newSrc = db.Sentences.Where(s2 => s2.PageId == s.PageId && s2.TransLang == s.SrcLang && s2.Name == s.Name).Select(s2 => new { s2.TransText, s2.TransHash, s2.Id }).First()
         select new {
           sent = s,
           newSrcText = newSrc.TransText,
           newSrcId = newSrc == null ? -1 : newSrc.Id,
           lookups = db.Lookups.Where(l => l.SrcLang == (short)srcLang && l.TransLang == (short)transLang && l.SrcHash == newSrc.TransHash).
             Select(l => new { l.SrcText, l.TransText })
         }).ToArray();
      //Cyklus pres sentence k prekladu (obohacene o text zdrojove sentence)
      foreach (var sentSrcText in sentSrcTexts) {
        string oldSrcText = xmlToExcel(sentSrcText.sent.SrcText, sb);
        string newSrcText = xmlToExcel(sentSrcText.newSrcText, sb);
        LocCommand actCmd = excelFlag(oldSrcText, newSrcText);
        if (actCmd == LocCommand.NONE) continue; //Zdroj je prazdny, neni co prekladat
        //Lookup zaznam: exact match na SrcText
        string[] lkp = sentSrcText.lookups.Where(l => l.SrcText == sentSrcText.newSrcText).Select(l => l.TransText).Distinct().ToArray();
        //lookup zaznam existuje: zmena TRANS nebo CHANGE na OK commandu pro pripad unique exact match v lookup
        if ((actCmd == LocCommand.TRANS || actCmd == LocCommand.CHANGE) && lkp != null && lkp.Length > 0)
          actCmd = lkp.Length == 1 ? LocCommand.OK : LocCommand.CHOICE;
        if (filter != null && filter.IndexOf(actCmd) < 0) continue;
        //Spocitej TransText:
        string transTxt;
        if (actCmd == LocCommand.TRANS)  //predpripravi text s NOTRANS prvky
          transTxt = transXmlToExcel(sentSrcText.sent.TransText, sentSrcText.newSrcText, sb);
        else if (actCmd == LocCommand.OK)  //predpripravi text s NOTRANS prvky
          transTxt = xmlToExcel(lkp[0], sb);
        else if (actCmd == LocCommand.CHOICE) { //nabidne volbu z puvodniho prekladu a vsech lookups
          sb.Length = 0;
          if (!string.IsNullOrEmpty(sentSrcText.sent.TransText)) sb.Append(sentSrcText.sent.TransText + crlfCode + "=============" + crlfCode);
          foreach (string ls in lkp.Where(s => s != sentSrcText.sent.TransText))
            sb.Append(ls + crlfCode + "=============" + crlfCode);
          transTxt = xmlToExcel(sb.ToString(), sb);
        } else //puvodni TRANS text (pro done nebo change)
          transTxt = xmlToExcel(sentSrcText.sent.TransText, sb);
        //return
        yield return new exportCmlItem(
          pg.SeeUrl,
          sentSrcText.sent.Id,
          sentSrcText.sent.Name,
          actCmd,
          transTxt,
          oldSrcText,
          newSrcText,
          sentSrcText.newSrcId);
      }
    }
示例#4
0
 public static void ImportXml(string xml, TradosDT.Sentence dummySent, StringBuilder log) {
   if (xml[0] != '<') xml = xml.Remove(0, 1);
   //xml = xml.Replace("&#10;", crlfCode);
   xml = xml.Replace("&#10;", " ");
   XElement xmlData = XElement.Parse(xml, LoadOptions.PreserveWhitespace);
   XNamespace ad = "urn:schemas-microsoft-com:office:spreadsheet";
   XNamespace ss = "urn:schemas-microsoft-com:office:spreadsheet";
   //ID vet s priznakem OK z Excel XML
   var okNodeIds =
     from el in xmlData.Descendants(ad + "Data")
     where
       (string)el.Attribute(ss + "Type") == "Number" && //ciselny node, obsahujici sentence ID
       el.Parent.Parent.Elements().ElementAt(0).Elements().ElementAt(0).Value.ToLower() == "ok" //veta oznacena jako OK
     select int.Parse(el.Value);
   StringBuilder sb = new StringBuilder();
   //Vety k prekladu z
   foreach (int okId in okNodeIds) {
     try {
       XElement row = xmlData.Descendants(ad + "Data").Where(el => (string)el.Attribute(ss + "Type") == "Number" && el.Value == okId.ToString()).Single().Parent.Parent;
       insertTrans(okId, dummySent,
         row.Elements().ElementAt(3).Value, //stary vzor je v Cell s indexem 3
         row.Elements().ElementAt(2).Value, //novy vzor je v Cell s indexem 2
         row.Elements().ElementAt(1).Value, //preklad je v Cell s indexem 1
         log, sb);
     } catch {/*loguje se*/}
   }
 }
示例#5
0
 /// <summary>
 /// Pred save vety: ev. pridani do lookup tabulky
 /// </summary>
 public static void RefreshLookup(TradosDT.TradosDB db, TradosDT.Sentence srcSent, string oldSrcText, string oldTransText, StringBuilder sb, StringBuilder log) {
   if (string.IsNullOrEmpty(srcSent.SrcText) || string.IsNullOrEmpty(srcSent.TransText)) return;
   TradosDT.Lookup[] lkps;
   if (!string.IsNullOrEmpty(oldSrcText))
     lkps = db.Lookups.Where(l => l.SrcLang == srcSent.SrcLang && l.TransLang == srcSent.TransLang &&
     ((l.SrcHash == srcSent.SrcHash && l.SrcText == srcSent.SrcText) ||
     (l.SrcHash == LowUtils.crc(oldSrcText) && l.SrcText == oldSrcText))).ToArray();
   else
     lkps = db.Lookups.
       Where(l => l.SrcLang == srcSent.SrcLang && l.TransLang == srcSent.TransLang && l.SrcHash == srcSent.SrcHash && l.SrcText == srcSent.SrcText).
       ToArray();
   //Lookup zaznam nove verze sentence
   TradosDT.Lookup newLkp;
   try {
     newLkp = lkps.Where(l => l.SrcText == srcSent.SrcText && l.TransText == srcSent.TransText).SingleOrDefault();
   } catch (Exception exp) {
     throw new Exception(string.Format("Lookup duplicites error: src={0}, trans={1}", srcSent.SrcText, srcSent.TransText), exp);
   }
   //Lookup zaznam stare verze sentence
   //Jedna se o opravu? Kdyz ano, budto puvodni polozku smaz (existuje-li j*z nova) nebo uprav (neexistuje-li)
   TradosDT.Lookup oldLkp;
   try {
     oldLkp = lkps.Where(l => !string.IsNullOrEmpty(oldSrcText) && !string.IsNullOrEmpty(oldTransText) && l.SrcText == oldSrcText && l.TransText == oldTransText).SingleOrDefault();
   } catch (Exception exp) {
     throw new Exception(string.Format("Lookup duplicites error: src={0}, trans={1}", oldSrcText, oldTransText), exp);
   }
   if (oldLkp != null) {
     if (newLkp == null) oldLkp.finish(srcSent); //else db.Lookups.Remove(oldLkp);
     return;
   }
   //nejedna se o opravu, novy zaznam v lookup j*z existuje: neni co delat
   if (newLkp != null) return;
   //Kontrola duplicit
   if (lkps.Where(l => l.SrcText == srcSent.SrcText).Any())
     if (log != null)
       log.AppendFormat("Vznikla duplicita v Lookup tabulce, doporučujeme zkontrolovat (src={0}, trans={1})<br/>", srcSent.SrcText, srcSent.TransText);
   //Lookup polozka neexistuje, zaloz:
   TradosDT.Lookup lkp = new TradosDT.Lookup();
   db.Lookups.Add(lkp);
   lkp.finish(srcSent);
 }