Simple subdomain localization for Laravel.

2.0.2 2024-03-22 18:51 UTC

This package is auto-updated.

Last update: 2024-06-22 19:23:33 UTC


Laravel Localization - Simplified

Build Status Latest Stable Version Total Downloads Patreon donate button Donate to this project using Flattr Donate to this project using Paypal

Simplified localization for Laravel based on the application's subdomain.

Table of Contents



From the command line run:

$ composer require torann/localization


Once installed you need to register the service provider with the application. Open up config/app.php and find the providers key.

'providers' => [

Publish the configurations

Run this on the command line from the root of your project:

php artisan vendor:publish --provider="Torann\Localization\LocalizationServiceProvider"

A configuration file will be published to config/localization.php.


The following methods are available:

  • getDefaultLocale(): string
  • getCurrentLocale(): string
  • setLocale(string $locale = null): string|null
  • getLocales(): array
  • getLocale(string $key, mixed $default = null): mixed
  • getLocaleDirection(string $locale = 'current'): string
  • getLocaleKeys(): array
  • getLocalizedURL(string $url = null, mixed $locale = false, array $extra = []): string
  • isSupported(mixed $key): bool
  • getConfig(string $key, mixed $default = null): mixed


Laravel Localization comes with a few helper methods


Returns the Torann\Localization\LocaleManager instance.

localize_url($url = null, $locale = null, $attributes = []): string

Returns the given URL adapted to provided locale.

Determining Locale

By Subdomain

For this to work the subdomain needs to match an enabled supported locale key.

By Host

When the given subdomain is determined to not be valid the system can then set the locale depending on the current host. You'll need to set a map of your application's locales to hosts using the hosts configuration option.


Localization is open-sourced software licensed under the BSD 2-Clause License.