private void ShowSelectedRecourceForChange(KeyValuePair <XmlNode, Dictionary <string, XmlNode> > resource) { ResourcelistView.Items.Clear(); ResourceKeytextBox.Text = resource.Key.Attributes["Key"].Value; ResourceUpdatedtextBox.Text = Convert.ToDateTime(resource.Key.Attributes["Updated"].Value).ToString("yyyy-MM-dd hh:mm:ss"); ResourceTranslatetextBox.Text = resource.Key.Attributes["Translate"].Value; ResourceChangetextBox.Text = resource.Key.Attributes["Change"].Value; foreach (KeyValuePair <string, XmlNode> translation in resource.Value) { ListViewItem newItem = ResourcelistView.Items.Add(translation.Key); newItem.SubItems.Add(translation.Value.InnerText); } if (!resource.Key.Attributes["Change"].Value.Contains("Deleted")) { UndoDeletebutton.Visible = false; string resourceType = ChangedResourcestreeView.Tag.ToString(); FindSuggestedTranslations(resource.Value[Localizer.GetDefaultCultureName(resourceType)].InnerText, resource.Key.Attributes["Key"].Value, resourceType); } else { UndoDeletebutton.Visible = true; SuggestedTranslationslistView.Clear(); } }
private void FindSuggestedTranslations(string text, string currentResourceKey, string resourceType) { Dictionary <string, int> columnDictionary = new Dictionary <string, int>(); SuggestedTranslationslistView.Items.Clear(); SuggestedTranslationslistView.Columns.Clear(); SuggestedTranslationslistView.Clear(); SuggestedTranslationslistView.Columns.Add(Localizer.GetDefaultCultureName(resourceType)); foreach (string moduleName in masterData[resourceType].Value.Keys) { foreach (string resourceContainerKey in masterData[resourceType].Value[moduleName].Value.Keys) { foreach (string resourceKey in masterData[resourceType].Value[moduleName].Value[resourceContainerKey].Value.Keys) { KeyValuePair <XmlNode, Dictionary <string, XmlNode> > resource = masterData[resourceType].Value[moduleName].Value[resourceContainerKey].Value[resourceKey]; if (resourceKey != currentResourceKey) { if (resource.Value[Localizer.GetDefaultCultureName(resourceType)].InnerText == text) { ListViewItem newItem = SuggestedTranslationslistView.Items.Add(resource.Value[Localizer.GetDefaultCultureName(resourceType)].InnerText); Dictionary <string, ListViewItem.ListViewSubItem> translations = new Dictionary <string, ListViewItem.ListViewSubItem>(); foreach (KeyValuePair <string, XmlNode> translation in resource.Value) { if (translation.Key != Localizer.GetDefaultCultureName(resourceType)) { if (!columnDictionary.ContainsKey(translation.Key)) { columnDictionary.Add(translation.Key, columnDictionary.Count + 1); SuggestedTranslationslistView.Columns.Add(translation.Key); } ListViewItem.ListViewSubItem newSubItem = new ListViewItem.ListViewSubItem(newItem, translation.Value.InnerText); translations.Add(translation.Key, newSubItem); } } foreach (KeyValuePair <string, int> column in columnDictionary) { if (translations.ContainsKey(column.Key)) { newItem.SubItems.Add(translations[column.Key]); } else { newItem.SubItems.Add(string.Empty); } } } } } } } }
private void useTranslationToolStripMenuItem_Click(object sender, EventArgs e) { if (SuggestedTranslationslistView.SelectedItems.Count == 1) { if (ChangedResourcestreeView.SelectedNode != null && ChangedResourcestreeView.SelectedNode.Tag != null) { string resourceType = ChangedResourcestreeView.Tag.ToString(); KeyValuePair <XmlNode, Dictionary <string, XmlNode> > resource = (KeyValuePair <XmlNode, Dictionary <string, XmlNode> >)ChangedResourcestreeView.SelectedNode.Tag; KeyValuePair <string, XmlNode> defaultTranslation = new KeyValuePair <string, XmlNode>(); foreach (KeyValuePair <string, XmlNode> translation in resource.Value) { if (translation.Key != Localizer.GetDefaultCultureName(resourceType)) { resource.Key.RemoveChild(translation.Value); } else { defaultTranslation = new KeyValuePair <string, XmlNode>(translation.Key, translation.Value); } } resource.Value.Clear(); resource.Value.Add(defaultTranslation.Key, defaultTranslation.Value); for (int index = 0; index < SuggestedTranslationslistView.Columns.Count; index++) { if (SuggestedTranslationslistView.Columns[index].Text != Localizer.GetDefaultCultureName(resourceType)) { string text; string cultureName = SuggestedTranslationslistView.Columns[index].Text; text = SuggestedTranslationslistView.SelectedItems[0].SubItems[index].Text; XmlElement newTranslation = resource.Key.OwnerDocument.CreateElement("Text"); newTranslation.SetAttribute("CultureName", cultureName); newTranslation.InnerText = text; resource.Key.AppendChild(newTranslation); resource.Value.Add(cultureName, newTranslation); } } if (!resource.Key.Attributes["Change"].Value.Contains("(")) { resource.Key.Attributes["Change"].Value += "_(Updated)"; } ShowSelectedRecourceForChange(resource); } } }
private void StructuretreeView_AfterSelect(object sender, TreeViewEventArgs e) { PropertiesKeytextBox.Text = string.Empty; PropertiesTranslatecheckBox.Enabled = false; PropertiesTranslatecheckBox.Checked = false; PropertiesTexttextBox.Text = string.Empty; if (e.Node.Tag != null) { string resourceType = ChangedResourcestreeView.Tag.ToString(); XmlNode selectedXmlNode = (XmlNode)e.Node.Tag; if (selectedXmlNode.Name == "Module") { PropertiesKeytextBox.Text = selectedXmlNode.Attributes["Name"].Value; } else { PropertiesKeytextBox.Text = selectedXmlNode.Attributes["Key"].Value; } if (selectedXmlNode.Name == "Module" || selectedXmlNode.Name == "Resource") { PropertiesTranslatecheckBox.Checked = Convert.ToBoolean(selectedXmlNode.Attributes["Translate"].Value); PropertiesTranslatecheckBox.Enabled = true; } else { PropertiesTranslatecheckBox.Enabled = false; } if (selectedXmlNode.Name == "Resource") { foreach (XmlNode childNode in selectedXmlNode.ChildNodes) { if (childNode.Attributes["CultureName"].Value == Localizer.GetDefaultCultureName(resourceType)) { PropertiesTexttextBox.Text = childNode.InnerText; } } } } }
private void removeLanguageToolStripMenuItem_Click(object sender, EventArgs e) { RemoveLngtoolStripComboBox.Items.Clear(); if (masterData != null) { string rt = ChangedResourcestreeView.Tag.ToString(); RemoveLngtoolStripComboBox.Items.AddRange(Localizer.GetSupportedTranslationsCultureNames(rt).Where(t => t != Localizer.GetDefaultCultureName(rt)).ToArray()); } }
private void EditTranslationtextBox_Leave(object sender, EventArgs e) { if (colResize) { EditTranslationtextBox.Focus(); } else { if (ChangedResourcestreeView.SelectedNode != null && ChangedResourcestreeView.SelectedNode.Tag != null) { if (ResourcelistView.SelectedItems.Count > 0 && ResourcelistView.SelectedItems[0].Text != Localizer.GetDefaultCultureName(ChangedResourcestreeView.Tag.ToString())) { string resourceType = ChangedResourcestreeView.Tag.ToString(); KeyValuePair <XmlNode, Dictionary <string, XmlNode> > resource = (KeyValuePair <XmlNode, Dictionary <string, XmlNode> >)ChangedResourcestreeView.SelectedNode.Tag; string cultureName = ResourcelistView.SelectedItems[0].Text; if (resource.Value.ContainsKey(cultureName)) { if (resource.Value[cultureName].InnerText != EditTranslationtextBox.Text) { resource.Value[cultureName].InnerText = EditTranslationtextBox.Text; if (!resource.Key.Attributes["Change"].Value.Contains("(")) { resource.Key.Attributes["Change"].Value += "_(Updated)"; } ShowSelectedRecourceForChange(resource); } } } } EditTranslationtextBox.Visible = false; } colResize = false; }
private void TranslatecontextMenuStrip_Opening(object sender, CancelEventArgs e) { e.Cancel = false; if (ResourcelistView.SelectedItems.Count == 0 || ResourcelistView.SelectedItems[0].Text == Localizer.GetDefaultCultureName(ChangedResourcestreeView.Tag.ToString())) { e.Cancel = true; } }
private void EditInExcel(string resourceType) { if (masterData != null) { Dictionary <string, int> cellDictionary = new Dictionary <string, int>(); Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); app.Visible = false; app.DisplayAlerts = false; try { Workbook workbook = null; workbook = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); try { this.Cursor = Cursors.WaitCursor; //Create DataArray //=================================================================================================================================================================================== int numberOfRows = 2; int numberOfCols = -1; foreach (string rt in masterData.Keys) { if (rt == resourceType) { foreach (string moduleName in masterData[rt].Value.Keys) { if (Convert.ToBoolean(masterData[rt].Value[moduleName].Key.Attributes["Translate"].Value)) { foreach (string resourceKey in masterData[rt].Value[moduleName].Value.Keys) { int numOfTransKeys = masterData[rt].Value[moduleName].Value[resourceKey].Value.Where(k => Convert.ToBoolean(k.Value.Key.Attributes["Translate"].Value)).Count(); numberOfRows += numOfTransKeys; //Find number of columns. Only done once if (numberOfCols == -1) { if (numOfTransKeys == masterData[rt].Value[moduleName].Value[resourceKey].Value.Count) { numberOfCols = masterData[rt].Value[moduleName].Value[resourceKey].Value.First().Value.Value.Count; numberOfCols += 5; //Add overhead columns } } } } } } } object[,] data = new object[numberOfRows, numberOfCols]; //=================================================================================================================================================================================== Worksheet sheet = (Worksheet)workbook.Worksheets.get_Item(1); sheet.Activate(); sheet.Application.ActiveWindow.SplitRow = 1; sheet.Application.ActiveWindow.SplitColumn = 6; sheet.Application.ActiveWindow.FreezePanes = true; sheet.Cells[1, 5].EntireColumn.ColumnWidth = 15; sheet.Cells[1, 6].EntireColumn.NumberFormat = "@"; sheet.Cells[1, 6].EntireColumn.WrapText = true; sheet.Cells[1, 6].EntireColumn.ColumnWidth = 40; data[0, 0] = "ResourceType"; data[0, 1] = "Module"; data[0, 2] = "ResourceKey"; data[0, 3] = "Key"; data[0, 4] = "Updated"; data[0, 5] = "text"; //sheet.Cells[1, 1] = "ResourceType"; //sheet.Cells[1, 2] = "Module"; //sheet.Cells[1, 3] = "ResourceKey"; //sheet.Cells[1, 4] = "Key"; //sheet.Cells[1, 5] = "Updated"; //sheet.Cells[1, 6] = "text"; int colIndex = 7; Dictionary <string, int> translationDictionary = new Dictionary <string, int>(); foreach (string cultureName in Localizer.GetSupportedTranslationsCultureNames(resourceType)) { sheet.Cells[1, colIndex].EntireColumn.ColumnWidth = 40; sheet.Cells[1, colIndex].EntireColumn.NumberFormat = "@"; //sheet.Cells[1, colIndex] = cultureName; data[0, colIndex - 1] = cultureName; translationDictionary.Add(cultureName, colIndex - 1); colIndex++; } sheet.Cells.Locked = false; sheet.Range["1:1"].EntireRow.Locked = true; sheet.Range["1:1"].EntireRow.Font.Bold = true; //int insertIndex = Math.Max(sheet.UsedRange.Rows.Count, 1); int insertIndex = 1; foreach (string rt in masterData.Keys) { if (rt == resourceType) { foreach (string moduleName in masterData[rt].Value.Keys) { if (Convert.ToBoolean(masterData[rt].Value[moduleName].Key.Attributes["Translate"].Value)) { foreach (string resourceKey in masterData[rt].Value[moduleName].Value.Keys) { foreach (string key in masterData[rt].Value[moduleName].Value[resourceKey].Value.Keys) { if (Convert.ToBoolean(masterData[rt].Value[moduleName].Value[resourceKey].Value[key].Key.Attributes["Translate"].Value)) { string updated = masterData[rt].Value[moduleName].Value[resourceKey].Value[key].Key.Attributes["Updated"].Value; data[insertIndex, 0] = rt; data[insertIndex, 1] = moduleName; data[insertIndex, 2] = resourceKey; data[insertIndex, 3] = key; data[insertIndex, 4] = updated; //sheet.Cells[insertIndex, 1] = rt; //sheet.Cells[insertIndex, 2] = moduleName; //sheet.Cells[insertIndex, 3] = resourceKey; //sheet.Cells[insertIndex, 4] = key; //sheet.Cells[insertIndex, 5] = updated; foreach (KeyValuePair <string, XmlNode> translation in masterData[rt].Value[moduleName].Value[resourceKey].Value[key].Value) { if (translation.Key == Localizer.GetDefaultCultureName(rt)) { //sheet.Cells[insertIndex, 6] = translation.Value.InnerText; data[insertIndex, 5] = translation.Value.InnerText; } else { //sheet.Cells[insertIndex, translationDictionary[translation.Key]] = translation.Value.InnerText; data[insertIndex, translationDictionary[translation.Key]] = translation.Value.InnerText; } } insertIndex++; } } } } } } } Range startCell = (Range)sheet.Cells[1, 1]; Range endCell = (Range)sheet.Cells[numberOfRows, numberOfCols]; Range writeRange = sheet.Range[startCell, endCell]; writeRange.Value2 = data; //string tmpFileName = "TranslationWorkSheet_" + Guid.NewGuid().ToString() + ".xlsx"; //string tmpFilePath = (Path.Combine(System.Windows.Forms.Application.ExecutablePath, tmpFileName)); //workbook.SaveAs(tmpFilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); excelIsClosed = false; Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeCloseEventHandler Event_BeforeBookClose; Event_BeforeBookClose = new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeCloseEventHandler(app_WorkbookBeforeClose); app.WorkbookBeforeClose += Event_BeforeBookClose; app.Visible = true; //Wait until excel is closed while (!excelIsClosed) { System.Threading.Thread.Sleep(1000); } if (excelData != null) { UpdateMasterFromExcelData(excelData); } this.Cursor = Cursors.Default; Marshal.FinalReleaseComObject(sheet); sheet = null; } finally { Marshal.FinalReleaseComObject(workbook); workbook = null; } } catch (Exception ex) { } finally { Marshal.FinalReleaseComObject(app); app = null; GC.Collect(); } } }