- How do I install and configure **Localized Routes Plus** for Laravel 10+?
- Run `composer require larasofthu/localized-routes-plus` and publish the config with `php artisan vendor:publish --tag=localized-routes-plus-config`. Edit the config to define supported locales, default strategies (prefix/subdomain), and route separators like `/en/` or `en.example.com`.
- Does this package support subdomain-based localization (e.g., `hu.example.com`)?
- Yes, it fully supports subdomain routing. Configure it in the `localized_routes_plus.php` config under `strategies.subdomain`. Ensure your DNS and server (Nginx/Apache) support wildcard subdomains (e.g., `*.example.com`).
- Can I mix prefix and subdomain strategies in the same Laravel app?
- No, you must choose one primary strategy per route group. However, you can define multiple route groups with different strategies (e.g., prefix for `/blog` and subdomain for `/shop`). Use route macros or middleware to handle edge cases.
- How does locale detection work? Does it override Laravel’s default locale?
- Locale detection prioritizes subdomain > URL prefix > browser `Accept-Language` header. It integrates with Laravel’s middleware pipeline, so you can customize the logic via hooks in the config. Existing locale resolution (e.g., from sessions) remains unaffected unless explicitly overridden.
- Will this package work with Laravel’s route caching (`php artisan route:cache`)?
- Yes, the package is fully compatible with Laravel’s route caching. Localized routes are generated during caching, so there’s no runtime overhead. Test caching in staging to ensure no conflicts with dynamic route generation.
- How do I handle unsupported locales (e.g., a user visits `/fr/page` but French isn’t configured)?
- Configure a fallback locale in the `localized_routes_plus.php` config under `fallback_locale`. By default, it redirects to the default locale (e.g., `/en/page`). You can also throw a 404 or use middleware to handle custom logic.
- Does this package support country-specific routes (e.g., `/en-us`, `/en-ca`)?
- Yes, use the `country` strategy in your route definitions. Configure supported countries in the `localized_routes_plus.php` config under `countries`. Combine with locales (e.g., `en-us`, `hu-hu`) for granular routing.
- Can I use this with API routes (e.g., `/api/en/users`) without breaking CORS?
- Prefix-based routes (e.g., `/api/en/users`) work well for APIs. Ensure your CORS middleware allows the dynamic locale prefixes. Subdomain-based APIs (e.g., `api.en.example.com`) may require additional CORS configuration for cross-subdomain requests.
- How do I generate localized URLs in Blade or PHP (e.g., for links or redirects)?
- Use the `localized_route()` helper method, which automatically resolves the current locale. Example: `localized_route('about')` generates `/about`, `/hu/about`, or `hu.example.com/about` based on the active strategy. For dynamic locales, pass a second argument: `localized_route('about', 'de')`.
- Are there performance concerns with subdomain routing in high-traffic Laravel apps?
- Subdomain routing adds DNS lookup latency, which can impact performance. Mitigate this by using a CDN with edge caching (e.g., Cloudflare) or pre-warming DNS records. Prefix-based routing is lighter and recommended for API-heavy or latency-sensitive applications.