- Can I use `symfony/polyfill-intl-icu` in Laravel to support RTL (right-to-left) languages like Arabic or Hebrew without the `intl` extension?
- Yes, but with limitations. The polyfill provides basic RTL detection via `locale_is_right_to_left()` and supports English-only ICU features. For full RTL functionality (e.g., Arabic/Hebrew sorting, formatting), you’ll still need the `intl` extension. Test `locale_is_right_to_left()` in your RTL locales and validate frontend frameworks like Tailwind or Bootstrap for CSS direction changes.
- How do I install `symfony/polyfill-intl-icu` in a Laravel project?
- Run `composer require symfony/polyfill-intl-icu` in your project root. No additional configuration is needed—it automatically replaces missing ICU functionality if the `intl` extension is unavailable. Ensure your `composer.json` requires a compatible version (e.g., `^1.34.0`).
- Will this polyfill work with Laravel’s localization system (e.g., `Lang::get()`, Carbon) for non-English locales?
- No, this polyfill is **English-only** and only provides fallbacks for ICU-related classes like `Collator` or `NumberFormatter`. For non-English locales (e.g., Thai, Hindi), you’ll need the `intl` extension. Use it as a temporary solution or for English-specific features like list formatting (`IntlListFormatter`).
- Does `symfony/polyfill-intl-icu` support PHP 8.5’s new `IntlListFormatter` in Laravel?
- Yes, the polyfill includes `IntlListFormatter` support for PHP 8.5, enabling localized list patterns (e.g., “A, B, and C”). However, this is English-only. If you’re targeting PHP 8.5, update your Laravel project (requires PHP 8.1+) and verify the formatter works with your locales. Benchmark performance for large lists.
- Is there a performance impact if I use `Collator::compare()` with this polyfill in Laravel?
- Yes, the polyfill’s `Collator::compare()` is **5–10x slower** than the native `intl` extension. Avoid using it for bulk operations like sorting large datasets or search filters. Cache results or plan to upgrade to the `intl` extension for production if performance is critical.
- Can I use this polyfill as a replacement for the `intl` extension in production?
- No, it’s a **temporary fallback** for environments where `intl` isn’t available (e.g., shared hosting). For full i18n support (non-English locales, complex sorting, or formatting), install the `intl` extension. Monitor usage logs and prioritize upgrading once feasible.
- Will this polyfill break existing Laravel code that uses `intl` functions?
- No, it’s designed for **zero-configuration fallback**. If the `intl` extension is installed, the polyfill won’t interfere. Only when `intl` is missing will it silently replace ICU classes. Test your app’s ICU-dependent features (e.g., `IntlDateFormatter`) to confirm compatibility.
- Are there alternatives to `symfony/polyfill-intl-icu` for Laravel RTL or ICU support?
- For RTL, consider Laravel’s built-in `locale_is_right_to_left()` with CSS frameworks (e.g., Tailwind’s RTL classes). For ICU, the `intl` extension is the only full-featured solution. Other polyfills (e.g., `php-intl-icu`) are less maintained. This Symfony polyfill is the most Laravel-friendly option for temporary fixes.
- How do I test if the polyfill is working in my Laravel app?
- Check if ICU classes are autoloaded by running `php artisan tinker` and testing `new Collator()` or `new IntlDateFormatter()`. If no errors appear, the polyfill is active. For RTL, verify `locale_is_right_to_left('ar')` returns `true`. Compare output with a system where `intl` is installed to spot English-only limitations.
- Does this polyfill support mixed-script sorting (e.g., Arabic + Latin characters) in Laravel?
- No, the polyfill’s `Collator` handles **English-only** sorting. Mixed-script sorting (e.g., Arabic + Latin) will fail or produce incorrect results. Cache results or upgrade to the `intl` extension for complex datasets. Test with `Collator::compare()` on mixed-script strings to confirm limitations.