private Dictionary <string, MtTag> GetSourceTagsDict() { dict = new Dictionary <string, MtTag>(); //try this //build dict for (int i = 0; i < sourceSegment.Elements.Count; i++) { System.Type elType = sourceSegment.Elements[i].GetType(); if (elType.ToString() == "Sdl.LanguagePlatform.Core.Tag") //if tag, add to dictionary { MtTag theTag = new MtTag((Tag)sourceSegment.Elements[i].Duplicate()); int tagNumber = sourceSegment.Elements.IndexOf(theTag.SdlTag); //this is a number we will assign the tag string tagText = "<tg" + tagNumber.ToString() + ">"; //create our abbreviated tag to send to google preparedSourceText += tagText; //now we have to figure out whether this tag is preceded and/or followed by whitespace if (i > 0 && !sourceSegment.Elements[i - 1].GetType().ToString().Equals("Sdl.LanguagePlatform.Core.Tag")) { string prevText = sourceSegment.Elements[i - 1].ToString(); if (!prevText.Trim().Equals(""))//and not just whitespace { //get number of trailing spaces for that segment int whitespace = prevText.Length - prevText.TrimEnd().Length; //add that trailing space to our tag as leading space theTag.padLeft = prevText.Substring(prevText.Length - whitespace); } } if (i < sourceSegment.Elements.Count - 1 && !sourceSegment.Elements[i + 1].GetType().ToString().Equals("Sdl.LanguagePlatform.Core.Tag")) { //here we don't care whether it is only whitespace //get number of leading spaces for that segment string nextText = sourceSegment.Elements[i + 1].ToString(); int whitespace = nextText.Length - nextText.TrimStart().Length; //add that trailing space to our tag as leading space theTag.padRight = nextText.Substring(0, whitespace); } dict.Add(tagText, theTag); //add our new tag code to the dict with the corresponding tag } else { //if not a tag string str = HttpUtility.HtmlEncode(sourceSegment.Elements[i].ToString()); //HtmlEncode our plain text to be better processed by google and add to string preparedSourceText += str; } } return(dict); }
private Dictionary<string, MtTag> GetSourceTagsDict() { dict = new Dictionary<string, MtTag>(); //try this //build dict for (int i = 0; i < sourceSegment.Elements.Count; i++) { System.Type elType = sourceSegment.Elements[i].GetType(); if (elType.ToString() == "Sdl.LanguagePlatform.Core.Tag") //if tag, add to dictionary { MtTag theTag = new MtTag((Tag)sourceSegment.Elements[i].Duplicate()); int tagNumber = sourceSegment.Elements.IndexOf(theTag.SdlTag);//this is a number we will assign the tag string tagText = "<tg" + tagNumber.ToString() + ">"; //create our abbreviated tag to send to google preparedSourceText += tagText; //now we have to figure out whether this tag is preceded and/or followed by whitespace if (i > 0 && !sourceSegment.Elements[i - 1].GetType().ToString().Equals("Sdl.LanguagePlatform.Core.Tag")) { string prevText = sourceSegment.Elements[i - 1].ToString(); if (!prevText.Trim().Equals(""))//and not just whitespace { //get number of trailing spaces for that segment int whitespace = prevText.Length - prevText.TrimEnd().Length; //add that trailing space to our tag as leading space theTag.padLeft = prevText.Substring(prevText.Length - whitespace); } } if (i < sourceSegment.Elements.Count - 1 && !sourceSegment.Elements[i + 1].GetType().ToString().Equals("Sdl.LanguagePlatform.Core.Tag")) { //here we don't care whether it is only whitespace //get number of leading spaces for that segment string nextText = sourceSegment.Elements[i + 1].ToString(); int whitespace = nextText.Length - nextText.TrimStart().Length; //add that trailing space to our tag as leading space theTag.padRight = nextText.Substring(0, whitespace); } dict.Add(tagText, theTag); //add our new tag code to the dict with the corresponding tag } else {//if not a tag string str = HttpUtility.HtmlEncode(sourceSegment.Elements[i].ToString()); //HtmlEncode our plain text to be better processed by google and add to string preparedSourceText += str; } } return dict; }