Esempio n. 1
0
        public MainForm(Subtitle sub, string title, string description, Form parentForm)
            : this()
        {
            Text              = title;
            _subtitle         = sub;
            _subtitleOriginal = new Subtitle(sub);
            foreach (var p in sub.Paragraphs)
            {
                p.Text = string.Empty;
            }

            _from = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitleOriginal);
            SetLanguages(comboBoxLanguageFrom, _from);
            GeneratePreview();
            RestoreSettings();
            var languages = BaiduTranslator.GetTranslationPairs().Select(p => p.Code).ToList();

            if (string.IsNullOrEmpty(_to) || _to == _from)
            {
                _to = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
                if (_to == _from)
                {
                    foreach (InputLanguage language in InputLanguage.InstalledInputLanguages)
                    {
                        if (languages.Contains(language.Culture.TwoLetterISOLanguageName))
                        {
                            _to = language.Culture.TwoLetterISOLanguageName;
                            if (_to != _from)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            if (_to == _from && _from == "en")
            {
                _to = "de";
            }
            if (_to == _from && _from == "es")
            {
                _to = "de";
            }
            SetLanguages(comboBoxLanguageTo, _to);
        }
Esempio n. 2
0
        private void SetLanguages(ComboBox comboBox, string language)
        {
            comboBox.Items.Clear();
            foreach (var pair in BaiduTranslator.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;
        }