Package

Mcamara Laravel Localization

Easy localization for Laravel

Package

mcamara/laravel-localization

View on GitHub →

Laravel Localization Package Summary

The Laravel Localization package provides a comprehensive solution for managing localization in Laravel applications, enhancing the framework's built-in localization capabilities. This package simplifies the implementation of multilingual routes, content, and automatic language detection.

Key Features

  • Automatic Language Detection: Detects user's language preferences from the browser settings.
  • Smart Redirection: Supports session and cookie-based redirection for remembering user language choices.
  • Intelligent Routing: Allows defining routes once and automatically handles language-based route variations.
  • Translatable Routes: Enables URL translations for different languages, maintaining the same controller logic.
  • Caching and Testing Support: Enhances performance and reliability with route caching and built-in testing capabilities.
  • Locale Management: Includes utilities to hide the default locale in URLs, customize locale order, and map locales for URLs.
  • Helpers and Utilities: Provides multiple helpers for generating localized URLs, getting current locale details, and creating language selectors.

Installation and Configuration

Install the package via Composer:

composer require mcamara/laravel-localization

For Laravel versions 5.4 and below, manually register the service provider as detailed in the package's additional documentation.

Publish the configuration file with:

php artisan vendor:publish --provider="Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider"

This will create a config/laravellocalization.php file where you can set supported locales, language detection settings, and other preferences.

Usage

Wrap routes within a localized group to enable automatic language prefixing and apply middleware for locale redirections:

Route::group(['prefix' => LaravelLocalization::setLocale()], function() {
Route::get('/', function() {
return view('welcome');
});
});

Middleware

Register the necessary middleware in your app/Http/Kernel.php to handle locale session redirection, cookie redirection, and more. Each middleware plays a role in managing how users interact with different locales in your application.

Advanced Features

  • Localized URLs: Generate URLs specific to locales and manage how URLs are presented with or without the default locale.
  • Translated Routes: Define route translations in language-specific files to support URL translations across different languages.
  • Route Caching: Use the custom route caching command provided by the package to ensure that your localized routes are efficiently managed.

Testing

The package supports testing localized applications by allowing you to set the locale context explicitly in your test cases.

Practical Utilities

  • Language Selectors: Easily create dropdowns or menus for users to switch languages.
  • Locale Information Helpers: Retrieve current locale details like name, script, and direction for use in views and controllers.

Conclusion

Laravel Localization is an essential package for developers looking to create multilingual web applications with Laravel. It extends the framework’s capabilities, providing robust tools for managing language preferences, routes, and content localization seamlessly.

Mcamara Laravel Localization Related Articles

Validate and Convert HEIC Images in Laravel image

Validate and Convert HEIC Images in Laravel

Read article
Ship AI with Laravel: Test Your AI System with Zero API Calls image

Ship AI with Laravel: Test Your AI System with Zero API Calls

Read article
ArtisanFlow: A Flowchart Engine for Laravel and Alpine.js image

ArtisanFlow: A Flowchart Engine for Laravel and Alpine.js

Read article
Laravel Blade Icons Stable Release image

Laravel Blade Icons Stable Release

Read article
A Practical Guide to Laravel's First-Party Image Processing image

A Practical Guide to Laravel's First-Party Image Processing

Read article
NativePHP for Mobile Is Now Free image

NativePHP for Mobile Is Now Free

Read article
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Pushsilver logo

Pushsilver

Pushsilver is simple invoicing for freelancers and small studios — send polished invoices, automate reminders, and get paid on time without the bloat.

Pushsilver
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum