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.
Strengths:
resources/lang/) while introducing a more maintainable syntax (@text, text()).TranslatorInterface. Ideal for teams needing multi-provider flexibility.@text directives (for views) and text() helpers (for logic), reducing context-switching overhead.:name, :count) across translations, critical for i18n consistency.Weaknesses:
user.first_name → "First Name") assumes snake_case and may produce suboptimal translations for non-English languages (e.g., compound words like German Schulname).--resync) could strain API budgets or slow CI pipelines if misconfigured (e.g., translating 10K keys at once).laratext:scan command processes all files recursively, which may be overkill for large apps or microservices.__() or JSON-based translations.spatie/laravel-translatable.text().TranslatorInterface).--resync or frequent scans could incur unexpected charges (e.g., OpenAI’s gpt-5.4-nano costs ~$0.000005/token). Mitigation: Add budget alerts or rate-limiting middleware.--only-missing in CI and manually review warnings.translate()/translateMany(), adding dev effort. Mitigation: Start with built-in providers; extend later.hello_mate → "Hello Mate") could clash with existing keys. Mitigation: Audit keys post-scan or disable auto-generation via config.Translation Strategy:
--resync usage.gpt-5.4-nano) suffice, or do some need premium providers (e.g., Claude for long-form content)?Workflow Integration:
laratext:scan --write --only-missing (daily PR builds).laratext:scan --write --prune (weekly, with manual review).Key Management:
domain.feature.action) to improve auto-generation quality, or rely on manual overrides?__() translations migrate to text()? Tooling needed for large codebases?Fallbacks & Edge Cases:
fallback_locale in texts.php?@text('greeting', 'Hello, :name!', ['name' => '<script>alert(1)</script>]) could expose XSS.Scaling:
laratext config or shared language files.spatie/translation-manager).text() in a controller).laratext:scan to a queue for async processing) and Horizon for monitoring.LaratextServiceProvider facades for integration tests.| Phase | Action | Tools/Commands | Risk Mitigation |
|---|---|---|---|
| Assessment | Audit existing __() usage. Identify high-impact strings. |
grep -r "__(" app/ |
Prioritize critical paths (e.g., auth). |
| Pilot | Replace __() with text() in a single module (e.g., auth). |
Manual refactor + laratext:scan |
Rollback plan for translation drift. |
| Configuration | Publish texts.php, set API keys, define languages. |
php artisan vendor:publish |
Use .env placeholders for secrets. |
| Scan & Validate | Run laratext:scan --dry --diff to preview changes. |
Compare with existing lang/ files. |
Review auto-generated texts. |
| Full Migration | Replace all __() with text()/@text. |
IDE refactor (e.g., VSCode regex) | CI gate: Block PRs with __() usage. |
| Optimization | Tune scan frequency (e.g., --only-missing in CI). |
Cron job + GitHub Actions | Monitor API costs. |
| Customization | Extend with custom translators or Blade directives if needed. | php artisan make:translator |
Start with built-in providers. |
laravel-lang).texts.php).App\Providers\RouteServiceProvider to set locale dynamically.resources/lang/ and .env.composer require).vendor:publish).--dry runs.__() in CI (e.g., PHPStan rules).laratext:scan to deploy scripts.--prune runs to clean up orphan keys.config/texts.php for changes (e.g., new translators, languages). Use Laravel Envoy or Ansible to sync across environments..env management tools (e.g., Laravel Forge, Vault).How can I help you explore Laravel packages today?