コード例 #1
0
 public MessageBody(string lang, string[] ids, string[] messages)
 {
     this.lang = lang;
     list      = new SortedDictionary <string, MessageBodyEntry>();
     for (int i = 0; i < ids.Length; i++)
     {
         list[ids[i]] = new MessageBodyEntry(messages[i], new string[] { });
     }
 }
コード例 #2
0
        public void write(string file)
        {
            StreamWriter sw = null;

            try {
                sw = new StreamWriter(file, false, new UTF8Encoding(false));
                if (!poHeader.Equals(""))
                {
                    sw.WriteLine("msgid \"\"");
                    sw.WriteLine("msgstr \"\"");
                    string[] spl = PortUtil.splitString(poHeader, new char[] { (char)0x0d, (char)0x0a }, true);
                    for (int i = 0; i < spl.Length; i++)
                    {
                        string line = spl[i];
                        sw.WriteLine("\"" + line + "\\" + "n\"");
                    }
                    sw.WriteLine();
                }
                else
                {
                    sw.WriteLine("msgid \"\"");
                    sw.WriteLine("msgstr \"\"");
                    sw.WriteLine("\"Content-Type: text/plain; charset=UTF-8\\" + "n\"");
                    sw.WriteLine("\"Content-Transfer-Encoding: 8bit\\" + "n\"");
                    sw.WriteLine();
                }
                foreach (var key in list.Keys)
                {
                    string           skey     = key.Replace("\n", "\\n\"\n\"");
                    MessageBodyEntry mbe      = list[key];
                    string           s        = mbe.message;
                    List <string>    location = mbe.location;
                    int count = location.Count;
                    for (int i = 0; i < count; i++)
                    {
                        sw.WriteLine("#: " + location[i]);
                    }
                    sw.WriteLine("msgid \"" + skey + "\"");
                    s = s.Replace("\n", "\\n\"\n\"");
                    sw.WriteLine("msgstr \"" + s + "\"");
                    sw.WriteLine();
                }
            } catch (Exception ex) {
            } finally {
                if (sw != null)
                {
                    try {
                        sw.Close();
                    } catch (Exception ex2) {
                    }
                }
            }
        }