示例#1
0
        // Copied from bin/src/LocaleStrings/Program.cs. Should remove this functionality there eventually.
        private static void StoreTranslatedContextHelp(XmlElement xelRoot,
                                                       Dictionary <string, POString> dictTrans)
        {
            XmlElement xelGroup = xelRoot.OwnerDocument.CreateElement("group");

            xelGroup.SetAttribute("id", "LocalizedContextHelp");
            Dictionary <string, POString> .Enumerator en = dictTrans.GetEnumerator();
            while (en.MoveNext())
            {
                POString pos    = en.Current.Value;
                string   sValue = pos.MsgStrAsString();
                if (String.IsNullOrEmpty(sValue))
                {
                    continue;
                }
                List <string> rgs = pos.AutoComments;
                if (rgs == null)
                {
                    continue;
                }
                for (int i = 0; i < rgs.Count; ++i)
                {
                    string sId = FindContextHelpId(rgs[i]);
                    if (!String.IsNullOrEmpty(sId))
                    {
                        XmlElement xelString = xelRoot.OwnerDocument.CreateElement("string");
                        xelString.SetAttribute("id", sId);
                        xelString.SetAttribute("txt", sValue);
                        xelGroup.AppendChild(xelString);
                        break;
                    }
                }
            }
            xelRoot.AppendChild(xelGroup);
        }
示例#2
0
 private static Dictionary <string, POString> LoadPOFile(string sMsgFile, out POString posHeader)
 {
     using (StreamReader srIn = new StreamReader(sMsgFile, Encoding.UTF8))
     {
         Dictionary <string, POString> dictTrans = new Dictionary <string, POString>();
         posHeader = POString.ReadFromFile(srIn);
         POString pos = POString.ReadFromFile(srIn);
         while (pos != null)
         {
             if (!pos.HasEmptyMsgStr && (pos.Flags == null || !pos.Flags.Contains("fuzzy")))
             {
                 dictTrans.Add(pos.MsgIdAsString(), pos);
             }
             pos = POString.ReadFromFile(srIn);
         }
         srIn.Close();
         return(dictTrans);
     }
 }
示例#3
0
 public bool HasSameMsgId(POString that)
 {
     if (this.m_rgsMsgId == null && that.m_rgsMsgId == null)
     {
         return(true);
     }
     else if (this.m_rgsMsgId == null || that.m_rgsMsgId == null)
     {
         return(false);
     }
     for (int i = 0; i < this.m_rgsMsgId.Count && i < that.m_rgsMsgId.Count; ++i)
     {
         string s1 = this.m_rgsMsgId[i];
         string s2 = that.m_rgsMsgId[i];
         if (s1 != s2)
         {
             return(false);
         }
     }
     return(this.m_rgsMsgId.Count == that.m_rgsMsgId.Count);
 }
 /// <summary>
 /// This nicely recursive method replaces the English txt attribute values with the
 /// corresponding translated values if they exist.
 /// </summary>
 /// <param name="xel"></param>
 /// <param name="dictTrans"></param>
 // Copied from bin/src/LocaleStrings/Program.cs. Should remove this functionality there eventually.
 private static void TranslateStringsElements(XmlElement xel,
                                              Dictionary <string, POString> dictTrans)
 {
     if (xel.Name == "string")
     {
         POString pos      = null;
         string   sEnglish = xel.GetAttribute("txt");
         if (dictTrans.TryGetValue(sEnglish, out pos))
         {
             string sTranslation = pos.MsgStrAsString();
             xel.SetAttribute("txt", sTranslation);
             xel.SetAttribute("English", sEnglish);
         }
     }
     foreach (XmlNode xn in xel.ChildNodes)
     {
         if (xn is XmlElement)
         {
             TranslateStringsElements(xn as XmlElement, dictTrans);
         }
     }
 }
示例#5
0
        // Copied from bin/src/LocaleStrings/Program.cs. Should remove this functionality there eventually.
        private static void StoreTranslatedAttributes(XmlElement xelRoot,
                                                      Dictionary <string, POString> dictTrans)
        {
            XmlElement xelGroup = xelRoot.OwnerDocument.CreateElement("group");

            xelGroup.SetAttribute("id", "LocalizedAttributes");
            Dictionary <string, POString> .Enumerator en = dictTrans.GetEnumerator();
            while (en.MoveNext())
            {
                POString pos    = en.Current.Value;
                string   sValue = pos.MsgStrAsString();
                if (String.IsNullOrEmpty(sValue))
                {
                    continue;
                }
                List <string> rgs = pos.AutoComments;
                if (rgs == null)
                {
                    continue;
                }
                for (int i = 0; i < rgs.Count; ++i)
                {
                    if (rgs[i] != null &&
                        // handle bug in creating original POT file due to case sensitive search.
                        (rgs[i].StartsWith("/") || rgs[i].StartsWith("file:///")) &&
                        IsFromXmlAttribute(rgs[i]))
                    {
                        XmlElement xelString = xelRoot.OwnerDocument.CreateElement("string");
                        xelString.SetAttribute("id", pos.MsgIdAsString());
                        xelString.SetAttribute("txt", sValue);
                        xelGroup.AppendChild(xelString);
                        break;
                    }
                }
            }
            xelRoot.AppendChild(xelGroup);
        }
