pijler / lang-scanner
An application for scanning files and updating translations.
Requires
- php: ^8.3
- ext-json: *
Requires (Dev)
- illuminate/view: ^12.55
- laravel-zero/framework: ^12.1
- laravel/pint: ^1.29
- mockery/mockery: ^1.6
- nunomaduro/termwind: ^2.4
- pestphp/pest: ^4.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Lang Scanner
π Introduction
A universal translation key scanner designed for Laravel projects.
It scans your codebase for translation calls, generates/updates your JSON language files, and ensures consistency across all locales.
Although itβs a Laravel package, itβs flexible enough to scan translations from any type of project (PHP, Vue, React, etc.) by customizing the extensions and methods.
β¨ Features
- π Scans translation calls in any file type (
.php,.js,.ts,.vue,.jsx, β¦). - βοΈ Flexible configuration for methods (
__,trans,trans_choice,t,i18n.t, β¦). - π Supports multiple paths and modules.
- π§© Extensible via
extendsfor modular configs. - β
checkor--checkchecks if all language files have the same keys. - π
sortautomatically orders JSON keys globally (enabled by default). - π
--dotsaves translations in dot notation. - π«
--no-updateskips updating JSON files when runningcheck(verification only). - π
mergeor--mergecombines duplicate or related translations into a single entry. - π
--duplicatelists all duplicate translations for review. - β
--removeremoves duplicate translations, keeping only the main version, when runningduplicate. - π§Ή
--unusedlists translations that are not used in code, and--pruneremoves them. - π
--dry-runshows what would change without changing any file. - π‘οΈ Validates
scanner.jsonwith clear error messages.
π¦ Installation
composer require pijler/lang-scanner --dev
βοΈ Configuration
Create a scanner.json file at the root of your Laravel project.
Example: Laravel project:
{
"scanner": [
{
"lang_path": "lang/",
"paths": ["resources/"],
"extensions": [".php"],
"methods": ["__(*)", "trans(*)", "trans_choice(*)"]
}
]
}
Example: Vue project inside Laravel:
{
"scanner": [
{
"lang_path": "resources/lang/",
"paths": ["resources/js/"],
"extensions": [".js", ".vue"],
"methods": ["$t(*)", "i18n.t(*)"]
}
]
}
Example: React project inside Laravel:
{
"scanner": [
{
"lang_path": "resources/lang/",
"paths": ["resources/js/"],
"extensions": [".jsx", ".tsx"],
"methods": ["t(*)", "i18n.t(*)"]
}
]
}
Example: Multi-module config:
{
"extends": [
"/module1/scanner.json",
"/module2/scanner.json"
]
}
Example with check:
{
"scanner": [
{
"check": true,
"lang_path": "lang/"
}
]
}
Example with merge:
{
"scanner": [
{
"merge": true,
"lang_path": "lang/"
}
]
}
π Usage
Run the scan:
./vendor/bin/scanner
The command will:
- Parse files defined in
pathswith the configuredextensions. - Detect translation calls based on the provided
methods. - Create or update JSON files inside
lang_path.
β‘ CLI Options
--check
Checks if that all language JSON files inside lang_path have the same keys.
Reports inconsistencies when a key exists in one locale but is missing in another.
./vendor/bin/scanner --check
--sort
Sorts all JSON keys alphabetically. Enabled globally by default, can be disabled if needed:
./vendor/bin/scanner --sort=false
--dot
Saves JSON translations in dot notation:
{
"auth.failed": "These credentials do not match our records."
}
./vendor/bin/scanner --dot
--no-empty
When using check, consider empty translations as missing (not finished).
A good option to use in CI/CD pipelines.
./vendor/bin/scanner --check --no-empty
--no-update
When using check, prevents updating JSON files even if sort or dot are enabled.
Useful for CI/CD validation pipelines.
./vendor/bin/scanner --check --no-update
--merge
Ensures that all language JSON files inside lang_path have the same keys.
./vendor/bin/scanner --merge
--duplicate
Checks for and lists all duplicate records, allowing you to identify inconsistencies without modifying anything yet.
./vendor/bin/scanner --duplicate
--remove
After identifying duplicate records, automatically removes the repeated entries, keeping only the main version.
./vendor/bin/scanner --duplicate --remove
--unused
Lists the translations that exist in the JSON files but are not used in the scanned files.
The scan fails when unused translations are found, so it can be used in CI/CD pipelines.
./vendor/bin/scanner --unused
Using a key as a group (e.g. __('menu')) keeps all of its nested keys.
Keys built at runtime (e.g.
__("status.$status")) can't be detected, so they are reported as unused.
--prune
Removes the translations that are not used in the scanned files, from every language file.
./vendor/bin/scanner --prune
--unused and --prune need to scan the whole project, so they can't be combined with --dirty, --diff or paths.
Configs that share the same lang_path are checked together, so a key used only by one of them is kept.
--dry-run
Runs any mode without changing files, showing only what would change.
./vendor/bin/scanner --prune --dry-run
π‘οΈ Configuration validation
The scanner.json is validated before any file is changed.
Unknown keys, wrong types and missing options fail with a clear message:
Invalid configuration [/app/scanner.json]: unknown key [lang-path] in [scanner[0]].
The options required by each mode are:
| Mode | Required options |
|---|---|
update |
lang_path, paths, extensions, methods |
duplicate |
lang_path, methods |
check |
lang_path |
merge |
lang_path |
Each method must contain exactly one * placeholder (e.g. __(*)).
π§© Extensibility with extends
Use extends to reuse configs across modules:
{
"extends": [
"/packages/core/scanner.json",
"/packages/admin/scanner.json"
]
}
π€ Laravel Boost
Lang Scanner ships with Laravel Boost support, so AI agents know how to keep your translations in sync.
When you run boost:install or boost:update, Boost automatically loads:
- The
lang-scannerguideline, with the main rules and commands. - The
lang-scannerskill, with the fullscanner.jsonand CLI reference.
php artisan boost:install
π‘ Best practices
- Configure
methodsaccording to your framework (__(*)/trans(*)for Laravel,t(*)for Vue/React). - Always run with
checkin multi-language projects. - Keep
sortenabled for clean, ordered JSON files. - Use
--no-updatein pipelines when you want validation only. - Avoid duplicate keys, as you may forget and translate them differently.
- Centralize shared configs with
extends.
Any improvement or correction can open a PR or Issue.
π License
Open-source under the MIT license.