edulazaro/laratext
Laratext manages and auto-translates Laravel text strings by using both key and text for readable, stable translations. Includes @text directive and text() helper, scans/updates language files, and supports OpenAI, Google Translate, and more.
Laratext 2.0 changes how laratext:scan keeps your translation files aligned with your source code. Drift between code and translation JSONs is now handled automatically by default, plus a new --prune flag cleans up orphan keys, and Anthropic's Claude joins OpenAI and Google as a built-in translator.
Default scan behaviour now retranslates drifted keys
Before 2.0, running laratext:scan --write only translated brand-new keys. If you edited the source text of an existing key in your code, the translation files were left silently out of sync until you remembered to pass --resync.
In 2.0, the default scan also retranslates any key whose source text in code no longer matches the value stored in lang/{defaultLocale}.json. The drifted source and target translations are regenerated together, so your lang files stay aligned with the codebase without extra flags.
If you preferred the conservative behaviour, pass the new --only-missing flag (see below).
--resync now retranslates everything
--resync previously meant "retranslate keys whose source text drifted". That role is now the default, so --resync was repurposed: it now retranslates every key in your codebase from scratch, ignoring the existing translation files.
This is intended for one-off full regenerations, for example after switching translator providers or upgrading the underlying model. Expect it to be expensive in tokens.
New features
--only-missing flag translates only brand-new keys, leaving drifted keys untouched. Drift is still detected and printed as a warning showing the old vs. new source text, so you know what would be retranslated, but no API calls are made for drifted keys. Restores the pre-2.0 default behaviour for teams that want it.
php artisan laratext:scan --write --only-missing
--prune flag detects keys present in lang/{locale}.json files but no longer referenced anywhere in code (left over from removed text() or [@text](https://github.com/text) calls). By default it only lists them; combined with --write, it deletes them from every configured language file.
php artisan laratext:scan --prune # list orphan keys only
php artisan laratext:scan --write --prune # actually delete orphan keys
A new ClaudeTranslator ships alongside the OpenAI and Google translators. It uses Anthropic's Messages API and defaults to claude-haiku-4-5 (override via the ANTHROPIC_MODEL env var). Prompt caching is enabled on the system prompt by default, so repeated batches in a single scan run reuse the cached instructions automatically.
Enable it per-run:
php artisan laratext:scan --write --translator=claude
Or set it as the project default in config/texts.php. The new config block:
'claude' => [
'api_key' => env('ANTHROPIC_API_KEY'),
'model' => env('ANTHROPIC_MODEL', 'claude-haiku-4-5'),
'timeout' => 60,
'retries' => 3,
'max_tokens' => 4096,
],
Other changes
Default OpenAI model bumped
The OpenAI translator's default model moves from the legacy gpt-3.5-turbo to gpt-5.4-nano, currently OpenAI's cheapest and fastest small model and a good fit for low-temperature JSON translation work. Override with the OPENAI_MODEL env var if you prefer a different model.
If you used laratext:scan --write in CI or automation expecting "only new keys, no drift handling", add --only-missing to keep that behaviour.
If you used --resync to fix drift, drop the flag, the default now does it.
If you want a full periodic cleanup, the modern recipe is:
php artisan laratext:scan --write --prune
Or, when changing translator or model:
php artisan laratext:scan --write --resync
Add retries to wrongly decoded values
Fix Open AI when JSON is wrapped with markdown quotes
Full Changelog: https://github.com/edulazaro/laratext/compare/1.2.3...1.2.4
Full Changelog: https://github.com/edulazaro/laratext/compare/1.2.2...1.2.3
Full Changelog: https://github.com/edulazaro/laratext/compare/1.2.1...1.2.2
translateMany method has been added to the translators. If not provided on the translators, it will perform many translate operations.Fixed automated tranlations. Texts in the /test folder are no more scanned.
Support more laravel versions
First version
How can I help you explore Laravel packages today?