Esempio n. 1
0
        private void AddTranslatedTextToGrid(DataGridViewRow SourceResxGridViewRow, DataGridView ResxGridView, TranslationResult TranslatedResult,
                                             LogEvent LogEvents)
        {
            string _FromResxFilePath      = SourceResxGridViewRow.Cells["FromFileName"].Value.ToString();
            string _Directory             = Path.GetDirectoryName(_FromResxFilePath);
            string _ResxFromFileExtension = Path.GetExtension(_FromResxFilePath);
            string _ResxRootFileName      = Path.GetFileNameWithoutExtension(_FromResxFilePath);
            string _OrigLangTag           = Path.GetExtension(_ResxRootFileName);
            string _ToResxPath;

            if (!string.IsNullOrWhiteSpace(TranslatedResult.TranslateFromCultureName))
            {
                _ToResxPath = Path.ChangeExtension(_ResxRootFileName, TranslatedResult.TranslatedCultureName + _ResxFromFileExtension);
            }
            else
            {
                _ToResxPath = _ResxRootFileName + "." + TranslatedResult.TranslatedCultureName + _ResxFromFileExtension;
            }

            if (!string.IsNullOrEmpty(_Directory))
            {
                _ToResxPath = Path.Combine(_Directory, _ToResxPath);
            }

            DataGridViewRow _DataGridViewRow = new DataGridViewRow();

            _DataGridViewRow.CreateCells(ResxGridView);
            _DataGridViewRow.SetValues(new object[] { SourceResxGridViewRow.Cells["FromKey"].Value.ToString(), TranslatedResult.TranslatedString, _ToResxPath });
            ResxGridView.Rows.Add(_DataGridViewRow);
            ResxGridView.Refresh();
        }
Esempio n. 2
0
        private void Translate()
        {
            dgvTo.Rows.Clear();
            Application.DoEvents();
            Cursor.Current = Cursors.WaitCursor;

            int _FileCount = 0;

            string _FileName        = string.Empty;
            string _FromLanguage    = GetLanguageTag(cboFromLanguage);
            string _FromCultureName = GetCultureName(cboFromLanguage);

            string _ToLanguage    = GetLanguageTag(cboToLanguage);
            string _ToCultureName = GetCultureName(cboToLanguage);

            _AbortRequested = false;

            AddLogTextLine(string.Empty);
            AddLogTextLine(string.Format(Properties.Resources.TranslateingStart, cboFromLanguage.Text, _FromCultureName,
                                         cboToLanguage.Text, _ToCultureName));

            TranslationResult    _TranslationResult    = new TranslationResult();
            TranslatorTextHelper _TranslatorTextHelper = new TranslatorTextHelper(_FromLanguage, _ToLanguage, _FromCultureName);

            _TranslatorTextHelper.TranslateAPIBaseUrl      = txtTranslateAPIBaseUrl.Text;
            _TranslatorTextHelper.TranslateSubscriptionKey = txtTranslateSubscriptionKey.Text;

            _TranslatorTextHelper.BingSpellCheckUrl             = txtBingSpellCheckUrl.Text;
            _TranslatorTextHelper.BingSpellCheckSubscriptionKey = txtBingSpellCheckSubscriptionKey.Text;

            _TranslatorTextHelper.ProxyUrl      = txtProxyAddress.Text;
            _TranslatorTextHelper.ProxyUserName = txtProxyUserName.Text;
            _TranslatorTextHelper.ProxyPassword = txtProxyPassword.Text;
            _TranslatorTextHelper.ProxyUseDefaultCredentials = chkProxyUseDefaultCred.Checked;

            foreach (DataGridViewRow _DataGridViewRow in dgvFrom.Rows)
            {
                if (!_FileName.Equals(_DataGridViewRow.Cells["FromFileName"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    _FileCount += 1;
                }

                _FileName           = _DataGridViewRow.Cells["FromFileName"].Value.ToString();
                _TranslationResult += _TranslatorTextHelper.Translation(
                    _FromCultureName, _ToCultureName,
                    chkBingSpellCheck.Checked,
                    _FileCount,
                    _DataGridViewRow, dgvTo,
                    AddLogText, () => _AbortRequested);
                SetStatusText(string.Format(Properties.Resources.TranslatingLineNo, _DataGridViewRow.Index, _FileCount));
                if (_AbortRequested)
                {
                    break;
                }
            }
            btnTranslate.Text = Properties.Resources.ButtonTranslate;
            if (!_AbortRequested)
            {
                AddLogTextLine(Properties.Resources.TranslateingEnd);
            }
            else
            {
                AddLogTextLine(Properties.Resources.TranslateingIncomplete);
            }
            ClearStatusText();
        }