Download the PHP package zeerats/laravel-lang-lint without Composer
On this page you can find all versions of the php package zeerats/laravel-lang-lint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zeerats/laravel-lang-lint
More information about zeerats/laravel-lang-lint
Files in zeerats/laravel-lang-lint
Package laravel-lang-lint
Short Description Artisan commands that lint Laravel language files: missing keys, unused keys and consistent formatting.
License MIT
Homepage https://github.com/zeerats/laravel-lang-lint
Informations about the package laravel-lang-lint
Laravel Lang Lint
Artisan commands that keep PHP language files in sync with the code that uses them.
| Command | What it does | Exit status |
|---|---|---|
lang:check |
Reports keys used in the source code that a language file does not define. | 1 when keys are missing |
lang:unused |
Reports keys in the language files that no code uses. --prune removes them. |
1 when keys are unused and not pruned |
lang:format |
Rewrites language files with sorted keys in one consistent style. --check only verifies. |
1 when --check finds unformatted files |
The commands never prompt. Files change only when you pass --prune or run lang:format without --check, so the commands are safe in git hooks, CI pipelines and any other non-interactive shell.
Invalid options or configuration, such as a locale without a directory, produce a one-line error and exit status 2.
Requirements
- PHP 8.3 or newer
- Laravel 12 or 13
Installation
Publish the configuration file when the defaults do not fit your project:
Usage
Missing translations
A key is missing when at least one locale does not define it. --show-locations adds a column with the files and lines that use each key.
Unused translations
Without --prune the command lists the unused keys with the locales that define them and exits with status 1. With --prune it removes the keys and rewrites the affected files in the canonical style described below. Parents that a removal leaves empty are removed as well.
Formatting
lang:format rewrites every language file of the selected locales in one canonical style:
- keys are sorted recursively by byte value, lists keep their order
- four spaces of indentation, single-quoted strings and a trailing comma after every entry
- a blank line after
return [and before];, matching the language files Laravel ships - comments are dropped, because the file is rendered from its data
--check reports the files that would change and exits with status 1, which makes it a formatting gate for CI. --prune removes unused keys in the same pass.
Options shared by all commands
| Option | Effect |
|---|---|
--path=app --path=routes |
Scan these directories instead of the configured paths. Relative to the base path. |
--locale=en --locale=de |
Work on these locales instead of every discovered one. |
Configuration
config/lang-lint.php:
assume_used covers two situations: keys the framework reads itself, such as validation messages, and keys your code builds at runtime, such as __("statuses.{$status}"). Both are never reported as unused and never pruned. Keys that appear literally in the code are still checked for missing translations.
How keys are detected
- Every
.phpfile below the configured paths is scanned, so Blade templates are included. - A call counts when its first argument is a single string literal, such as
__('messages.welcome'), also when the call spans several lines. - Interpolated keys such as
__("messages.{$type}")and concatenated keys such as__('messages.' . $type)cannot be resolved statically and are skipped. Add a pattern toassume_usedso their targets are kept. - Namespaced keys such as
package::messages.welcomebelong to packages and are skipped. - Strings without a dot or with whitespace are JSON translation strings and are skipped. The package checks PHP language files only.
- A key used as a prefix marks everything below it as used:
__('messages.types')returns the whole array, somessages.types.imagecounts as used. - Detection is textual. A call inside a comment counts as a usage, and a call made through a variable function name does not.
Continuous integration
GitLab CI:
GitHub Actions:
A pre-commit hook can run the same two commands.
Development
This runs PHPStan, Pint, Pest's type coverage and the test suite.
Changelog
See CHANGELOG.md.
License
MIT, see LICENSE.md.
All versions of laravel-lang-lint with dependencies
illuminate/collections Version ^12.0||^13.0
illuminate/console Version ^12.0||^13.0
illuminate/contracts Version ^12.0||^13.0
illuminate/support Version ^12.0||^13.0
symfony/finder Version ^7.2||^8.0