Example #1
0
        private void OnEditEntry(object sender, EventArgs e)
        {
            if (lvTranslations.SelectedItems.Count == 1)
            {
                TranslationItem ti = lvTranslations.SelectedItems[0].Tag as TranslationItem;
                if (ti != null && _tf.Items.ContainsKey(ti.StringName))
                {
                    string oldName = ti.StringName;

                    EntryNameDialog dlg = new EntryNameDialog(oldName, ti.BaseString, ti.TranslatedString, chkReadOnly.Checked, cmbLanguage.Text);
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ti.StringName       = dlg.EntryName;
                        ti.BaseString       = dlg.EnglishString;
                        ti.TranslatedString = dlg.TranslatedString;

                        _tf.Items.Remove(oldName);
                        _tf.Items.Add(ti.StringName, ti);

                        lvTranslations.SelectedItems[0].SubItems[0].Text = ti.StringName;
                        lvTranslations.SelectedItems[0].SubItems[1].Text = ti.BaseString;
                        lvTranslations.SelectedItems[0].SubItems[2].Text = ti.TranslatedString;
                    }
                }
            }
        }
Example #2
0
        private void OnNewEntry(object sender, EventArgs e)
        {
            EntryNameDialog dlg = new EntryNameDialog("TXT_ENTRY_NAME", "", "", chkReadOnly.Checked, cmbLanguage.Text);

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TranslationItem ti = new TranslationItem(string.Empty);
                ti.StringName       = dlg.EntryName;
                ti.BaseString       = dlg.EnglishString;
                ti.TranslatedString = dlg.TranslatedString;

                _tf.Items.Add(ti.StringName, ti);

                ListViewItem item = new ListViewItem(new string[]
                {
                    ti.StringName, ti.BaseString, ti.TranslatedString
                });

                item.Tag = ti;
                lvTranslations.Items.Add(item);

                lvTranslations.SelectedItems.Clear();
                item.Selected = true;

                lvTranslations.EnsureVisible(item.Index);
            }
        }
Example #3
0
        private void StartTask(string sourceFile, string destFile, List <string> tags, bool isMove, bool isDelete)
        {
            if (!isDelete)
            {
                foreach (string lang in TranslationFile.SupportedLanguages)
                {
                    TranslationFile srcTranslation  = new TranslationFile(sourceFile, lang);
                    TranslationFile destTranslation = new TranslationFile(destFile, lang);

                    foreach (string tag in tags)
                    {
                        TranslationItem ti = srcTranslation.Items[tag];
                        destTranslation.Items[tag] = ti;
                    }

                    destTranslation.ForceSave();
                }
            }

            if (isMove || isDelete)
            {
                foreach (string lang in TranslationFile.SupportedLanguages)
                {
                    TranslationFile srcTranslation = new TranslationFile(sourceFile, lang);

                    foreach (string tag in tags)
                    {
                        srcTranslation.Items.Remove(tag);
                    }

                    srcTranslation.ForceSave();
                }
            }
        }
Example #4
0
        private void DeleteSelectedEntries()
        {
            if (lvTranslations.SelectedItems.Count == 1)
            {
                TranslationItem ti = lvTranslations.SelectedItems[0].Tag as TranslationItem;
                if (ti != null && _tf.Items.ContainsKey(ti.StringName))
                {
                    _tf.Items.Remove(ti.StringName);

                    lvTranslations.Items.Remove(lvTranslations.SelectedItems[0]);
                }
            }
        }
Example #5
0
        public bool CheckConflictingResource(string language, TranslationItem ti, ref TranslationItem conflict)
        {
            Dictionary <string, TranslationItem> langResources = _resources[language];
            string cmp = (language == "en") ? ti.BaseString : ti.TranslatedString;

            foreach (KeyValuePair <string, TranslationItem> kvp in langResources)
            {
                string s1 = kvp.Key.Trim().ToLowerInvariant();
                string s2 = cmp.Trim().ToLowerInvariant();

                if ((s1 == s2) || (s1 == s2 + ":") || (s1 + ":" == s2))
                {
                    conflict = kvp.Value;
                    return(true);
                }
            }

            langResources.Add(cmp, ti);

            return(false);
        }
Example #6
0
        private bool BuildBaseItems()
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(_path);

                XmlNodeList nodes = doc.GetElementsByTagName("data");
                if (nodes != null && nodes.Count > 0)
                {
                    foreach (XmlNode node in nodes)
                    {
                        TranslationItem ti = new TranslationItem(_path);
                        ti.StringName = node.Attributes["name"].Value;
                        ti.BaseString = GetValueFromNode(node);

                        if (Items.ContainsKey(ti.StringName))
                        {
                            Items[ti.StringName].BaseString = ti.BaseString;
                        }
                        else
                        {
                            Items.Add(ti.StringName, ti);
                        }
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("BuildBaseItems failed: " + ex.Message);
            }

            return(false);
        }
Example #7
0
        void ResourceValidationDialog_Load(object sender, EventArgs e)
        {
            Dictionary <string, List <TranslationItem[]> > duplicateTranslations =
                new Dictionary <string, List <TranslationItem[]> >();

            foreach (string file in _scanAssemblies)
            {
                if (!duplicateTranslations.ContainsKey("en"))
                {
                    duplicateTranslations["en"] = new List <TranslationItem[]>();
                }

                TranslationFile tf = new TranslationFile(file, "ro");

                foreach (TranslationItem ti in tf.Items.Values)
                {
                    try
                    {
                        TranslationItem conflict = null;
                        if (CheckConflictingResource("en", ti, ref conflict))
                        {
                            List <TranslationItem[]> lst  = duplicateTranslations["en"];
                            TranslationItem[]        pair = new TranslationItem[2] {
                                ti, conflict
                            };

                            lst.Add(pair);
                        }
                    }
                    catch
                    {
                    }
                }


                foreach (string lang in TranslationFile.SupportedLanguages)
                {
                    if (!duplicateTranslations.ContainsKey(lang))
                    {
                        duplicateTranslations[lang] = new List <TranslationItem[]>();
                    }

                    tf = new TranslationFile(file, lang);

                    foreach (TranslationItem ti in tf.Items.Values)
                    {
                        try
                        {
                            TranslationItem conflict = null;
                            if (CheckConflictingResource(lang, ti, ref conflict))
                            {
                                List <TranslationItem[]> lst  = duplicateTranslations[lang];
                                TranslationItem[]        pair = new TranslationItem[2] {
                                    ti, conflict
                                };

                                lst.Add(pair);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }

            tvResults.Nodes.Clear();

            foreach (KeyValuePair <string, List <TranslationItem[]> > kvp in duplicateTranslations)
            {
                TreeNode langNode = tvResults.Nodes.Add(string.Format("{0} - {1} conflict(s) found", kvp.Key, kvp.Value.Count));

                List <TranslationItem[]> lst = null;

                try
                {
                    lst = kvp.Value.ToList();
                    lst.Sort(CompareSort);
                }
                catch
                {
                }

                foreach (TranslationItem[] cds in lst)
                {
                    TreeNode conflictNode = langNode.Nodes.Add(cds[0].StringName);

                    conflictNode.Nodes.Add(cds[0].ToString());
                    conflictNode.Nodes.Add(cds[1].ToString());
                }
            }

            //tvResults.ExpandAll();
        }