How can I detect text language with flutter

1,139

Solution 1

I had a small search in pub.dev to check if there is any new lib to do this, but I didn't find it.

However, I recommend you use google API which receives the text and returns the language type.

You can check it in: google-detecting-language

A sample from the website you can check: body POST:

{
  "q": "Mi comida favorita es una enchilada."
}

response:

{
  "data": {
    "detections": [
      [
        {
          "confidence": 1,
          "isReliable": false,
          "language": "es"
        }
      ]
    ]
  }
}

Solution 2

I found another way to detect language code; You need to use this package. I leave a simple code example below;

Translation translation = await translator.translate("Example Text");
lanCode = translation.sourceLanguage.code;
print("Language Code: $lanCode");
Share:
1,139
MuhammedYesilmen
Author by

MuhammedYesilmen

Updated on December 31, 2022

Comments

  • MuhammedYesilmen
    MuhammedYesilmen over 1 year

    I need a package that detects and returns the text language. Do you have a flutter package recommendation for this? If you know of any other method besides the packages, I'd be happy to hear it.

  • Raphael Souza
    Raphael Souza over 2 years
    Another REST API you could use is: detectlanguage.com
  • MuhammedYesilmen
    MuhammedYesilmen over 2 years
    Thank you very much, I can use these APIs :)