public void TranslationPairs_Method() { Assert.Throws <ArgumentNullException>(() => IYandexTranslatorExtensions.TranslationPairs(null)); IEnumerable <ITranslationPair> pairs; Assert.Throws <ArgumentNullException>(() => IYandexTranslatorExtensions.TranslationPairs(null, out pairs)); TestTranslationPairsResult(xmlTranslator.TranslationPairs()); Assert.True(xmlTranslator.TranslationPairs(out pairs)); TestTranslationPairsResult(pairs); TestTranslationPairsResult(jsonTranslator.TranslationPairs()); Assert.True(jsonTranslator.TranslationPairs(out pairs)); TestTranslationPairsResult(pairs); }
/// <summary> /// <para>Makes a request to Yandex.Translator web service to return collection of supported languages pairs (translations directions).</para> /// </summary> /// <param name="translator">Translator instance to be used.</param> /// <param name="pairs">Collection of supported language pairs (directions).</param> /// <returns><c>true</c> if request was successfull and <paramref name="pairs"/> output parameter contains supported language pairs, or <c>false</c> if request failed and <paramref name="pairs"/> is a <c>null</c> reference.</returns> /// <exception cref="ArgumentNullException">If <paramref name="translator"/> is a <c>null</c> reference.</exception> /// <seealso cref="http://api.yandex.ru/translate/doc/dg/reference/getLangs.xml"/> public static bool TranslationPairs(this IYandexTranslator translator, out IEnumerable <ITranslationPair> pairs) { Assertion.NotNull(translator); try { pairs = translator.TranslationPairs(); return(true); } catch { pairs = null; return(false); } }
private void btn_Translate_Click(object sender, EventArgs e) { if (txt_ShowPDF.Text == "") { if (cb_ChooseLanguage.SelectedItem == null) { MessageBox.Show("Please Open PDF, Convert and Select Language!"); } else { MessageBox.Show("Please Open PDF and Convert!"); } } else { if (cb_ChooseLanguage.SelectedItem == null) { MessageBox.Show("Select language!"); } else { /* string credential_path = @"C:\Users\user\Desktop\selinbuyurman\translate\translate\translate\translate_api.json"; * System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path); * System.Console.OutputEncoding = System.Text.Encoding.Unicode; * TranslationClient client = TranslationClient.Create(); * var response = client.TranslateText( txt_ShowPDF.Text, cb_ChooseLanguage.SelectedItem.ToString()); * System.Console.WriteLine(response.TranslatedText); */ IYandexTranslator translator = Yandex.Translator.Yandex.Translator( api => api.ApiKey("trnsl.1.1.20171205T210927Z.1672e72d24851492.692b3b66cd77d62884c5e5ab6c2f51a0befa0e17") .Format(ApiDataFormat.Json)); IEnumerable <ITranslationPair> translationPairs = translator.TranslationPairs(); ITranslation translation = translator.Translate(cb_ChooseLanguage.SelectedItem.ToString(), txt_ShowPDF.Text, "html"); txt_ShowTranslate.Text = translation.Text; } } }