PHPackages                             shammaa/laravel-multilingual - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. shammaa/laravel-multilingual

ActiveLibrary

shammaa/laravel-multilingual
============================

High-performance multilingual package for Laravel with URL localization support and optimized routing

1.1.1(4mo ago)37MITPHPPHP ^8.1

Since Dec 2Pushed 4mo agoCompare

[ Source](https://github.com/shammaa/laravel-multilingual)[ Packagist](https://packagist.org/packages/shammaa/laravel-multilingual)[ RSS](/packages/shammaa-laravel-multilingual/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (5)Used By (0)

Laravel Multilingual
====================

[](#laravel-multilingual)

A high-performance multilingual package for Laravel with optimized URL localization support. Built with performance in mind, this package provides seamless language switching without impacting your site's speed.

Features
--------

[](#features)

- 🚀 **High Performance** - Optimized with caching and minimal overhead
- 🌍 **Multiple Languages** - Support for unlimited languages (60+ languages available)
- 🔗 **Flexible URLs** - Hide/Show any locale from URL (not just default)
- 🎯 **Smart Detection** - Automatic locale detection from URL, session, cookie, or browser
- 🔄 **Easy Switching** - Simple language switching helpers
- 📱 **RTL Support** - Built-in support for right-to-left languages
- 🛣️ **Route Macros** - Easy localized route registration

Installation
------------

[](#installation)

```
composer require shammaa/laravel-multilingual
```

Publish configuration:

```
php artisan vendor:publish --tag=multilingual-config
```

Quick Start
-----------

[](#quick-start)

### 1. Configure Languages

[](#1-configure-languages)

Edit `config/multilingual.php` or use `.env`:

```
// config/multilingual.php
'supported_locales' => ['ar', 'en', 'fr'],
'default_locale' => 'ar',
```

Or via `.env`:

```
MULTILINGUAL_LOCALES=ar,en,fr
```

**Available Languages:** The package includes 60+ languages (Arabic, English, French, Spanish, German, Chinese, Japanese, Turkish, Russian, and many more). Just choose from them!

### 2. Add Middleware

[](#2-add-middleware)

Add to `app/Http/Kernel.php`:

```
protected $middlewareGroups = [
    'web' => [
        // ... other middleware
        \Shammaa\LaravelMultilingual\Http\Middleware\SetLocale::class,
    ],
];
```

**That's it!** The middleware automatically:

- ✅ Detects locale from URL, session, cookie, or browser
- ✅ Sets locale for your entire application
- ✅ Works on **all routes automatically**

### 3. Register Localized Routes

[](#3-register-localized-routes)

```
Route::localized(function () {
    Route::get('/', function () {
        return view('home');
    })->name('home');

    Route::get('/about', function () {
        return view('about');
    })->name('about');

    Route::get('/posts/{post}', [PostController::class, 'show'])
        ->name('posts.show');
});
```

This automatically creates routes for all locales:

- `/` (default locale - hidden)
- `/en` (English)
- `/en/about` (English)
- `/about` (default locale)
- `/posts/1` (default locale)
- `/en/posts/1` (English)

### 4. Language Switcher

[](#4-language-switcher)

**Using Blade Component:**

```

```

**Or manually:**

```
@foreach(Multilingual::getSupportedLocales() as $locale)

        {{ locale_flag($locale) }} {{ locale_name($locale) }}

@endforeach
```

**For specific routes:**

```
@foreach(Multilingual::getSupportedLocales() as $locale)

        {{ locale_flag($locale) }} {{ locale_name($locale) }}

@endforeach
```

Usage
-----

[](#usage)

### Helper Functions

[](#helper-functions)

```
// Get localized URL for current route
localized_url('en')                    // Current URL in English

// Get localized URL for specific path
localized_url('en', '/about')          // /en/about

// Get all localized URLs
all_localized_urls()                   // All languages for current URL

// Switch locale and get URL
switch_locale('en')                    // Switch and get localized URL

// Check if current locale is RTL
is_rtl()                               // Returns true/false

// Get locale information
locale_name('ar')                      // Returns: العربية
locale_flag('ar')                      // Returns: 🇸🇾

// Generate localized route
localized_route('posts.show', $post, 'en')  // /en/posts/1
```

### Working with Models

[](#working-with-models)

**No model modification needed!** Just use helper functions with your existing models:

```
// In your Blade template

    Read in English

// Language switcher for a post
@foreach(Multilingual::getSupportedLocales() as $locale)

        {{ locale_flag($locale) }} {{ locale_name($locale) }}

@endforeach
```

Configuration
-------------

[](#configuration)

### Hiding Locales from URL

[](#hiding-locales-from-url)

Control which locales appear in URLs:

**Example 1: Hide default locale only (default behavior)**

```
'hidden_locales' => [],
'hide_default_locale' => true,
// Results: /about (Arabic - hidden), /en/about (English)
```

**Example 2: Hide multiple locales**

```
'hidden_locales' => ['ar', 'en'],
// Results: /about (hidden), /fr/about (French shown)
```

**Example 3: Show all locales**

```
'hidden_locales' => [],
'hide_default_locale' => false,
// Results: /ar/about, /en/about, /fr/about
```

**Via .env:**

```
MULTILINGUAL_HIDDEN_LOCALES=ar,en
MULTILINGUAL_HIDE_DEFAULT_LOCALE=true
```

### Excluding Routes

[](#excluding-routes)

Exclude routes from localization:

```
'excluded_routes' => [
    'api/*',
    'admin/*',
    'storage/*',
],
```

### Cache Configuration

[](#cache-configuration)

Enable caching for better performance:

```
'cache' => [
    'enabled' => true,
    'ttl' => 86400, // 24 hours
],
```

Clear cache:

```
php artisan multilingual:clear-cache
```

Performance
-----------

[](#performance)

This package is optimized for performance:

- **Minimal Middleware Overhead** - Only processes when needed
- **Smart Caching** - URL generation and locale detection are cached
- **Efficient URL Generation** - Fast, in-memory operations
- **No Database Queries** - Pure in-memory operations
- **Zero Impact** on PageSpeed scores

**Performance Tips:**

- Enable caching in production
- Use route exclusions for routes that don't need localization

API Reference
-------------

[](#api-reference)

### Facade Methods

[](#facade-methods)

```
Multilingual::getSupportedLocales()      // Get all supported locales
Multilingual::getDefaultLocale()         // Get default locale
Multilingual::isSupportedLocale($locale) // Check if locale is supported
Multilingual::getLocaleName($locale)     // Get locale name
Multilingual::getLocaleFlag($locale)     // Get locale flag
Multilingual::isRtlLocale($locale)       // Check if RTL
Multilingual::getLocalizedUrl($locale, $url) // Get localized URL
Multilingual::getAllLocalizedUrls($url)  // Get all localized URLs
```

### Helper Functions

[](#helper-functions-1)

```
localized_url($locale, $url = null)      // Get localized URL
all_localized_urls($url = null)          // Get all localized URLs
switch_locale($locale)                   // Switch locale
is_rtl()                                 // Check if RTL
locale_name($locale = null)              // Get locale name
locale_flag($locale = null)              // Get locale flag
localized_route($name, $params, $locale) // Generate localized route
```

License
-------

[](#license)

MIT

Author
------

[](#author)

Shadi Shammaa

Support
-------

[](#support)

For issues and feature requests, please use the GitHub issue tracker.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance76

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

4

Last Release

131d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/092a8b57ed995393618ee9dbf2055d43060fef84a2c5b4ef4e305bab3ff5b432?d=identicon)[shadishammaa](/maintainers/shadishammaa)

---

Top Contributors

[![shammaa](https://avatars.githubusercontent.com/u/8601466?v=4)](https://github.com/shammaa "shammaa (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shammaa-laravel-multilingual/health.svg)

```
[![Health](https://phpackages.com/badges/shammaa-laravel-multilingual/health.svg)](https://phpackages.com/packages/shammaa-laravel-multilingual)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
