private void OnSelectedIndexChanged(object sender, EventArgs e) { if (dataGrid.SelectedRows.Count > 0) { DataGridViewRow row = dataGrid.SelectedRows[0]; InternalKey key = (InternalKey)row.Tag; if (key != null) { namespaceEdit.Text = row.Cells[1].Value.ToString(); keyEdit.Text = key.Key; pathEdit.Text = key.Path; if (row.Cells[4].Value != null) { translationEdit.Text = row.Cells[4].Value.ToString(); } else { translationEdit.Text = ""; } } } else { namespaceEdit.Text = ""; keyEdit.Text = ""; pathEdit.Text = ""; translationEdit.Text = ""; } }
public void LoadFromArchive(string Culture, string FileText) { if (Subnamespaces == null) { throw new System.InvalidOperationException("Load manifest first."); } if (Cultures.Contains(Culture)) { throw new System.ArgumentException("Culture already appended: " + Culture); } LocaleArchive archive = JsonConvert.DeserializeObject <LocaleArchive>(FileText); if (ArchiveVersion != archive.FormatVersion) { throw new FormatException("Invalid Archive::FormatVersion."); } if (ArchiveNamespace != archive.Namespace) { throw new FormatException("Invalid Archive::Namespace. Must be empty."); } // Move "Children" to "Subnamespace" without name if (archive.Children != null && archive.Children.Count > 0) { LocaleArchiveNamespace emptyNS = new LocaleArchiveNamespace(); emptyNS.Namespace = ""; emptyNS.Children = archive.Children; archive.Subnamespaces.Insert(0, emptyNS); } foreach (var ns in archive.Subnamespaces) { InternalNamespace ins = GetNamespace(ns.Namespace); if (ins == null) { throw new FormatException("Archive::Subnamespace not found: " + ns.Namespace + "!"); } foreach (var child in ns.Children) { InternalKey ikey = ins.GetKey(child.Key); if (ikey == null) { throw new FormatException("Invalid key (" + child.Key + ") in Archive::Subnamespace::Child " + child.Source.Text + "!"); } InternalText text = new InternalText(); text.Culture = Culture; text.Text = child.Translation.Text; ikey.Translations.Add(text); } } Cultures.Add(Culture); }
public void LoadFromManifest(string InFileName, string FileText) { Clear(); LocaleManifest manifest = JsonConvert.DeserializeObject <LocaleManifest>(FileText); if (ManifestVersion != manifest.FormatVersion) { throw new FormatException("Invalid Manifest::FormatVersion."); } if (ManifestNamespace != manifest.Namespace) { throw new FormatException("Invalid Manifest::Namespace. Must be empty."); } // Move "Children" to "Subnamespace" without name if (manifest.Children != null && manifest.Children.Count > 0) { LocaleManifestNamespace emptyNS = new LocaleManifestNamespace(); emptyNS.Namespace = ""; emptyNS.Children = manifest.Children; manifest.Subnamespaces.Insert(0, emptyNS); } Subnamespaces = new List <InternalNamespace>(); foreach (var ns in manifest.Subnamespaces) { InternalNamespace ins = new InternalNamespace(); ins.Name = ns.Namespace; ins.Children = new List <InternalRecord>(ns.Children.Count); foreach (var child in ns.Children) { InternalRecord record = new InternalRecord(); record.Source = child.Source.Text; record.Keys = new List <InternalKey>(child.Keys.Count); foreach (var key in child.Keys) { InternalKey ikey = new InternalKey(); ikey.Key = key.Key; ikey.Path = key.Path; ikey.Translations = new List <InternalText>(); ikey.parent = record; record.Keys.Add(ikey); } ins.Children.Add(record); } Subnamespaces.Add(ins); } Cultures = new List <string>(); }
// // Utilites // public void SetRowTranslation(DataGridViewRow row, string text) { InternalKey key = (InternalKey)row.Tag; if (key != null) { string culture = cultureCombo.SelectedItem.ToString(); row.Cells[4].Value = text; key.SetTranslationForCulture(culture, text); } }
private void UpdateLocaleListTranslation() { dataGrid.SuspendLayout(); if (data != null) { string culture = cultureCombo.SelectedItem.ToString(); bool native = (culture == data.NativeCulture); dataGrid.Columns[3].HeaderText = native ? "Source" : "Native Culture"; foreach (DataGridViewRow item in dataGrid.Rows) { InternalKey key = (InternalKey)item.Tag; item.Cells[3].Value = native ? key.parent.Source : key.GetTranslationForCulture(data.NativeCulture); item.Cells[4].Value = key.GetTranslationForCulture(culture); } } dataGrid.ResumeLayout(); }
public static InternalFormat Import(string FileName) { InternalFormat data = null; // open excel document Excel.Application App = new Excel.Application(); Excel.Workbooks Workbooks = App.Workbooks; Excel.Workbook Workbook = Workbooks.Open(FileName); Excel._Worksheet Worksheet = App.ActiveSheet; Excel.Range Range = Worksheet.UsedRange; // read document data var Cells = Range.Value2; int rowCount = Cells.GetLength(0); int columnCount = Cells.GetLength(1); data = new InternalFormat(); // read native and other cultures data.Cultures = new List <string>(); for (int col = 3; col <= columnCount; col++) { if (Cells[1, col] != null) { // third column is NativeCulture if (col == 3) { data.NativeCulture = Cells[1, col]; } data.Cultures.Add(Cells[1, col]); } } int index = 2; int cultureCount = data.Cultures.Count; List <InternalKey> keys = new List <InternalKey>(rowCount / 2); // read all translation keys for (; Cells[index, 1].ToString() != serviceData; index++) { InternalKey key = new InternalKey(); key.Key = InternalNamespace.SplitFullName(Cells[index, 2])[1]; key.Translations = new List <InternalText>(cultureCount); for (int culture = 0; culture < cultureCount; culture++) { InternalText translation = new InternalText(); translation.Culture = data.Cultures[culture]; translation.Text = Cells[index, culture + 3]; if (translation.Text == null) { translation.Text = ""; } else // replace \n to \r\n { translation.Text = Regex.Replace(translation.Text, "(?<!\r)\n", "\r\n"); } key.Translations.Add(translation); } keys.Add(key); } int indexOfServiceData = index; data.Subnamespaces = new List <InternalNamespace>(rowCount / 2); InternalNamespace lastNS = null; InternalRecord lastRec = null; index++; for (; index < rowCount + 1; index++) { string source = Cells[index, 1]; string ns = Cells[index, 2]; string key = Cells[index, 3]; string path = Cells[index, 4]; if (lastNS == null || lastNS.Name != ns) { lastNS = new InternalNamespace(); lastNS.Name = ns; lastNS.Children = new List <InternalRecord>(); data.Subnamespaces.Add(lastNS); lastRec = null; } if (lastRec == null || lastRec.Source != source) { lastRec = new InternalRecord(); lastRec.Source = source; lastRec.Keys = new List <InternalKey>(); lastNS.Children.Add(lastRec); } InternalKey ikey = keys[index - indexOfServiceData - 1]; if (ikey.Key != key) { throw new FormatException("Unexpected key: " + key + "!"); } ikey.Path = path; ikey.parent = lastRec; lastRec.Keys.Add(ikey); } // close excel and clear all headres Marshal.ReleaseComObject(Range); Range = null; Marshal.ReleaseComObject(Worksheet); Worksheet = null; Workbook.Close(false, Type.Missing, Type.Missing); Marshal.ReleaseComObject(Workbook); Workbook = null; Workbooks.Close(); Marshal.ReleaseComObject(Workbooks); Workbooks = null; App.Quit(); Marshal.ReleaseComObject(App); App = null; return(data); }