When I was reading some article, I found some other language words appeared in that article. I was fascinated to know for what language those words belong to and searched for an API to detect the language based on the content which we are providing. I found a simple API to do the job here. Follow the steps to work with this API.
- Register here to get the API key.
- Create maven project and add the below dependency to pom.xml
com.detectlanguage detectlanguage 1.0.0
Write a simple java code by using API to detect the language of context. The code is provided below.
package org.smarttechie; import java.util.List; import com.detectlanguage.DetectLanguage; import com.detectlanguage.Result; import com.detectlanguage.errors.APIError; public class LanguageDetector { /** * @param args * @throws APIError */ public static void main(String[] args) throws APIError { DetectLanguage.apiKey = "[YOUR API KEY]"; List results = DetectLanguage.detect("ಕನ್ನಡ ಲಿಪಿ"); Result result = results.get(0); System.out.println("Language: " + result.language); } }
Once you run the above code, it will detect the language code as “KN” [KANNADA].
The source code is available here.
Hi there,I checked your article named “Language Detection API”. Your writing style is nice, keep doing what you`re doing!