flutter_langdetect

A Flutter package for language detection, ported from the Python langdetect library.

Features

  • Detects 55 languages
  • Lightweight and fast

Languages

flutter_langdetect supports 55 languages out of the box (ISO 639-1 codes):

af, ar, bg, bn, ca, cs, cy, da, de, el, en, es, et, fa, fi, fr, gu, he,
hi, hr, hu, id, it, ja, kn, ko, lt, lv, mk, ml, mr, ne, nl, no, pa, pl,
pt, ro, ru, sk, sl, so, sq, sv, sw, ta, te, th, tl, tr, uk, ur, vi, zh-cn, zh-tw

Installation

Add flutter_langdetect to your pubspec.yaml dependencies:

dependencies:
  flutter_langdetect: ^0.0.1

Then, run flutter pub get to download and install the package.

Usage

import 'package:flutter/widgets.dart';

// recommend to import 'as langdetect' because this package shows a simple function name 'detect'
import 'package:flutter_langdetect/flutter_langdetect.dart' as langdetect;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await langdetect.initLangDetect();  // This is needed once in your application after ensureInitialized()

  String text = 'Hello, world!';
  final language = langdetect.detect(text);
  print('Detected language: $language'); // -> "en"

  final probs = langdetect.detectLangs(text);
  for (final p in probs) {
    print("Language: ${p.lang}");  // -> "en"
    print("Probability: ${p.prob}");  // -> 0.9999964132193504
  }
}

History

The flutter_langdetect package is inspired by the Python library langdetect created by Mimino666.

In turn, the Python langdetect library is a port of Nakatani Shuyo's language-detection library, which is written in Java.

Both of these projects have contributed significantly to the field of natural language processing and have enabled developers to easily integrate language detection capabilities into their applications.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.

License

This package is licensed under the Apache 2.0 License.

Libraries

utils/profiles/all_language_profiles
detector
detector_factory
flutter_langdetect
utils/profiles/profiles_data/lang_af
utils/profiles/profiles_data/lang_ar
utils/profiles/profiles_data/lang_bg
utils/profiles/profiles_data/lang_bn
utils/profiles/profiles_data/lang_ca
utils/profiles/profiles_data/lang_cs
utils/profiles/profiles_data/lang_cy
utils/profiles/profiles_data/lang_da
utils/profiles/profiles_data/lang_de
lang_detect_exception
utils/profiles/profiles_data/lang_el
utils/profiles/profiles_data/lang_en
utils/profiles/profiles_data/lang_es
utils/profiles/profiles_data/lang_et
utils/profiles/profiles_data/lang_fa
utils/profiles/profiles_data/lang_fi
utils/profiles/profiles_data/lang_fr
utils/profiles/profiles_data/lang_gu
utils/profiles/profiles_data/lang_he
utils/profiles/profiles_data/lang_hi
utils/profiles/profiles_data/lang_hr
utils/profiles/profiles_data/lang_hu
utils/profiles/profiles_data/lang_id
utils/profiles/profiles_data/lang_it
utils/profiles/profiles_data/lang_ja
utils/profiles/profiles_data/lang_kn
utils/profiles/profiles_data/lang_ko
utils/profiles/profiles_data/lang_lt
utils/profiles/profiles_data/lang_lv
utils/profiles/profiles_data/lang_mk
utils/profiles/profiles_data/lang_ml
utils/profiles/profiles_data/lang_mr
utils/profiles/profiles_data/lang_ne
utils/profiles/profiles_data/lang_nl
utils/profiles/profiles_data/lang_no
utils/profiles/profiles_data/lang_pa
utils/profiles/profiles_data/lang_pl
utils/lang_profile
utils/profiles/profiles_data/lang_pt
utils/profiles/profiles_data/lang_ro
utils/profiles/profiles_data/lang_ru
utils/profiles/profiles_data/lang_sk
utils/profiles/profiles_data/lang_sl
utils/profiles/profiles_data/lang_so
utils/profiles/profiles_data/lang_sq
utils/profiles/profiles_data/lang_sv
utils/profiles/profiles_data/lang_sw
utils/profiles/profiles_data/lang_ta
utils/profiles/profiles_data/lang_te
utils/profiles/profiles_data/lang_th
utils/profiles/profiles_data/lang_tl
utils/profiles/profiles_data/lang_tr
utils/profiles/profiles_data/lang_uk
utils/profiles/profiles_data/lang_ur
utils/profiles/profiles_data/lang_vi
utils/profiles/profiles_data/lang_zhcn
utils/profiles/profiles_data/lang_zhtw
language
utils/profiles/language_data
utils/ngram
utils/ngram_data
utils/unicode_block