using LanguageDetection;
LanguageDetector ld = new LanguageDetector();
ld.AddAllLanguages();
string dasdfas = "????????";
string lanCode = ld.Detect(dasdfas);
// string languageNaturalName = ld.Detect(lanCode); //returns "English" for language code "en"
Console.WriteLine(lanCode);
Console.ReadLine();
Iam using this code but it shows only english language

Jithu ThomasRank #437 · 5.7K reputationPosted Jan 31, 2024, 2:32 AM EST
To improve the accuracy of language detection, you should use a more representative text that includes actual words and phrases from the language you want to detect. For example:
LanguageDetector ld = new LanguageDetector(); ld.AddAllLanguages(); string sampleText = "This is a sample text in English."; string lanCode = ld.Detect(sampleText); Console.WriteLine(lanCode); Console.ReadLine();Replace the
sampleTextwith a more typical text for the languages you are interested in detecting. This should yield more accurate results. Keep in mind that no language detection library is perfect, and the accuracy may vary depending on the quality and length of the input text.Srikanth Vankayalapati25 reputationPosted Jan 31, 2024, 3:08 AM EST
Hi Jithu Thomas,
Thanks for your reply.
When i have give text like hindi, chinies, japanies text its shows null result.
Thanks
Srikanth
Sri29 reputationPosted Jan 31, 2024, 10:32 AM EST
HI Srikanth,
i tried your code,tested with 2 languages.it is working and returning relative language code (used LanguageDetection.NETStandard lib)
using LanguageDetection;
LanguageDetector ld = new LanguageDetector();
ld.AddAllLanguages();
string dasdfas = "???? ??? ???? ??";
string lanCode = ld.Detect(dasdfas);
Console.WriteLine(lanCode);//output : hin
Console.ReadLine();
Sachin SinghRank #66 · 26.2K reputationPosted Feb 1, 2024, 1:43 AM EST
using System; using Zemberek.LanguageDetection; class Program { static void Main() { LanguageDetector detector = LanguageDetectorBuilder.FromAllBuiltInLanguages().Build(); string text = "?? ??????? ?????? ??"; var detectionResult = detector.Detect(text); if (detectionResult.IsReliable) { Console.WriteLine($"Detected Language: {detectionResult.Language}"); } else { Console.WriteLine("Language detection not reliable."); } Console.ReadLine(); } }Tuhin PaulRank #7 · 71.9K reputationPosted Feb 2, 2024, 9:26 AM EST
1. Check Language Support:
Check that the library you're using supports the languages you are testing. Some libraries may have limited language support.
2. Check Text Input:
Make sure that the input text (dasdfas in your case) contains a sufficient amount of text for accurate language detection. Very short or ambiguous text might lead to less accurate results.
3. Library Configuration:
Check if the library has any configuration options that you can adjust. Some libraries may have settings related to language models or confidence thresholds.
4.Review Documentation:
Read the documentation of the LanguageDetection library to see if there are any specific guidelines or recommendations for usage.
5.Explore Alternative Libraries:
If you continue to face issues, you might want to explore alternative language detection libraries. Libraries like LangDetectSharp, TextCat, or CLD2 are commonly used for language detection.
using System; using NTextCat; class Program { static void Main() { var factory = new RankedLanguageIdentifierFactory(); var identifier = factory.Load("Core14.profile.xml"); string inputText = "????????"; var languages = identifier.Identify(inputText); var mostCertainLanguage = languages.FirstOrDefault(); if (mostCertainLanguage != null) { Console.WriteLine($"Detected Language: {mostCertainLanguage.Item1.Iso639_3}"); } else { Console.WriteLine("Language not detected."); } Console.ReadLine(); } }Jithu ThomasRank #437 · 5.7K reputationPosted Jan 31, 2024, 12:44 PM EST
Hi,
Please follow this code and it is working: -
using LanguageDetection; LanguageDetector ld = new LanguageDetector(); ld.AddAllLanguages(); string englishText = "This is a sample text in English."; string hindiText = "?? ????? ??? ?? ????? ??? ???"; string chineseText = "??????????"; string japaneseText = "??????????????????"; string englishLanguageCode = ld.Detect(englishText); string hindiLanguageCode = ld.Detect(hindiText); string chineseLanguageCode = ld.Detect(chineseText); string japaneseLanguageCode = ld.Detect(japaneseText); Console.WriteLine("English: " + englishLanguageCode); Console.WriteLine("Hindi: " + hindiLanguageCode); Console.WriteLine("Chinese: " + chineseLanguageCode); Console.WriteLine("Japanese: " + japaneseLanguageCode); Console.ReadLine();Output: -
Please accept the answer if you found the same is useful!