Ejemplo n.º 1
0
        public void LoadXML(string filename)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(filename);

            XmlNode n = xml.SelectSingleNode("/root/basepath");

            this.basepath = n.Attributes["name"].Value;
            basepath      = new Regex("[/\\\\]+$").Replace(basepath, "");

            XmlNodeList nl = xml.SelectNodes("/root/resource");

            foreach (XmlNode r in nl)
            {
                TranslatedResource tr = new TranslatedResource();
                tr.basepath = basepath;

                string b = r.Attributes["base"].Value;
                if (b.IndexOf(basepath) == 0)
                {
                    b = b.Remove(0, basepath.Length);
                }

                XmlNode f = r.SelectSingleNode("files");
                foreach (XmlNode l in f.SelectNodes("file"))
                {
                    string lang = l.Attributes["lang"].Value;
                    tr.files[lang] = l.FirstChild.InnerText;
                    if (tr.files[lang].IndexOf(basepath) == 0)
                    {
                        tr.files[lang] = tr.files[lang].Remove(0, basepath.Length);
                    }
                }

                foreach (XmlNode k in r.SelectNodes("key"))
                {
                    string        key = k.Attributes["value"].Value;
                    TranslatedKey tk  = new TranslatedKey();
                    foreach (XmlNode t in k.ChildNodes)
                    {
                        string lang = t.Attributes["lang"].Value;
                        tk.Translations[lang] = t.InnerText;
                    }
                    tr.TranslatedKey[key] = tk;
                }

                Resources[b] = tr;
            }
        }
Ejemplo n.º 2
0
        public void SaveXML(string filename)
        {
            XmlTextWriter w = new XmlTextWriter(filename, null);

            w.Formatting = Formatting.Indented;

            w.WriteStartElement("root");

            w.WriteStartElement("basepath");
            w.WriteAttributeString("name", basepath);
            w.WriteEndElement();

            foreach (string res in Resources.Keys)
            {
                w.WriteStartElement("resource");
                w.WriteAttributeString("base", res);

                w.WriteStartElement("files");
                foreach (string lang in Resources[res].files.Keys)
                {
                    w.WriteStartElement("file");
                    w.WriteAttributeString("lang", lang);
                    w.WriteString(Resources[res].files[lang]);
                    w.WriteEndElement();
                }
                w.WriteEndElement();

                foreach (string key in Resources[res].TranslatedKey.Keys)
                {
                    w.WriteStartElement("key");
                    w.WriteAttributeString("value", key);
                    TranslatedKey t = Resources[res].TranslatedKey[key];
                    foreach (string lang in t.Translations.Keys)
                    {
                        w.WriteStartElement("value");
                        w.WriteAttributeString("lang", lang);
                        w.WriteString(t.Translations[lang]);
                        w.WriteEndElement();
                    }
                    w.WriteEndElement();
                }
                w.WriteEndElement();
            }

            w.Close();
        }
Ejemplo n.º 3
0
        private int countEmptyKeys()
        {
            int count = 0;

            foreach (ListViewItem item in listView1.Items)
            {
                TranslatedKey tk = (TranslatedKey)item.Tag;
                foreach (string lang in displayedLanguages)
                {
                    if (!tk.Translations.ContainsKey(lang))
                    {
                        count++;
                    }
                }
            }

            return(count);
        }
Ejemplo n.º 4
0
        private void UpdateItem(ListViewItem item)
        {
            TranslatedKey tk = (TranslatedKey)item.Tag;

            foreach (string lang in displayedLanguages)
            {
                if (tk.Translations.ContainsKey(lang))
                {
                    item.SubItems[lang].BackColor = Color.Transparent;
                    item.SubItems[lang].Text      = tk.Translations[lang];
                }
                else
                {
                    item.SubItems[lang].BackColor = Color.LightSalmon;
                    item.SubItems[lang].Text      = "";
                }
            }
        }
Ejemplo n.º 5
0
        private void lang2TextBox_Leave(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count <= 0)
            {
                return;
            }

            string        lang = "de";
            ListViewItem  item = listView1.SelectedItems[0];
            TranslatedKey tk   = (TranslatedKey)item.Tag;

            if (!tk.Translations.ContainsKey(lang))
            {
                tk.Add(lang, "");
            }
            tk.Translations[lang]    = lang2TextBox.Text;
            item.SubItems[lang].Text = lang2TextBox.Text;
            UpdateItem(item);
            textBox2.Text = countEmptyKeys().ToString();
        }