示例#6
0
 /// <summary>
 /// CompareMsgIds two POString objects with the purpose of sorting the PO file by msgid.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static int CompareMsgIds(POString x, POString y)
 {
     if (x.m_rgsMsgId == null && y.m_rgsMsgId == null)
     {
         return(0);
     }
     else if (x.m_rgsMsgId == null)
     {
         return(-1);
     }
     else if (y.m_rgsMsgId == null)
     {
         return(1);
     }
     for (int i = 0; i < x.m_rgsMsgId.Count && i < y.m_rgsMsgId.Count; ++i)
     {
         string s1 = RemoveLeadingCruft(x.m_rgsMsgId[i].Replace("&", "").Trim());
         string s2 = RemoveLeadingCruft(y.m_rgsMsgId[i].Replace("&", "").Trim());
         int    n  = s1.CompareTo(s2);
         if (n != 0)
         {
             return(n);
         }
     }
     if (x.m_rgsMsgId.Count < y.m_rgsMsgId.Count)
     {
         return(-1);
     }
     else if (x.m_rgsMsgId.Count > y.m_rgsMsgId.Count)
     {
         return(1);
     }
     else
     {
         return(x.m_rgsMsgId[0].CompareTo(y.m_rgsMsgId[0]));
     }
 }
示例#7
0
        static public POString ReadFromFile(StreamReader srIn)
        {
            // Move past any blank lines, checking for the end of file.
            if (srIn.EndOfStream)
            {
                return(null);
            }
            string s = srIn.ReadLine();

            ++s_cLines;
            if (s != null)
            {
                s = s.Trim();
            }
            while (String.IsNullOrEmpty(s))
            {
                if (srIn.EndOfStream)
                {
                    return(null);
                }
                s = srIn.ReadLine();
                ++s_cLines;
                if (s != null)
                {
                    s = s.Trim();
                }
            }
            POString pos     = new POString();
            bool     fMsgId  = false;
            bool     fMsgStr = false;
            bool     fError  = false;

            do
            {
                if (s == "#")
                {
                    pos.AddUserComment("");
                }
                else if (s.StartsWith("# "))
                {
                    pos.AddUserComment(s.Substring(2).TrimStart());
                }
                else if (s.StartsWith("#."))
                {
                    pos.AddAutoComment(s.Substring(2).TrimStart());
                }
                else if (s.StartsWith("#:"))
                {
                    pos.AddReference(s.Substring(2).TrimStart());
                }
                else if (s.StartsWith("#,"))
                {
                    pos.AddFlags(s.Substring(2).TrimStart());
                }
                else if (s.ToLower().StartsWith("msgid"))
                {
                    fMsgId = true;
                    if (fMsgStr)
                    {
                        fError = true;
                    }
                    pos.AddMsgIdLine(s);
                }
                else if (s.ToLower().StartsWith("msgstr"))
                {
                    if (!fMsgId)
                    {
                        fError = true;
                    }
                    fMsgId  = false;
                    fMsgStr = true;
                    pos.AddMsgStrLine(s);
                }
                else if (s.StartsWith("\""))
                {
                    if (fMsgId)
                    {
                        pos.AddMsgIdLine(s);
                    }
                    else if (fMsgStr)
                    {
                        pos.AddMsgStrLine(s);
                    }
                    else
                    {
                        fError = true;
                    }
                }
                else if (s.StartsWith("#~"))
                {
                    pos.IsObsolete = true;
                    if (pos.UserComments != null)
                    {
                        pos.UserComments.Clear();
                    }
                    if (pos.AutoComments != null)
                    {
                        pos.AutoComments.Clear();
                    }
                    if (pos.Reference != null)
                    {
                        pos.Reference.Clear();
                    }
                    if (pos.Flags != null)
                    {
                        pos.Flags.Clear();
                    }
                    if (pos.MsgId != null)
                    {
                        pos.MsgId.Clear();
                    }
                    if (pos.MsgStr != null)
                    {
                        pos.MsgStr.Clear();
                    }
                }
                else
                {
                    fError = true;
                }
                if (fError)
                {
                    Console.WriteLine("INVALID PO FILE: ERROR ON LINE " + s_cLines);
                    throw new Exception("BAD PO FILE");
                }
                if (srIn.EndOfStream)
                {
                    break;
                }
                s = srIn.ReadLine();
                ++s_cLines;
                if (s != null)
                {
                    s = s.Trim();
                }
            } while (!String.IsNullOrEmpty(s));

            return(pos);
        }
