How to Detect Language of Text using NLP in Go

Cloudmersive
1 min readJul 15, 2021

--

If you don’t optimize your websites and applications for international customers, you could potentially lose out on a lot of business. One way you can position your online platforms for success in the global market is to ensure an efficient translation process is in place. The following API will employ Natural Language Processing technology to automatically detect languages for you, which will ensure the translation can be processed quickly and accurately.

To call the function of this NLP API in Go, simply input your text string into the below example code:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/nlp-v2/language/detect"
method := "POST"
payload := strings.NewReader("textToDetect=%3Cstring%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet