syntaxas / laravel-lang-checker
Laravel package for checking language files and translations.
Requires
- php: ^8.2
- illuminate/contracts: ^11.0||^12.0||^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^11.0.0||^10.0.0||^9.0.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-arch: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
README
Laravel Lang Checker is a package for checking language files and translations in Laravel applications. It helps ensure that your translations are complete and consistent across different languages.
Requirements
- PHP 8.2, 8.3, 8.4, or 8.5
- Laravel 11, 12, or 13
Installation
You can install the package via composer:
composer require syntaxas/laravel-lang-checker
Usage
php artisan laravel-language:check
What It Checks
The command scans all locale directories under your lang/ path and runs the following checks:
| Check | Outcome |
|---|---|
lang/ directory does not exist |
❌ Fails |
| No locale subdirectories found | ⚠️ Warning, passes |
| A translation file exists in some locales but not all | ❌ Fails |
| A translation key exists in some locales but not all | ❌ Fails |
| A key is an array in one locale but a scalar value in another | ❌ Fails |
| A translation file does not return an array | ❌ Fails |
| A translation value is an empty string | ⚠️ Warning, passes |
Checks work recursively — files in subdirectories (e.g. /lang/lt/admin/dashboard.php) are included.
When the command fails, it reports the total number of issues found:
[ERROR] Language files check failed with 3 issue(s).
When everything is consistent:
[OK] Language files are consistent across all locales.
Examples
Missing translation key
lang/en/messages.php
return [ 'welcome' => 'Welcome', 'goodbye' => 'Goodbye', // present in EN ];
lang/lt/messages.php
return [ 'welcome' => 'Sveiki', // 'goodbye' is missing ];
[ERROR] LT locale missing goodbye translation in messages.php
Missing file
lang/en/auth.php — exists
lang/lt/auth.php — missing
[ERROR] Missing file for locale LT: auth.php
Type mismatch
lang/en/messages.php
return [ 'nav' => [ 'home' => 'Home', 'about' => 'About', ], ];
lang/lt/messages.php
return [ 'nav' => 'Navigacija', // scalar instead of array ];
[ERROR] Type mismatch for key nav in messages.php (EN=array, LT=value)
Empty translation
lang/en/messages.php
return [ 'welcome' => '', // empty string ];
[WARNING] Empty translation in messages.php (EN): welcome
All correct
lang/en/messages.php
return [ 'welcome' => 'Welcome', 'goodbye' => 'Goodbye', ];
lang/lt/messages.php
return [ 'welcome' => 'Sveiki', 'goodbye' => 'Viso gero', ];
[OK] Language files are consistent across all locales.
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.