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:
.json files) while introducing a more maintainable key-value approach.@text directives and text() helper functions, aligning with Laravel’s templating and logic separation.user.first_name → "First Name"), reducing manual entry for boilerplate strings.:name), critical for localization accuracy.Weaknesses:
btn.submit → "Submit" vs. "Click to Submit").--only-missing mitigates this.Laravel Ecosystem Compatibility:
trans() helper but replaces it with a more robust system. No conflicts with existing translation packages (e.g., Laravel Localization) if configured as the primary method.@lang or @choice directives.Existing Workflow Impact:
__() or trans() calls with text() or @text, requiring a one-time refactor. Auto-generation reduces manual key-value mapping.laratext:scan) can be automated in pipelines to sync translations pre-deploy (e.g., on git push or PR merge).Database/Storage:
.json files (default: resources/lang/), avoiding database schema changes. Custom storage (e.g., Redis) would require extending the package.API Reliability:
gpt-5.4-nano could deprecate or change pricing.--only-missing to avoid unnecessary API calls during development.retries and timeout config.Translation Quality:
--resync sparingly; manually review critical translations.TranslatorInterface to add pre/post-processing (e.g., regex fixes).Performance:
translateMany) may time out for large projects or slow APIs (e.g., Claude’s max_tokens limit).vendor/ or node_modules/).gpt-4o-mini) for non-critical text.Key Collisions:
pages.home.title) might clash with existing keys or each other if not namespaced carefully.feature.x.y for modular apps).--diff to preview changes before --write.Translation Strategy:
Cost Management:
gpt-5.4-nano costs ~$0.000005/token.)Workflow Integration:
@text strings directly)?Fallbacks:
Scalability:
Compliance:
Laravel Core:
Translation Layer:
trans() but provides a more structured key-value system. Can coexist if configured to use the same .json files.@text directive integrates seamlessly with Laravel’s Blade compiler.AI/External Services:
TranslatorInterface. Ideal for teams already using these services..env and config/texts.php, aligning with Laravel’s 12-factor principles.Database:
.json), avoiding database migrations. Custom storage (e.g., Redis) would require extending the package’s TranslationRepository.Assessment Phase:
.php/.json files) for compatibility with the key-value model.Pilot Migration:
auth or dashboard) to test:
__('messages.welcome') with text('auth.welcome').@text in Blade views.config/texts.php with supported languages and default translator.Incremental Rollout:
__() calls with text() in controllers/services.@text.php artisan laratext:scan --write to auto-generate missing keys.--only-missing → full sync as confidence grows).CI/CD Integration:
php artisan laratext:scan --write --only-missing
--prune to clean up orphan keys.Fallback Strategy:
FallbackTranslator) that returns cached or placeholder values if the primary API fails.Laravel Versions:
Existing Packages:
spatie/laravel-translation-loader) may duplicate functionality. Choose one primary system.@text.Laratext.Customizations:
make:translator).TranslationRepository for non-file storage.How can I help you explore Laravel packages today?