This library can take a given text and detect its language using the database previously generated in the training phase.
To use this package, you need to set it up as a package dependency in Package.swift
:
let package = Package(
name: "MyPackage",
dependencies: [
.package(url: "https://github.com/Al00X/LanguageDetector.git", from: "2.0.0")
],
targets: [
.target(
name: "MyTarget",
dependencies: [
.product(name: "LanguageDetector", package: "language-detector")
]
)
]
)
You can either instantiate the class or use it statically.
let detector = LanguageDetector(languages: ["en", "it", "fr", "ar"])
// add more languages
detector.addLanguages(languages: ["es", "de"])
// detect
let result = detector.evaluate(text: "Hi there!") // [(String, Int)]
return result.first.0 // en
let result = LanguageDetector.detect(text: "I'm on static", languages: ["en", "fr", "es"]) // String
return result // en
The library currently supports 110 languages. You can see the list of the languages here.
This package is inspired by php-language-detection