- How does Artisan Translator extract strings from Blade templates without breaking existing translations?
- The package scans `.blade.php` files for raw text wrapped in Laravel’s `__()` helper or similar patterns, then generates translation keys while preserving HTML tags, placeholders (`:name`, `{count}`), and Laravel syntax. It avoids overwriting existing translations by default, requiring explicit confirmation for new keys.
- Can I use Artisan Translator with Laravel 10? The docs say it supports 11/12.
- No, the package explicitly requires Laravel 11 or 12 due to Blade compiler changes and PHP 8.2+ dependencies. For Laravel 10, you’d need to check for forks or alternative packages like `spatie/laravel-translation-loader`, though they lack AI translation features.
- What happens if Google Gemini’s API fails or hits rate limits during translation?
- The package includes retry logic with exponential backoff for API failures. If rate limits are hit, it pauses and resumes later. For critical projects, cache translations locally (e.g., Redis) or configure a fallback to manual overrides via the `--fallback` flag in commands.
- Does Artisan Translator support custom Blade components or directives like `@component` or `@slot`?
- It primarily targets static text in Blade templates and may miss dynamic content inside custom components or `@slot` directives. For these cases, manually add translations or extend the package’s parser via service provider bindings to include additional Blade syntax patterns.
- How do I prevent Artisan Translator from removing translation keys used in JavaScript or dynamic strings?
- The cleanup feature only removes keys unused in Blade files. To protect keys used in JavaScript or dynamic contexts, either exclude them from extraction (wrap them in comments like `{{-- __('key') --}`) or configure the `--ignore-js` flag to skip JavaScript-related keys during cleanup.
- Can I integrate Artisan Translator with a translation management tool like Crowdin or Lokalise?
- Direct integration isn’t built-in, but you can export cleaned language files (`resources/lang/`) to these tools. For syncing back, use their APIs or manual imports. Avoid running both tools simultaneously on the same files to prevent conflicts, as Artisan Translator prioritizes Blade-based extraction.
- What’s the best way to run translations in CI/CD without blocking pipelines?
- Use the `--batch` flag for parallel processing and the `--queue` option to offload translations to Laravel queues (e.g., `queue:work`). For CI, cache API responses or run translations in a separate job after tests pass. Monitor API costs by setting budget alerts in Google Cloud Console.
- How does Artisan Translator handle strings with interpolated variables like `__('Welcome, :name')`?
- It preserves placeholders (`:name`, `{count}`) during extraction and translation, ensuring they remain functional in your code. The AI translation skips these markers, so the output retains the original structure. Test translations thoroughly, as Gemini may occasionally misinterpret complex placeholders.
- Are there alternatives to Artisan Translator that don’t rely on Google Gemini?
- Yes, for extraction and cleanup, consider `spatie/laravel-translation-loader` (supports Laravel 8+) or `laravel-lang/manager`. For AI translation, replace Gemini with a local service (e.g., `microsoft-translator` SDK) or manual overrides. These alternatives lack batch processing but avoid external API dependencies.
- How do I test Artisan Translator in a Laravel project before production use?
- Start with a backup of your `resources/lang/` directory. Use the `translate:extract` command in a staging environment to test extraction, then manually review generated keys. For translation testing, use the `--dry-run` flag to preview changes without modifying files. Mock the Gemini API in tests with a local HTTP client.