Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Language Detection

Language Detection Laravel Package

patrickschur/language-detection

Detect the language of any text in Laravel/PHP with fast, lightweight language identification. Supports multiple languages, simple API, and easy framework integration—ideal for auto-tagging content, localization workflows, and routing based on user input.

View on GitHub
Deep Wiki
Context7

A language detection library for PHP. Detects the language from a given text string.

Frequently asked questions about Language Detection
How do I install this package in a Laravel project?
Run `composer require patrickschur/language-detection` in your project root. Ensure the `mbstring` PHP extension is enabled, as it’s required for multibyte string handling. The package integrates cleanly with Laravel’s service container and facades.
Which Laravel versions does this package support?
The package works with Laravel 8+ and PHP 7.4+. For Laravel 10+ (PHP 8.4), it includes nullable type support for better IDE integration and type safety, but existing code remains fully backward-compatible.
Can I detect languages in real-time for user-submitted content?
Yes, the package is optimized for real-time detection. It processes text quickly and supports high-volume use cases like user comments or forum posts. For edge cases, combine with fallback logic (e.g., default locale or user preferences).
How accurate is the language detection for short texts or slang?
Accuracy depends on text length and language complexity. The package uses N-gram analysis and includes training data for 110 languages. For short or informal texts, pair it with rule-based fallbacks (e.g., user locale or domain-specific rules).
Does this package work with Laravel’s service container and facades?
Absolutely. Bind the detector to Laravel’s container via a service provider or use the facade (`LanguageDetector::detect($text)`). The package supports nullable types, so you can safely handle optional inputs in typed Laravel applications.
How do I handle null or empty inputs in Laravel middleware?
The package’s nullable type support (`detect(?string $text): ?string`) makes it trivial to handle null inputs in middleware. For example, `LanguageDetector::detect($request->input('content'))` will return `null` gracefully if the input is missing.
Can I customize the language model or add new languages?
Yes, the package allows training custom language models. You can extend the default 110-language dataset by providing additional text samples and regenerating the N-gram database. Check the README for training instructions.
What’s the best way to cache detection results in Laravel?
Cache results using Laravel’s cache system (e.g., `Cache::remember()`) with a key like `language_{md5($text)}`. This avoids redundant processing for repeated texts. For null inputs, cache the result to prevent redundant checks.
Are there alternatives for high-precision language detection?
For specialized use cases (e.g., code, medical text), consider dedicated libraries like `google/cloud-language` or `symfony/translation`. However, this package is ideal for general-purpose text detection with a lightweight footprint.
How do I test this package in a Laravel CI pipeline?
Test with PHPUnit by mocking the detector or using real text samples. Validate nullable inputs (e.g., `detect(null)`) and edge cases like mixed-language texts. Ensure your CI includes PHP 8.4 tests if targeting Laravel 10+.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
phalcon/cli-options-parser
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata