Пример #1
0
        void Application_Idle(object sender, EventArgs e)
        {
            Application.Idle -= new EventHandler(Application_Idle);
            var translator = new BingTranslator("en", _requestedCulture.TwoLetterISOLanguageName);

            try
            {
                var s = translator.TranslateText(string.Format(_originalMessageTemplate, _requestedCulture.EnglishName, _requestedCulture.NativeName));
                if (!string.IsNullOrEmpty(s))
                {
                    _messageLabel.Text = s;
                    // In general, we will be able to translate OK and the title bar text iff we were able to translate
                    // the message.  This assumption saves a few processor cycles and prevents disappearing text when
                    // a language has not been localized (as is likely the case when we display this dialog).
                    _OKButton.Text = translator.TranslateText("OK");
                    Text           = translator.TranslateText(Text);
                }
            }
            catch (Exception)
            {
                //swallow
            }
        }
        /// ------------------------------------------------------------------------------------
        private void HandleTanslateItems(object sender, DoWorkEventArgs e)
        {
            var worker           = sender as BackgroundWorker;
            var nodesToTranslate = e.Argument as IDictionary <int, LocTreeNode <T> >;
            int i = 0;

            foreach (var kvp in nodesToTranslate)
            {
                var node    = kvp.Value;
                var locInfo = new LocalizingInfo(node.Id);
                locInfo.UpdateFields = UpdateFields.None;
                locInfo.LangId       = TgtLangId;

                var text = node.GetText(SrcLangId);
                if (!string.IsNullOrEmpty(text))
                {
                    text = (BingTranslator.TranslateText(text) ?? string.Empty).Trim();
                    if (text != string.Empty)
                    {
                        locInfo.Text          = text;
                        locInfo.UpdateFields |= UpdateFields.Text;
                    }
                }

                text = node.GetToolTip(SrcLangId);
                if (!string.IsNullOrEmpty(text))
                {
                    text = (BingTranslator.TranslateText(text) ?? string.Empty).Trim();
                    if (text != string.Empty)
                    {
                        locInfo.ToolTipText   = text;
                        locInfo.UpdateFields |= UpdateFields.ToolTip;
                    }
                }

                if (locInfo.UpdateFields != UpdateFields.None)
                {
                    SaveChangesInMemory(node, locInfo);
                    worker.ReportProgress(++i, kvp.Key);
                }
            }
        }