예제 #1
0
        private void Translate(string source, string target, CopyPasteTranslator translator, int maxTextSize)
        {
            buttonOk.Enabled     = false;
            buttonCancel.Enabled = false;
            _abort = false;
            progressBarTranslate.Maximum = _subtitleOriginal.Paragraphs.Count;
            progressBarTranslate.Value   = 0;
            progressBarTranslate.Visible = true;

            try
            {
                var log           = new StringBuilder();
                var selectedItems = listViewTranslate.SelectedItems;
                var startIndex    = selectedItems.Count <= 0 ? 0 : selectedItems[0].Index;
                var start         = startIndex;
                int index         = startIndex;
                var blocks        = translator.BuildBlocks(maxTextSize, source, startIndex);
                for (int i = 0; i < blocks.Count; i++)
                {
                    var block = blocks[i];
                    using (var form = new TranslateBlock(block, string.Format(LanguageSettings.Current.GoogleTranslate.TranslateBlockXOfY, i + 1, blocks.Count), checkBoxAutoCopyToClipboard.Checked))
                    {
                        if (form.ShowDialog(this) == DialogResult.OK)
                        {
                            var result = translator.GetTranslationResult(target, form.TargetText, block);
                            FillTranslatedText(result, start, index);
                            progressBarTranslate.Refresh();
                            Application.DoEvents();
                            index += block.Paragraphs.Count;
                            start  = index;
                            progressBarTranslate.Value = Math.Min(index, progressBarTranslate.Maximum);
                        }
                        else
                        {
                            _abort = true;
                        }
                    }

                    if (_abort)
                    {
                        break;
                    }
                }
            }
            finally
            {
                progressBarTranslate.Visible = false;
                buttonTranslate.Enabled      = true;
                buttonOk.Enabled             = true;
                buttonCancel.Enabled         = true;
            }
        }
예제 #2
0
        private void buttonTranslate_Click(object sender, EventArgs e)
        {
            _abort = false;
            buttonTranslate.Enabled      = false;
            progressBarTranslate.Maximum = _subtitle.Paragraphs.Count;
            progressBarTranslate.Value   = 0;
            progressBarTranslate.Visible = true;

            try
            {
                var translator = new CopyPasteTranslator(_subtitleOriginal.Paragraphs, textBoxLineSeparator.Text);
                Translate(string.Empty, string.Empty, translator, (int)numericUpDownMaxBytes.Value);
            }
            finally
            {
                buttonTranslate.Enabled      = true;
                progressBarTranslate.Visible = false;
            }
        }
예제 #3
0
        private void SetLanguages(ComboBox comboBox, string language)
        {
            comboBox.Items.Clear();
            foreach (var pair in CopyPasteTranslator.GetTranslationPairs())
            {
                comboBox.Items.Add(pair);
            }
            int i = 0;

            foreach (var l in comboBox.Items)
            {
                if (l is TranslationPair tl && tl.Code.Equals(language, StringComparison.OrdinalIgnoreCase))
                {
                    comboBox.SelectedIndex = i;
                    return;
                }
                i++;
            }
            comboBox.SelectedIndex = 0;
        }
예제 #4
0
        private void buttonTranslate_Click(object sender, EventArgs e)
        {
            _abort = false;
            buttonTranslate.Enabled       = false;
            buttonCancelTranslate.Enabled = true;
            progressBar1.Maximum          = _subtitle.Paragraphs.Count;
            progressBar1.Value            = 0;
            progressBar1.Visible          = true;

            try
            {
                _from = ((TranslationPair)comboBoxLanguageFrom.Items[comboBoxLanguageFrom.SelectedIndex]).Code;
                _to   = ((TranslationPair)comboBoxLanguageTo.Items[comboBoxLanguageTo.SelectedIndex]).Code;
                var translator = new CopyPasteTranslator(_subtitleOriginal.Paragraphs, textBoxLineSeparator.Text);
                Translate(_from, _to, translator, (int)numericUpDownMaxBytes.Value);
            }
            finally
            {
                buttonTranslate.Enabled       = true;
                buttonCancelTranslate.Enabled = false;
                progressBar1.Visible          = false;
            }
        }