PHPackages                             misaf/vendra-localization - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. misaf/vendra-localization

ActiveVendra-module[Localization &amp; i18n](/categories/localization)

misaf/vendra-localization
=========================

Request locale resolution for Laravel applications.

v1.10.0(2w ago)1245MITPHPPHP ^8.3CI failing

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/misaf/vendra-localization)[ Packagist](https://packagist.org/packages/misaf/vendra-localization)[ Docs](https://github.com/misaf/vendra-localization)[ RSS](/packages/misaf-vendra-localization/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (27)Versions (26)Used By (5)

Vendra Localization
===================

[](#vendra-localization)

Request locale resolution for Laravel applications.

Features
--------

[](#features)

- `SetLocale` middleware that resolves the request locale, calls `App::setLocale()`, and sets the `Content-Language` and `Vary` response headers
- Config-driven resolver chain: the first resolver that produces a locale wins
- Built-in resolvers for the `Accept-Language` header, query string, route parameter, and authenticated user (including Laravel's `HasLocalePreference` contract)
- Validates the resolved locale against the supported locales, matching region variants (`fr-CA` matches a supported `fr`)
- Falls back to `app.fallback_locale` whenever the resolved locale is missing or unsupported
- Sends `Vary: Accept-Language` only when the locale actually derives from the header
- Optional syncing of the resolved locale to `Carbon` dates and the `Number` helper

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 12 or 13
- Pest 4

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

[](#installation)

```
composer require misaf/vendra-localization
```

Publish the config file:

```
php artisan vendor:publish --tag=vendra-localization-config
```

The service provider is auto-registered.

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

[](#configuration)

`config/vendra-localization.php`:

```
return [
    // The locales your application serves. Region variants (fr-CA)
    // match their base language (fr).
    'supported_locales' => ['en', 'fa', 'de'],

    // Tried in order; the first resolver returning a locale wins.
    'resolvers' => [
        Misaf\VendraLocalization\Resolvers\UserLocaleResolver::class,
        Misaf\VendraLocalization\Resolvers\AcceptLanguageLocaleResolver::class,
    ],

    // Also apply the resolved locale to Carbon dates and the Number
    // helper (the latter requires ext-intl).
    'sync' => [
        'carbon' => false,
        'number' => false,
    ],
];
```

Usage
-----

[](#usage)

Register the middleware on the group or routes that should be localized, e.g. in `bootstrap/app.php`:

```
use Misaf\VendraLocalization\Http\Middleware\SetLocale;

->withMiddleware(function (Middleware $middleware): void {
    $middleware->web(append: [
        SetLocale::class,
    ]);
})
```

On each request the middleware resolves a locale through the configured resolver chain, validates it against `supported_locales`, applies it with `App::setLocale()`, and adds the response headers:

```
Content-Language: fa
Vary: Accept-Language

```

`Vary: Accept-Language` is only added when the chain includes the `Accept-Language` resolver, so cache keys stay accurate for query- or route-based strategies.

### Per-route resolver chains

[](#per-route-resolver-chains)

The package registers a `vendra.locale` middleware alias that accepts resolver aliases (or class names) as parameters, overriding the configured chain for those routes:

```
Route::middleware('vendra.locale:route,accept-language')->group(function (): void {
    // ...
});
```

Resolvers
---------

[](#resolvers)

ResolverAliasReads the locale from`AcceptLanguageLocaleResolver``accept-language`The `Accept-Language` request header`QueryLocaleResolver``query`The `?locale=` query string parameter`RouteLocaleResolver``route`The `{locale}` route parameter`UserLocaleResolver``user`The authenticated user: `preferredLocale()` when the user implements `Illuminate\Contracts\Translation\HasLocalePreference`, otherwise the `locale` attributeResolvers return `null` when their source has no value; the chain then moves to the next resolver, and the `SetLocale` middleware applies `app.fallback_locale` when the whole chain comes up empty.

Custom resolver
---------------

[](#custom-resolver)

Implement the `LocaleResolver` contract and add it to the `resolvers` chain:

```
use Illuminate\Http\Request;
use Misaf\VendraLocalization\Contracts\LocaleResolver;

final readonly class TenantLocaleResolver implements LocaleResolver
{
    public function resolve(Request $request): ?string
    {
        return $request->user()?->tenant?->locale;
    }
}
```

```
// config/vendra-localization.php
'resolvers' => [
    App\Localization\TenantLocaleResolver::class,
    Misaf\VendraLocalization\Resolvers\AcceptLanguageLocaleResolver::class,
],
```

The resolved locale is still validated against `supported_locales` by the middleware, so an unsupported value falls back automatically. Return `null` to defer to the next resolver in the chain.

If your resolver reads request headers, also implement `Misaf\VendraLocalization\Contracts\ProvidesVaryHeaders` so the middleware can advertise them in the response `Vary` header.

Events
------

[](#events)

Laravel dispatches `Illuminate\Foundation\Events\LocaleUpdated` whenever `App::setLocale()` runs — listen for that event to react to locale changes; the package does not add an event of its own.

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance93

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~1 days

Total

24

Last Release

20d ago

Major Versions

0.2.0 → v1.0.02026-07-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/41fd7351d25e29dafa18068d0418eecf6bb47a7473aabe6bc674b4ca35e71805?d=identicon)[misaf](/maintainers/misaf)

---

Top Contributors

[![misaf](https://avatars.githubusercontent.com/u/8195685?v=4)](https://github.com/misaf "misaf (16 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravellocalizationlocalemisafvendra

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/misaf-vendra-localization/health.svg)

```
[![Health](https://phpackages.com/badges/misaf-vendra-localization/health.svg)](https://phpackages.com/packages/misaf-vendra-localization)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M238](/packages/laravel-mcp)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

46273.9k](/packages/harris21-laravel-fuse)

PHPackages © 2026

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