COGNITIVE_SERVICE_TRANSLATE_ERROR
Have you ever seen a web page with this exact title, COGNITIVE_SERVICE_TRANSLATE_ERROR
? You are not alone!
It could be because the site uses the Optimizely Languages addon and Azure Cognitive Services to auto-translate content.
There can be several reasons for this exact error message, but let's see one way we can reproduce it.
If I use Languages and try to auto-translate to a language that is not too widely used, like Norwegian Nynorsk, I'll get a translation that contains only the error code: COGNITIVE_SERVICE_TRANSLATE_ERROR.
What about the logs?
System.Exception: Error code: 400036, The target language is not valid.
at EPiServer.Labs.LanguageManager.Business.Providers.CognitiveTranslatorProvider.Translate(String inputText, String fromLang, String toLang)
System.Net.Http.HttpClient.Default.LogicalHandler: Information: Start processing HTTP request POST https://api.cognitive.microsofttranslator.com/translate?*
System.Net.Http.HttpClient.Default.ClientHandler: Information: Sending HTTP request POST https://api.cognitive.microsofttranslator.com/translate?*
System.Net.Http.HttpClient.Default.ClientHandler: Information: Received HTTP response headers after 55.8259ms - 400
System.Net.Http.HttpClient.Default.LogicalHandler: Information: End processing HTTP request after 63.0691ms - 400
EPiServer.Labs.LanguageManager.Business.Providers.CognitiveTranslatorProvider: Error: . Cannot translate with Cognitive service, input=[input to be translated], fromLang=en, toLang=nn-NO
System.Exception: Error code: 400036, The target language is not valid.
at EPiServer.Labs.LanguageManager.Business.Providers.CognitiveTranslatorProvider.Translate(String inputText, String fromLang, String toLang)
The log message pinpoints the problem; the target language is not supported!
A lot of languages are supported, including Klingon – but Norwegian Nynorsk is not.
If you need to translate to a language not supported by Azure Translator, you can use my addon that uses OpenAI – or you can write your own translator provider.