- How does Laratext differ from Laravel’s built-in __() translation helper?
- Laratext combines the readability of inline text with the maintainability of translation keys by letting you define both (e.g., `@text('greeting', 'Hello, :name!')`). Unlike Laravel’s `__()` helper, it auto-translates missing keys via AI services while preserving placeholders like `:name`.
- Which Laravel versions does Laratext support?
- Laratext is designed for Laravel 9.x and 10.x. Check the package’s [Packagist page](https://packagist.org/packages/edulazaro/laratext) for the latest version’s compatibility notes. Always verify your Laravel version matches the package’s requirements.
- Can I use Laratext with custom translation services beyond OpenAI/Google?
- Yes, Laratext supports custom translators via the `TranslatorInterface`. Implement the interface and register it in the `config/texts.php` file under the `translators` array. This makes it extensible for private APIs or niche services.
- How do I auto-translate existing language files with AI?
- Run `php artisan laratext:scan` to identify missing translations, then use `php artisan laratext:translate` to auto-generate translations for supported languages. Configure your preferred translator (e.g., OpenAI) in `config/texts.php` first.
- What’s the best way to handle API rate limits or failures during bulk translations?
- Laratext includes retry logic configurable in `config/texts.php` (e.g., `retries` and `delay`). For production, consider queueing translations using Laravel Queues or implementing a fallback to cached translations if APIs fail.
- Will Laratext break my existing translation files if I update the package?
- Laratext is backward-compatible with Laravel’s language file structure (`resources/lang/`). However, running `php artisan laratext:resync` forces full retranslations, which may overwrite manual edits. Always back up files before major updates or use `--dry-run` to preview changes.
- How do I integrate Laratext’s translations into Blade templates?
- Use the `@text` directive (e.g., `@text('welcome', 'Welcome back, :user!')`) or the `text()` helper (e.g., `{{ text('error', 'Something went wrong') }}`). Both support placeholders and fall back to Laravel’s `__()` if the key isn’t found.
- Are there alternatives to Laratext for Laravel AI translations?
- Alternatives include `spatie/laravel-translatable` (for database-backed translations) or `laravel-lang/lang` (for static files). However, Laratext uniquely combines AI auto-translation with a hybrid key-text model, reducing manual effort while maintaining readability.
- How do I test Laratext translations in a CI/CD pipeline?
- Use `php artisan laratext:scan --test` to validate missing translations without auto-updating files. Mock AI services in tests by implementing a custom `TranslatorInterface` or using Laravel’s `MockTranslator` for isolated testing.
- What’s the cost impact of using OpenAI/Google for bulk translations?
- AI translation costs scale with usage. OpenAI’s API charges per token, while Google Translate uses pay-as-you-go pricing. Monitor usage with the provider’s dashboards and consider caching frequent translations or using free tiers for non-critical content.