PHPackages                             marcnewton/laravel-alsl - 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. marcnewton/laravel-alsl

ActiveLibrary[Localization &amp; i18n](/categories/localization)

marcnewton/laravel-alsl
=======================

Detects a users language preferences in the Accept-Language request header, from the order of their language preference; an attempt to find and set a matching locale available in Laravel's resources/lang directory.

1.0.0(5y ago)37631[1 issues](https://github.com/marcnewton/laravel-alsl/issues)MITPHPPHP &gt;=7.4|^8.0

Since Jan 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/marcnewton/laravel-alsl)[ Packagist](https://packagist.org/packages/marcnewton/laravel-alsl)[ Docs](https://https://github.com/marcnewton/laravel-alsl)[ GitHub Sponsors](https://github.com/sponsors/marcnewton)[ RSS](/packages/marcnewton-laravel-alsl/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Accept-Language to SetLocale (ALSL)
===========================================

[](#laravel-accept-language-to-setlocale-alsl)

Adds support for il8n Detection.

Iteration of a user's language preferences set in the `Accept-Language` request header, using order of language preference from users web browser; attempts to find a matching locale available in Laravel `resources/lang` directory.

- Attempts Fallback to a mainland language, honouring the users first preferences.
- Restores saved user preference from an authenticated user `User::locale` if set.
- Fallback to Laravel configuration `app.locale` else `en` (English).

[![Laravel ALSL](https://camo.githubusercontent.com/195e0585f7c9bc29ddca25568f76d8f6d216c9b3a014fad9b8fd45269867bd77/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f5672764255655356444e452f302e6a7067)](https://youtu.be/VrvBUeSVDNE)

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

[](#installation)

`composer require marcnewton/laravel-alsl`

Usage Information
-----------------

[](#usage-information)

`app()->getLocale()` will return the value of either the users web browser language preference or authenticated user `locale` attribute if present, as long as a matching ISO is found in the `resources/lang` directory else the `app.locale` config value will be used.

Language Variants
-----------------

[](#language-variants)

To support variants, create language translation folders in `resources/lang`.

For example, to support **English (United States)** and **English (United Kingdom)**; create the following directories: `en-US` and `en-GB` in addition to `en` (English).

How detection works.
--------------------

[](#how-detection-works)

Web browsers are natively set to their systems user preferences for languages on installation and then further fallback preferences can be configured in the browser by the user, this information is sent with requests via a header called [Accept-Language](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language), it is a widely supported standard often overlooked.

The header is processed and a best match for laravels language directories is detected and set using Laravels built in locale functionality.

Here is an example of some different senarios for an individual whos preference is Mexican Spanish (español mexicano es-MX) and their secondary fallback is United States Spanish (Estados Unidos es-US):

Available Server LanguagesMatches**en, es\_US, es**`es-US`**en, es\_US, es\_MX, es**`es-MX`**en, es**`es`**en**`en`**en, en\_US, es\_US, es\_MX, es\_CL**`es-MX`If the user only specified **Spanish** then this would match `es` but if the server only has `en` then it would present `en`.

However, if the user specified a preference for **Spanish** first then a Spanish variant, `es` would match first rather than the latter choices for variants unless the server does not have an `es` language folder, a variant folder will match else fallback to a configuration default.

**Underscores** from the `Accept-Language` header are converted to **Hyphens** to align with usages in PHP &amp; Javascript localization methods.

Deployments
-----------

[](#deployments)

When adding or removing language support in `resources/lang`, you should ensure you run `php artisan cache:forget resources.languages` to clear the cache.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

1994d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ff6212f8600a29ca6b2d8ef94c6caaa1d22aeb0336711da5052081a0faa224b?d=identicon)[marc-newton](/maintainers/marc-newton)

---

Tags

laravellanguage

### Embed Badge

![Health badge](/badges/marcnewton-laravel-alsl/health.svg)

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

###  Alternatives

[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

544656.8k4](/packages/codezero-laravel-localized-routes)[josiasmontag/laravel-redis-mock

This Laravel package provides a Redis mock for your tests

471.8M19](/packages/josiasmontag-laravel-redis-mock)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5414.5k1](/packages/longman-laravel-multilang)

PHPackages © 2026

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