Looking to hire Laravel developers? Try LaraJobs

laravel-translation-scanner maintained by nativecodein

Description
Laravel translation scanner that auto-extracts __(), trans() and t() strings from PHP, Blade, and Inertia React (JS/TS/JSX/TSX) files into resources/lang/en.json. Supports Laravel 10, 11, 12 and 13.
Author
Last update
2026/05/20 13:45 (dev-main)
License
Downloads
5

Comments
comments powered by Disqus

Laravel Translation Scanner

Latest Version on Packagist Total Downloads License: MIT

Laravel Translation Scanner is a zero-config Laravel package that scans your entire project — PHP, Blade, and Inertia React (JS / TS / JSX / TSX) files — and automatically appends every missing translation string to resources/lang/en.json.

Stop manually copy-pasting strings into your language files. Run one Artisan command and ship i18n-ready Laravel apps in seconds.

Works seamlessly with Laravel + Inertia.js + React, Blade, and pure PHP controllers. Supports Laravel 10, 11, 12, and 13.


Why Laravel Translation Scanner?

  • Automatic discovery — finds every __(), trans(), and t() call across your codebase
  • Inertia React aware — scans .js, .ts, .jsx, and .tsx files for t("..."), t(\...`), and t(variable)` usage
  • Local-variable resolution — resolves const title = "Settings"; t(title) and adds Settings
  • Non-destructive — only appends missing keys; never overwrites your existing translations
  • Sorted output — keys are alphabetically sorted in en.json for clean diffs
  • Smart exclusions — skips vendor/, node_modules/, bootstrap/, storage/, tests/, and other noise
  • Zero configuration — install and run

Installation

Install via Composer:

composer require nativecodein/laravel-translation-scanner

The service provider is auto-discovered. No further setup required.


Usage

Run the scanner from your Laravel project root:

php artisan translations:scan

The command will:

  1. Read existing resources/lang/en.json (or create it if missing).
  2. Recursively scan your project for translatable strings.
  3. Append any missing keys with the key as the default value.
  4. Save the sorted en.json back to disk.

Supported Translation Patterns

PHP / Blade

{{ __('Dashboard') }}

{{ __('Plugins') }}

return trans('Welcome Back');

Inertia React / JS / TS / JSX / TSX

t("Login");

t("Register");

t(`Dashboard`);

Local Variable Resolution

const title = "Settings";

t(title);

Example Output

After running php artisan translations:scan, your resources/lang/en.json:

{
  "Dashboard": "Dashboard",
  "Login": "Login",
  "Plugins": "Plugins",
  "Register": "Register",
  "Settings": "Settings",
  "Welcome Back": "Welcome Back"
}

Console output:

Added: Dashboard
Added: Plugins
Added: Welcome Back
Added: Login
Added: Settings
Translation scan completed.

Supported File Types

Extension Scans For
.php __('...'), trans('...')
.blade.php __('...'), trans('...')
.js t('...'), t(\...`), t(variable)`
.ts t('...'), t(\...`), t(variable)`
.jsx t('...'), t(\...`), t(variable)`
.tsx t('...'), t(\...`), t(variable)`

Excluded Folders

The scanner automatically skips these directories:

bootstrap/
config/
database/
routes/
storage/
tests/
vendor/

Supported Laravel Versions

Laravel Status
10.x Supported
11.x Supported
12.x Supported
13.x Supported

Updating

composer update nativecodein/laravel-translation-scanner

Then re-run the scan:

php artisan translations:scan

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


Security

If you discover any security-related issues, please email oss@nativecode.in instead of using the public issue tracker.


Support


License

The MIT License (MIT). Please see LICENSE for more information.

Copyright © NativeCode.