Exemple #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            List <TranslationTable> tables = GetXmlsFromViewTable();

            for (int K = 0; K < languages.Count; K++)
            {
                TranslationTable tab = tables[K];
                SerializeXml(languages[K], ref tab);
            }
        }
Exemple #2
0
        public void LoadTables()
        {
            xmlFiles = GetFileNames("tables/", "*.xml");

            foreach (string xmlFile in xmlFiles)
            {
                string fileContent = File.ReadAllText("tables/" + xmlFile);
                string language    = xmlFile.Split('_')[1].Split('.')[0];
                languages.Add(language);
                TranslationTable table = Deserialize(fileContent);
                listOfTranslationTables.Add(table);
            }

            if (listOfTranslationTables.Count > 0)
            {
                CreateTable();
            }
        }
Exemple #3
0
        private List <TranslationTable> GetXmlsFromViewTable()
        {
            List <TranslationTable> tables = new List <TranslationTable>();
            int iCol = 0;

            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                TranslationTable m     = new TranslationTable();
                List <Entry>     items = new List <Entry>();
                int iRow = 0;
                if (iCol > 0)
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        string string_name = row.Cells[0].Value != null ? row.Cells[0].Value.ToString() : "";
                        if (String.IsNullOrEmpty(string_name))
                        {
                            continue;
                        }
                        string result = row.Cells[iCol].Value != null ? row.Cells[iCol].Value.ToString() : "";

                        Entry item = new Entry
                        {
                            StringName = string_name,
                            Result     = String.IsNullOrEmpty(result) ? "--" : result
                        };

                        if (String.IsNullOrEmpty(item.StringName))
                        {
                            continue;
                        }
                        items.Add(item);
                        iRow++;
                    }
                    m.Language = languages[iCol - 1];
                    m.Entries  = items;
                    tables.Add(m);
                }
                iCol++;
            }
            return(tables);
        }
Exemple #4
0
        private void SerializeXml(string lan, ref TranslationTable tab)
        {
            var ser = new XmlSerializer(typeof(TranslationTable));
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("", "");

            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent             = true
            };

            using (StreamWriter stream = new StreamWriter("tables/translationTable_" + lan + ".xml"))
            {
                using (var writer = XmlWriter.Create(stream, settings))
                {
                    ser.Serialize(writer, tab, ns);
                }
            }
        }