示例#8
0
		static public POString ReadFromFile(StreamReader srIn)
		{
			// Move past any blank lines, checking for the end of file.
			if (srIn.EndOfStream)
				return null;
			string s = srIn.ReadLine();
			++s_cLines;
			if (s != null)
				s = s.Trim();
			while (String.IsNullOrEmpty(s))
			{
				if (srIn.EndOfStream)
					return null;
				s = srIn.ReadLine();
				++s_cLines;
				if (s != null)
					s = s.Trim();
			}
			POString pos = new POString();
			bool fMsgId = false;
			bool fMsgStr = false;
			bool fError = false;
			do
			{
				if (s == "#")
				{
					pos.AddUserComment("");
				}
				else if (s.StartsWith("# "))
				{
					pos.AddUserComment(s.Substring(2).TrimStart());
				}
				else if (s.StartsWith("#."))
				{
					pos.AddAutoComment(s.Substring(2).TrimStart());
				}
				else if (s.StartsWith("#:"))
				{
					pos.AddReference(s.Substring(2).TrimStart());
				}
				else if (s.StartsWith("#,"))
				{
					pos.AddFlags(s.Substring(2).TrimStart());
				}
				else if (s.ToLower().StartsWith("msgid"))
				{
					fMsgId = true;
					if (fMsgStr)
						fError = true;
					pos.AddMsgIdLine(s);
				}
				else if (s.ToLower().StartsWith("msgstr"))
				{
					if (!fMsgId)
						fError = true;
					fMsgId = false;
					fMsgStr = true;
					pos.AddMsgStrLine(s);
				}
				else if (s.StartsWith("\""))
				{
					if (fMsgId)
						pos.AddMsgIdLine(s);
					else if (fMsgStr)
						pos.AddMsgStrLine(s);
					else
						fError = true;
				}
				else if (s.StartsWith("#~"))
				{
					pos.IsObsolete = true;
					if (pos.UserComments != null)
						pos.UserComments.Clear();
					if (pos.AutoComments != null)
						pos.AutoComments.Clear();
					if (pos.Reference != null)
						pos.Reference.Clear();
					if (pos.Flags != null)
					   pos.Flags.Clear();
				   if (pos.MsgId != null)
						pos.MsgId.Clear();
					if (pos.MsgStr != null)
						pos.MsgStr.Clear();
				}
				else
				{
					fError = true;
				}
				if (fError)
				{
					Console.WriteLine("INVALID PO FILE: ERROR ON LINE " + s_cLines);
					throw new Exception("BAD PO FILE");
				}
				if (srIn.EndOfStream)
					break;
				s = srIn.ReadLine();
				++s_cLines;
				if (s != null)
					s = s.Trim();
			} while (!String.IsNullOrEmpty(s));

			return pos;
		}
示例#9
0
		public bool HasSameMsgId(POString that)
		{
			if (this.m_rgsMsgId == null && that.m_rgsMsgId == null)
				return true;
			else if (this.m_rgsMsgId == null || that.m_rgsMsgId == null)
				return false;
			for (int i = 0; i < this.m_rgsMsgId.Count && i < that.m_rgsMsgId.Count; ++i)
			{
				string s1 = this.m_rgsMsgId[i];
				string s2 = that.m_rgsMsgId[i];
				if (s1 != s2)
					return false;
			}
			return this.m_rgsMsgId.Count == that.m_rgsMsgId.Count;
		}
示例#10
0
		/// <summary>
		/// CompareMsgIds two POString objects with the purpose of sorting the PO file by msgid.
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <returns></returns>
		public static int CompareMsgIds(POString x, POString y)
		{
			if (x.m_rgsMsgId == null && y.m_rgsMsgId == null)
				return 0;
			else if (x.m_rgsMsgId == null)
				return -1;
			else if (y.m_rgsMsgId == null)
				return 1;
			for (int i = 0; i < x.m_rgsMsgId.Count && i < y.m_rgsMsgId.Count; ++i)
			{
				string s1 = RemoveLeadingCruft(x.m_rgsMsgId[i].Replace("&", "").Trim());
				string s2 = RemoveLeadingCruft(y.m_rgsMsgId[i].Replace("&", "").Trim());
				int n = s1.CompareTo(s2);
				if (n != 0)
					return n;
			}
			if (x.m_rgsMsgId.Count < y.m_rgsMsgId.Count)
				return -1;
			else if (x.m_rgsMsgId.Count > y.m_rgsMsgId.Count)
				return 1;
			else
				return x.m_rgsMsgId[0].CompareTo(y.m_rgsMsgId[0]);
		}