Exemplo n.º 1
0
        /// <summary>
        /// Handles "Translate resources" command from Solution Explorer's context menu.
        /// </summary>
        private void TranslateSolExpClick(object sender, EventArgs args)
        {
            try {
                if (OperationInProgress)
                {
                    throw new Exception("Cannot start operation 'Global translate', because another operation is in progress.");
                }
                OperationInProgress = true;

                globalTranslateCommand.Process((Array)VisualLocalizerPackage.Instance.UIHierarchy.SelectedItems);
            } catch (Exception ex) {
                if (OperationInProgress)
                {
                    VLDocumentViewsManager.ReleaseLocks();
                }

                Dictionary <string, string> add = null;
                if (ex is CannotParseResponseException)
                {
                    CannotParseResponseException cpex = ex as CannotParseResponseException;
                    add = new Dictionary <string, string>();
                    add.Add("Full response:", cpex.FullResponse);
                }

                VLOutputWindow.VisualLocalizerPane.WriteException(ex, add);
                MessageBox.ShowException(ex, add);
                OperationInProgress = false;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Translate selected rows
        /// </summary>
        /// <param name="provider">Translation provider to handle the process</param>
        /// <param name="from">Source language (can be null)</param>
        /// <param name="to">Target language</param>
        private void EditorControl_TranslateRequested(TRANSLATE_PROVIDER provider, string from, string to)
        {
            try {
                List <AbstractTranslateInfoItem> data = new List <AbstractTranslateInfoItem>();
                AddToTranslationList(SelectedRows, data); // collect data to translate

                TranslationHandler.Translate(data, provider, from, to);

                foreach (AbstractTranslateInfoItem item in data)
                {
                    item.ApplyTranslation(); // modify the editor's data
                }
            } catch (Exception ex) {
                Dictionary <string, string> add = null;
                if (ex is CannotParseResponseException)
                {
                    CannotParseResponseException cpex = ex as CannotParseResponseException;
                    add = new Dictionary <string, string>();
                    add.Add("Full response:", cpex.FullResponse);
                }

                VLOutputWindow.VisualLocalizerPane.WriteException(ex, add);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex, add);
            }
        }