Download the PHP package larasofthu/localized-routes-plus without Composer
On this page you can find all versions of the php package larasofthu/localized-routes-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download larasofthu/localized-routes-plus
More information about larasofthu/localized-routes-plus
Files in larasofthu/localized-routes-plus
Package localized-routes-plus
Short Description Advanced Laravel package for creating localized routes with subdomain support, country-specific routing, and automatic locale management. Supports URL prefixes, subdomains, and multi-country localization strategies.
License MIT
Homepage https://github.com/LarasoftHU/localized-routes-plus
Informations about the package localized-routes-plus
Laravel Localized Routes Plus
A powerful Laravel package for creating localized routes with advanced features including subdomain support, country-specific routing, and automatic locale management.
Features
🌍 Multiple Localization Strategies
- URL prefix-based localization (
/en/page,/hu/page) - Subdomain-based localization (
en.example.com,hu.example.com) - Country-specific routing (
/en-us/page,/en-ca/page)
🚀 Framework Integration
- Seamless Laravel Route integration
- Automatic middleware registration
- Resource route support
- Custom route model binding
⚙️ Flexible Configuration
- Whitelist/blacklist locales
- Configurable separators
- Multiple domains per locale
- Default locale customization
🔧 Developer-Friendly
- Intuitive API design
- Helper methods for URL generation
- Comprehensive testing
- Full IDE support
Installation
Install the package via Composer:
Publish the configuration file:
Quick Start
Basic Usage
Create localized routes by chaining the localized() method:
Resource Routes
Helper Functions
The package provides convenient helper functions for common tasks:
Configuration
The configuration file (config/localized-routes-plus.php) contains all available options:
URL Prefix Localization
Basic Configuration
Route Examples
Including Default Locale in URLs
Subdomain Localization
Configuration
Multiple Domains per Locale
Route Examples
Country-Specific Routing
Configuration
Multiple Countries per Locale
Path Separators
Route Examples
Selective Localization
Whitelist Specific Locales
Blacklist Specific Locales
Advanced Usage
Route Model Binding
Route Parameters
Middleware Integration
The package automatically registers middleware to set the application locale:
Helper Methods
Route Switching
URL Generation
Route Information
Global Helper Functions
The package provides convenient global helper functions:
current_route()
Get the current route URL in a different locale:
route_is()
Check if the current route matches a name (locale-agnostic):
localized_route()
Generate localized route URLs:
Localized URI Translation
The package supports translating URI segments using Laravel's language files. This allows you to have different URL structures for different locales while keeping the same route logic.
Setup
Create language files for your routes in the lang/{locale}/routes.php files:
Usage
Define your routes normally and the package will automatically use the translated URIs:
Generated Routes
The above configuration will generate the following routes:
With Route Parameters
You can also translate URIs that contain parameters:
Important Notes
- The translation key must match the route name exactly (use
getSafeName()without locale prefix) - If no translation is found, the original URI is used
- Parameters must be preserved in translated URIs (
{parameter}) - This works with all localization strategies (prefixes, subdomains, countries)
Blade Helpers
Language Switcher
Current Locale Detection
Testing
The package includes comprehensive tests covering all functionality:
API Reference
LocalizedRoute Methods
| Method | Description | Example |
|---|---|---|
localized($locales = []) |
Create localized versions | ->localized(['en', 'hu']) |
localizedExcept($locales = []) |
Exclude specific locales | ->localizedExcept('de') |
locale($locale, $country = null) |
Get route for locale | $route->locale('hu') |
getUrl($locale = null, $country = null) |
Generate URL for locale | $route->getUrl('de') |
getLocale() |
Get route locale | $route->getLocale() |
getCountry() |
Get route country | $route->getCountry() |
getSafeName() |
Get name without locale prefix | $route->getSafeName() |
is($name) |
Check route name (locale-agnostic) | $route->is('products.index') |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
locales |
array |
['en'] |
Available locales |
default_locale |
string |
'en' |
Default application locale |
use_route_prefix_in_default_locale |
bool |
false |
Include prefix for default locale |
use_subdomains_instead_of_prefixes |
bool |
false |
Use subdomains instead of prefixes |
domains |
array |
[] |
Domain mapping for locales |
use_countries |
bool |
false |
Enable country-specific routing |
country_path_separator |
string |
'dash' |
Separator between locale and country |
countries |
array |
[] |
Country mapping for locales |
Global Helper Functions
| Function | Description | Example |
|---|---|---|
current_route($locale, $country, $parameters, $absolute) |
Get current route URL in different locale | current_route('de') |
route_is($name) |
Check route name (locale-agnostic) | route_is('products.index') |
localized_route($name, $parameters, $absolute, $locale, $country) |
Generate localized route URL | localized_route('products.show', $product) |
Middleware
| Class | Description | Auto-Applied |
|---|---|---|
SetLocaleFromRoute |
Sets App::setLocale() from route |
✅ Yes |
SetCountryFromRoute |
Sets App::setCountry() from route |
✅ When countries enabled |
Examples
E-commerce Site
Multi-Country Site
Subdomain Setup
Troubleshooting
Common Issues
Route names must be set before localized()
Missing domain configuration for subdomains
Country parameter required when countries enabled
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Security
If you discover any security vulnerabilities, please email [email protected] instead of using the issue tracker.
Credits
- Kapási Fülöp
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of localized-routes-plus with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^9.0||^10.0||^11.0||^12.0