Error with language code

83 views
Skip to first unread message

Frank Toyota

unread,
Jul 21, 2021, 3:32:21 PM7/21/21
to Google Cloud Translation API
Hey.
I'm trying to use the TranslationServiceClient to detect some languages in my .NET application.
It works fine, but the response I'm getting back is not in BCP-47 language code as it states in the documentation.

This is my code:
            var client = TranslationServiceClient.Create();

            var request = new DetectLanguageRequest
            {
                Content = fullText,
                Parent = new ProjectName("language-detection-308612").ToString(),
                MimeType = "text/plain"
            };

            var detectedLanguageResponse = client.DetectLanguage(request)
                .Languages
                .FirstOrDefault();

            Utilities.LogController.WriteToConsole("fulltext: ", fullText);

            Utilities.LogController.WriteToConsole("response: ", detectedLanguageResponse);

            if (detectedLanguageResponse == null)
            {
                return null;
            }

            if (detectedLanguageResponse.Confidence >= 0.95)
            {
                return detectedLanguageResponse.LanguageCode;
            }

And this is my console output:
21-07-2021 17:12:39.574 fulltext:  GOTHENBURGSWEDEN We got the information from Germanintelligence and took the first flight. A person on the watch list is arrivingin Gothenburg from Germany via Denmark. I wanted to be present at the arrest, sothey're holding the ferry's passengers. -Erik Nolander, Customs.-Hi. -Is this your doing?-Eva Forsberg, Security Service. I understand we're looking fora truck with German plates, LCL4268. I've told everyonethat this is a random check. -Go ahead.-All right, start letting them out. There it is. -Hello.-Hi. Thank you. -From Germany?-Yeah. They listed the cargo asspare parts for agricultural equipment. That seems correct.Shall I start the search? -How far am I from the cabin?-Hang on. There's a metre missing. -Can we get a blowtorch?-Sure. One moment. Can you send.? Police! Stop! Stop or I'll shoot! Request police assistance!Seal off the port area! -Now!-Go and get the first-aid box. We need help! Send back-up to port area D.Two people have been shot. Breathe slowly, please. Breathe slowly. I need assistance here! Damn it! Damn it! Dad will be here soon, sweetie pie.

21-07-2021 17:12:39.578 response:  {
  "LanguageCode": "en",
  "Confidence": 1.0
}

The languageCode should be en-GB, but it's not.
Can someone help me?

Kind regards

Jun (Cloud Platform Support)

unread,
Aug 3, 2021, 6:13:53 PM8/3/21
to Google Cloud Translation API
Hey Oliver, 

Can you share the documentation that you're referring to "but the response I'm getting back is not in BCP-47 language code as it states in the documentation."? As well as the documentation that you've followed while encountering error with language code?

In the meanwhile, please notice that Google Groups are reserved for general product discussion, StackOverflow for technical questions whereas Issue Tracker is for product bugs (unexpected behaviors) and feature requests. 

To get a better support you should post to the relevant forum, thus please read the Community Support article for better understanding. 

Frank Toyota

unread,
Aug 4, 2021, 10:59:13 AM8/4/21
to Google Cloud Translation API
Hey :) All right, I wasn't aware of that.
If you look under LanguageCode on this site, it states that it's a BCP-47 language code that should be returned.

Reply all
Reply to author
Forward
0 new messages