コード例 #1
0
ファイル: Form1.cs プロジェクト: monotwist/yandex-translator
        private async Task Translate(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var srcFullName  = sourceLangSelector.SelectedItem.ToString();
            var destFullName = destLangSelector.SelectedItem.ToString();



            var srcLang = LanguageProvider.FindCodeByFullName(srcFullName);

            if (srcFullName == "Auto" || srcFullName == "Авто")
            {
                srcLang = await Translator.DetectLanguage(text);
            }
            var destLang = LanguageProvider.FindCodeByFullName(destFullName);

            if (srcLang == null || destLang == null)
            {
                return;
            }

            var rT = await Translator.Translate(sourceText.Text, srcLang, destLang);

            destText.Text = rT;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: monotwist/yandex-translator
        private async void InitVariables()
        {
            ApiSettings.ApiKey = "trnsl.1.1.20180720T045104Z.3b603be702905c49.b19db5e51d21fcc36424800c088a9819a376f447"; //ну я хуй знает, в шарпе все равно не спрячешь
            var uiLang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName.ToString();

            translateButton.Text     = uiLang == "ru" ? "Перевести" : "Translate";
            liveTranslateSwitch.Text = uiLang == "ru" ? liveTranslateSwitch.Text : "\"Live\" translate";
            var langs = await LanguageProvider.GetLanguages(uiLang);

            var langFullNames = langs.Values.ToList();

            langFullNames.Sort();
            destLangSelector.Items.AddRange(langFullNames.ToArray());
            langFullNames.Insert(0, uiLang == "ru" ? "Авто" : "Auto");
            sourceLangSelector.Items.AddRange(langFullNames.ToArray());
            sourceLangSelector.SelectedIndex = 0;
            destLangSelector.SelectedIndex   = 0;
            translateButton.Enabled          = true;
        }