[go: up one dir, main page]

Skip to content

Al00X/LanguageDetector

Repository files navigation

Language Detector

Version License

Detect languages of any given text with high accuracy!

This library can take a given text and detect its language using the database previously generated in the training phase.


Installation

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")
      ]
    )
  ]
)

Usage

You can either instantiate the class or use it statically.

Instance Use

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

Static Use

let result = LanguageDetector.detect(text: "I'm on static", languages: ["en", "fr", "es"]) // String

return result // en

Supported languages

The library currently supports 110 languages. You can see the list of the languages here.



This package is inspired by php-language-detection