0

I find YandexTranslator in here : https://github.com/prokhor-ozornin/Yandex.NET.Translator

I installed YandexTranslator via Nuget

This iy my code in button translate:

IYandexTranslator translator = Yandex.Translator(api => api.ApiKey(ConfigurationManager.AppSettings["ApiKey"]).Format(ApiDataFormat.Json));
    IEnumerable<ITranslationPair> translationPairs = translator.TranslationPairs(); //error The remote server returned an error: (403) Forbidden.
    string language = translator.Detect("This is English text");
    ITranslation translation = translator.Translate("ru", "To be translated to Russian");

But when I try to run so get error : "The remote server returned an error: (403) Forbidden."

I have just begun with interface Everybody can help fix it !!

  • Invalid authentication data specified in the request, or access to the requested resource is forbidden. Check to make sure you have the correct ApiKey being passed, and that API key has access to that resource. (I would download postman for chrome, and run the request manually, to ensure it's working correctly) – Blue Mar 21 '17 at 05:44
  • I add apikey correctly in appSetting – Releases Download Mar 21 '17 at 05:51

1 Answers1

0

The code that given by this package github page is wrong. Yandex.Translator is a namespace and you can not create an instance from a namespace.

So after installing Yandex.Translator package on Nuget, use my code below which works well.

string apiKey = "YourApiKey";

IYandexTranslator translator = Yandex.Translator.Yandex.Translator(api =>
                         api.ApiKey(apiKey).Format(ApiDataFormat.Json));

var translate = _translator.Translate("en-es", "Translate this text to Spanish!");
string result = translate.Text;  // Traducir este texto a Español!
agenc
  • 322
  • 4
  • 10