The simplest way to use JLangDetect is to use the UberLanguageDetector singleton, available in the jlangdetect-extra module :
import me.champeau.ld.UberLanguageDetector;
UberLanguageDetector detector = UberLanguageDetector.getInstance();
// ..
String language = detector.detectLang("ceci est un petit texte en français");
Alternatively, if you don’t need to detect russian, chinese, japanese or korean languages, you can use the EuroparlDetector available in the jlangdetect-europarl module. Note that you can still create your own language detector and register custom languages using the core module.
Keep in mind that this package requires SLF4J to be referenced.
JLangDetect is now available on Maven Central.
Then use the following dependency :
<dependency>
<groupId>me.champeau.jlangdetect</groupId>
<artifactId>jlangdetect-extra</artifactId>
<version>0.6</version>
</dependency>
or with Gradle:
dependencies {
implementation("me.champeau.jlangdetect:jlangdetect:0.6")
}
As a last integration example, here is how to use it from Groovy, through a simple script :
@Grab('me.champeau.jlangdetect:jlangdetect-extra:0.6')
import me.champeau.ld.UberLanguageDetector as ULD
ULD.instance.with {
assert detectLang('ceci est un petit texte en français') == 'fr'
assert detectLang('this is a text in english') == 'en'
}