Ejemplo n.º 1
0
 public string GetTargetPath(LocFileType fileType)
 {
     if (fileType == LocFileType.Application)
     {
         return(Path.Combine(LddAssetsPath, Key, "localizedStrings.loc"));
     }
     return(Path.Combine(LddMaterialsPath, Key.ToUpper(), "localizedStrings.loc"));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// identifikace souvisleho fragmentu k prekladu v TRANS elementu
 /// </summary>
 static string getResxId(XElement fragmentParent, LocFileType fileType) {
   //string nm = Anot.GetAnotName(fragmentParent);
   //if (nm != null) return nm;
   int id; int count; Anot.GetAnotId(fragmentParent, out id, out count);
   return "T" + fragmentParent.Name.LocalName + (id == 0 ? null : id.ToString()) + (count == 0 ? null : "_" + count.ToString()) + (fileType == LocFileType.aspx ? ".Text" : null);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Vrat prvky RESX souboru k prekladu
 /// </summary>
 public static IEnumerable<resxNameValue> resxItems(XElement root, LocFileType fileType) {
   StringBuilder sb = new StringBuilder();
   //LMAP:
   if (fileType == LocFileType.lmap) {
     int cnt = 0;
     //Preklad LMAP souboru (<Script Type="LMCAPTION" Command=" (я) дýмаю{t=myslím si}" />)
     foreach (string txt in transLMAP(root))
       yield return new resxNameValue(getResxId(ref cnt), normalizeXmlText(txt, sb), (XAttribute)null);
     yield break;
   }
   //Else: Atributy k prekladu
   if (fileType == LocFileType.lmdata)
     foreach (XAttribute attr in transAttributes(root))
       yield return new resxNameValue(getResxId(attr), normalizeXmlText(((string)attr).Substring(attrStart.Length), sb), attr);
   else if (fileType == LocFileType.aspx)
     foreach (XAttribute attr in transAspxAttributes(root))
       yield return new resxNameValue(getAspxResxId(attr), normalizeXmlText((string)attr, sb), attr);
   //Preklad prosteho HTML textu
   if (fileType == LocFileType.lmdata || fileType == LocFileType.aspx) {
     //souvisle useky k prekladu
     foreach (List<XNode> fragment in transFragments(root))
       yield return new resxNameValue(getResxId(fragment[0].Parent, fileType),
         normalizeXmlText(fragment.InnerXml(html), sb), fragment);
   }
   if (fileType == LocFileType.sitemap) {
     foreach (var el in root.Descendants().Select(e => new {
       key = e.Attribute("resourceKey"),
       title = e.Attribute("title"),
       descr = e.Attribute("description")
     }).Where(kv => kv.key != null && (kv.title != null || kv.descr != null))) {
       if (el.key.Value.IndexOf('.') >= 0) throw new Exception("Wrong resourceKey " + el.key.Value);
       if (el.title != null)
         yield return new resxNameValue(el.key.Value + ".title", normalizeXmlText(el.title.Value, sb), el.key);
       if (el.descr != null)
         yield return new resxNameValue(el.key.Value + ".description", el.descr.Value, el.key);
     }
   }
   if (fileType == LocFileType.downloadXml) {
     foreach (XElement el in root.Element("Sites").Elements("SiteInfo").Where(el => el.Element("Site").Value == "com").Elements("Downloads").Elements("DownloadInfo")) {
       string id = "com." + el.Element("CourseId").Value;
       foreach (resxNameValue resx in extractDownloads(el, id)) yield return resx;
       foreach (XElement subEl in el.Element("Items").Elements("DownloadInfo")) {
         string subId = id + "." + subEl.Element("Id").Value;
         foreach (resxNameValue resx in extractDownloads(subEl, subId)) yield return resx;
       }
     }
   }
 }
Ejemplo n.º 4
0
 public bool CheckFileExist(LocFileType fileType)
 {
     return(File.Exists(GetTargetPath(fileType)));
 }
Ejemplo n.º 5
0
 public static string Parse(string content, GenResxContext ctx, LocFileType fileType, out bool modified) {
   modified = false;
   StringBuilder sb = new StringBuilder();
   foreach (regExItem item in regExItem.Parse(content, rxCSLocalize)) {
     if (item.IsMatch) {
       string val = item.Value.Substring(20, item.Value.Length - 21);
       string[] parts = val.Split(new char[] { ',' }, 3);
       for (int i = 0; i < parts.Length; i++) parts[i] = parts[i].Trim();
       //prvni parametr: GUID nebo null
       string id;
       if (parts[0] == "null") {
         id = Guid.NewGuid().ToString().Replace("-", null); parts[0] = id;
         ctx.ids.Add(id, true);
         modified = true;
       } else {
         id = parts[0].Substring(1, 32);
         if (ctx.ids.ContainsKey(id)) {
           id = Guid.NewGuid().ToString().Replace("-", null);
           modified = true;
         }
         ctx.ids.Add(id, true);
       }
       //Druhy parametr: grupa
       if (parts[1] != "LocPageGroup." + ctx.grp.ToString()) {
         parts[1] = "LocPageGroup." + ctx.grp.ToString();
         modified = true;
       }
       //Modifikovane volani procedury
       sb.Append(@"CSLocalize."); //rozdeleno aby se nestalo predmetem lokalizace
       sb.Append(@"localize(""");
       sb.Append(id);
       sb.Append("\", ");
       sb.Append(parts[1]);
       sb.Append(", ");
       sb.Append(parts[2]);
       sb.Append(")");
       //Vystup hodnoty do resource:
       val = parts[2];
       if (val[0] == '@') {
         val = val.Substring(2, val.Length - 3);
         val = val.Replace("\"\"", "\"");
       } else {
         val = val.Substring(1, val.Length - 2);
         val = Regex.Unescape(val);
       }
       ctx.toTrans.Add(new TradosLib.resxNameValue(id, val, (XAttribute)null));
     } else
       sb.Append(item.Value);
   }
   content = sb.ToString();
   return content;
 }