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.
?string for optional text).detect(null)).| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Unchanged: Combine with rule-based fallbacks (e.g., user locale or config defaults). |
| Edge Cases | Updated: Test nullable inputs (e.g., detect(null)) in PHP 8.4’s strict mode. |
| Maintenance | Low Risk: Nullable types are additive; monitor PHP 8.4-specific edge cases. |
| Thread Safety | Unchanged: Stateless design remains safe for Laravel’s request lifecycle. |
| Type Safety | New: Nullable types catch runtime errors (e.g., null inputs) earlier. |
| Backward Compatibility | Critical: Confirm PHP 8.3 behavior (nullable types ignored) doesn’t break existing logic. |
null inputs (e.g., return null or default locale).null results to avoid redundant processing of invalid inputs.$this->app->singleton(LanguageDetector::class, function () {
return new \Patrickschur\LanguageDetection\Detector(); // Now supports `detect(?string $text): ?string`
});
LanguageDetector::detect($text) → ?string).public function handle(Request $request, Closure $next): Response {
$text = $request->input('content'); // May be null
$language = LanguageDetector::detect($text); // Handles null gracefully
return $next($request);
}
language: ?string).null inputs (e.g., return null or default locale).ENUM or JSON.composer require patrickschur/language-detection:^5.3.php artisan vendor:publish --tag=language-detection-config.public function detect(?string $text): ?string { ... }
null inputs (e.g., detect(null)).?string).detected_language: null for failures).null input volumes or PHP version mismatches.null input scenarios in PHP 8.3 (where types may be ignored).var_dump() to inspect nullable inputs (e.g., $text = null).null results may indicate invalid input or unsupported languages.null for invalid inputs) to avoid redundant processing.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| High Ambiguity Rates | Poor UX | Confidence thresholds + fallback. |
| Algorithm Drift | Accuracy degrades | Quarterly retesting. |
| Nullable Input Handling | New: null inputs crash logic in PHP 8.3 |
Validate inputs early; return null gracefully. |
| PHP 8.3 Nullable Ignore | Silent failures in PHP 8.3 | Add runtime checks for null inputs. |
| Type Errors in PHP 8.4 | Breaks custom code | Audit service bindings for ?string compliance. |
How can I help you explore Laravel packages today?