π§ Language Detector (Python)
A simple yet enhanced Python tool that automatically detects the language of any text using the langdetect library. You can input a single text or scan an entire file β the program will identify each language detected!
β¨ Features
β Detects over 55+ languages β Supports single text or file input β Can export results to JSON or CSV β Command-line interface with flexible arguments β Lightweight, fast, and beginner-friendly β Built entirely with pure Python
βοΈ Installation
Install the required dependency:
pip install langdetect
Clone this repository (if you havenβt yet):
git clone https://github.com/Coder-dev2006/language-detection.git cd language-detection
π Usage π§Ύ Option 1: Single text detection
Run from terminal:
python main.py -t "Bonjour tout le monde"
Output:
Detected: fr / French β top: fr(0.9999)
π Option 2: Detect languages in a text file
Create a file named texts.txt:
Hello world ΠΡΠΈΠ²Π΅Ρ ΠΌΠΈΡ Salom dunyo Hola mundo
Then run:
python main.py -f texts.txt --csv results.csv
Output example:
Detected 4 lines, exported to results.csv β
π οΈ Command-line arguments Argument Description Example -t, --text Analyze a single text string -t "Hello world" -f, --file Analyze a file with multiple lines -f texts.txt --json Save detection results in JSON format --json result.json --csv Save detection results in CSV format --csv result.csv --top Show top N detected languages --top 3 -v Verbose mode (debug info) -v π Project Structure language-detection/ β βββ main.py βββ README.md βββ requirements.txt # optional βββ texts.txt # sample input
β‘ How It Works
Imports the detect() function from the langdetect library.
Takes either user input or file input.
Detects the dominant language(s).
Displays results or saves them in JSON/CSV.
π Common Language Codes Code Language Code Language en English fr French uz Uzbek ru Russian de German es Spanish ar Arabic ja Japanese zh Chinese it Italian π§© Future Improvements
β Add translation feature (via googletrans)
β Add GUI (Tkinter) interface for easy use
β Support batch file processing
β Improve accuracy metrics and confidence score output
π€ Contributing
Want to add new features?
Fork this repository
Create a new branch
git checkout -b feature/my-feature
Commit your changes
git commit -m "Add: new detection improvement"
Push and create a Pull Request π
π¨βπ» Author
Developed with β€οΈ by Coder-dev2006
Simple yet powerful example of natural language detection in Python.
π License
This project is licensed under the MIT License β free for personal and educational use!!!