- Can I use this package with Laravel’s native Blade templating?
- No, this package is specifically designed for Twig templates. If your Laravel app uses Blade, stick with Laravel’s built-in `@lang` directives or `Lang::get()` methods. For mixed environments, isolate Twig functions to avoid conflicts.
- How do I install and configure this extension in a Laravel project?
- First, install via Composer: `composer require phpmyadmin/twig-i18n-extension`. Then, register the extension in your Twig environment (e.g., via `spatie/twig-laravel`) by adding `TwigI18nExtension::class` to your Twig extensions array in `config/twig.php`. Ensure your translation files (`.po` or `.json`) align with Twig’s syntax.
- Does this package support dynamic language switching like Laravel’s `App::setLocale()`?
- Yes, but you’ll need an adapter layer to sync Laravel’s locale with Twig. Create a service class (e.g., `TwigI18nAdapter`) that bridges `App::getLocale()` with the Twig extension’s locale settings. This ensures real-time updates when users switch languages.
- What Laravel versions are compatible with this package?
- This package has no hard Laravel version dependency, but it requires PHP 7.4+ and Twig 2.x+. Test compatibility with your Laravel version (e.g., 8.x, 9.x, or 10.x) by checking the `spatie/twig-laravel` package’s requirements, as it’s often used as a bridge for Twig in Laravel.
- Will this package work with Laravel’s JSON translation files (e.g., `resources/lang/en/json`)?
- No, this package relies on gettext’s `.po`/`.mo` files or Twig-compatible JSON structures. You’ll need to migrate or adapt your Laravel JSON files to match Twig’s expected format (e.g., `{{ 'message'|trans }}`). Consider writing a custom loader to bridge the gap if needed.
- Are there performance concerns when using this extension in production?
- The extension adds minimal overhead for template-level i18n. For optimal performance, cache translations using Laravel’s cache system or Twig’s runtime caching. Avoid loading translations dynamically in loops or high-traffic pages.
- How does this compare to Laravel’s built-in `Lang` facade for internationalization?
- Laravel’s `Lang` facade is optimized for Blade and backend logic, while this package specializes in Twig templates with gettext features like pluralization and RTL support. Use this package if you’re heavily invested in Twig or need advanced i18n features not available in Blade.
- Can I use this with other Twig-based Laravel packages like `twig-laravel` or `laravel-telescope`?
- Yes, this package is designed to integrate with Twig in Laravel. Ensure you’re using a compatible Twig environment (e.g., `spatie/twig-laravel`). Test thoroughly, as some packages may have their own Twig extensions that could conflict with this one.
- What happens if I need to update translations frequently? Is there a hot-reload feature?
- This package doesn’t include hot-reloading for translations. For development, use Twig’s debug mode to auto-reload templates. For production, clear Laravel’s cache (`php artisan cache:clear`) or Twig’s runtime cache after updating `.po`/`.json` files to reflect changes.
- Are there alternatives to this package for Twig i18n in Laravel?
- For Twig i18n in Laravel, alternatives include custom Twig extensions using Laravel’s `Lang` facade or third-party packages like `twig/extensions`. However, this package offers phpMyAdmin-proven gettext integration, which may handle edge cases (e.g., RTL languages) better than generic solutions.