示例#1
0
        /// <summary>
        /// Loads a line to be translated by key. If the line doesn't
        /// exist or the key is null the translation elements will be reset.
        /// </summary>
        /// <param name="key"></param>
        private void LoadLine(string key)
        {
            this.UpdateSelectedListItem();
            this.UpdateTranslatedCount();

            // Reset it null or unknown key
            if (key == null || !_originalLines.TryGetValue(key, out var originalValue))
            {
                this.ResetTranslationControls();
                return;
            }

            if (!_translatedLines.TryGetValue(key, out var translatedValue))
            {
                translatedValue = originalValue;
            }

            // Prepare doc
            var doc = this.GetDoc(translatedValue);

            // Get translatable elements from document
            var elements = new List <TranslatableElement>();

            foreach (var node in doc.DocumentNode.ChildNodes)
            {
                elements.AddRange(this.GetElements(key, node));
            }

            // Create buttons
            this.Elements.Controls.Clear();
            foreach (var element in elements)
            {
                var button = new Button();
                button.Text   = element.Name;
                button.Tag    = element;
                button.Click += this.Element_Click;

                this.Elements.Controls.Add(button);
            }

            // Save current objects
            _currentDoc     = doc;
            _currentElement = null;

            // Initialize input
            _loading = true;
            this.TxtOriginalLine.Text     = originalValue;
            this.TxtTranslatedLine.Text   = translatedValue;
            this.TxtTranslateElement.Text = "";
            this.LoadMachineTranslation();
            _loading = false;
        }
示例#2
0
        /// <summary>
        /// Loads the clicked element to be translated.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Element_Click(object sender, EventArgs e)
        {
            var button  = (sender as Button);
            var element = (button.Tag as TranslatableElement);

            foreach (Button control in this.Elements.Controls)
            {
                control.ForeColor = DefaultColor;
            }

            button.ForeColor = HighlightColor;
            _currentElement  = element;

            this.TxtTranslateElement.Text = element.Text;
            this.TxtTranslateElement.SelectAll();
            this.TxtTranslateElement.Select();
        }
示例#3
0
        /// <summary>
        /// Opens the given file as original file.
        /// </summary>
        /// <param name="filePath"></param>
        private void OpenOriginal(string filePath)
        {
            if (!File.Exists(filePath))
            {
                MessageBox.Show(this, "File not found.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var sr = new StreamReader(fs))
                    {
                        // Clear variables once we have access to the file
                        _openOriginalFilePath = filePath;
                        _originalLines.Clear();
                        _translatedLines.Clear();
                        _lineKeys.Clear();
                        _loading        = false;
                        _currentDoc     = null;
                        _currentElement = null;
                        _elementButtons.Clear();
                        _translatableElements.Clear();
                        _selectedListViewItem = null;

                        this.LstLines.Items.Clear();
                        this.LstLines.BeginUpdate();

                        // Load lines
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            var index = line.IndexOf('\t');
                            if (index == -1)
                            {
                                continue;
                            }

                            var key   = line.Substring(0, index);
                            var value = line.Substring(index + 1);

                            value = Regex.Replace(value, "<br ?/>", Environment.NewLine);

                            _originalLines[key] = value;
                            _lineKeys.Add(key);

                            var lvi = this.LstLines.Items.Add(key);
                            lvi.Tag = key;
                        }

                        this.LstLines.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                        this.LstLines.EndUpdate();

                        this.ResetTranslationControls();
                        this.UpdateTranslatedCount();
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Failed to open file. Error: " + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }