PHPackages                             arosemena/localechooser - 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. arosemena/localechooser

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

arosemena/localechooser
=======================

Locale chooser based on common browser headers

1.0.1(11y ago)030MITPHPPHP &gt;=5.4.0

Since Feb 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/arosemena/localechooser)[ Packagist](https://packagist.org/packages/arosemena/localechooser)[ Docs](https://github.com/arosemena/localechooser)[ RSS](/packages/arosemena-localechooser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Locale Chooser for PHP
======================

[](#locale-chooser-for-php)

This is a simple class to detect the locale that the user preffers.

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

[](#installation)

The easiest way to install this is through composer, inside your composer.json require block add

```
"arosemena/localechooser": "1.0.1"

```

and then do `composer update`, otherwise you could grab the class itself and autoload it with the method of your choosing.

Usage
-----

[](#usage)

You will need an instance of the LocaleChooser class, the constructor takes 3 parameters, first an array of the available language, `['en', 'es', 'fr']` for example, the second parameter is a string of the default language in case nothing can be matched, the third parameter is the name of the cookie that contains the language that overrides all the normal priority.

```
    $chooser = new Arosemena\LanguageChooser\LanguageChooser(['en', 'es'], 'en', 'language');
```

After the class has been instanciated do `$chooser->obtain()` to get the appropiate locale.

Examples
--------

[](#examples)

```
    $chooser = new Arosemena\LanguageChooser\LanguageChooser(['en', 'es', 'fr'], 'es', 'language');
    // if the browser says that the user prefers french (fr)
    $chooser->obtain(); // returns 'fr'
    // if the browser says that the user prefers german (de)
    $chooser->obtain(); // returns 'es' because it is the default language and german isn't supported
    // if the browser says that the user prefers spanish (es) and sends a cookie named language with the value 'fr'
    $chooser->obtain(); // returns 'fr' because the cookie overrides the browser preferred language
```

How does it work?
-----------------

[](#how-does-it-work)

The class will read the `$_SERVER['HTTP_ACCEPT_LANGUAGE']` variable which is a header sent by most modern browsers and it will be parsed and evaluated against the available languages to determine the most appropiate one.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~0 days

Total

2

Last Release

4093d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad042d78993f9b63fd8fe81112f5e9b21fca6b487ecb36510d0a1abd8a23885f?d=identicon)[arosemena](/maintainers/arosemena)

---

Top Contributors

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

---

Tags

languageLocalChooser

### Embed Badge

![Health badge](/badges/arosemena-localechooser/health.svg)

```
[![Health](https://phpackages.com/badges/arosemena-localechooser/health.svg)](https://phpackages.com/packages/arosemena-localechooser)
```

###  Alternatives

[codezero/laravel-localized-routes

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

543638.1k4](/packages/codezero-laravel-localized-routes)[gettext/languages

gettext languages with plural rules

7530.3M10](/packages/gettext-languages)[aplus/language

Aplus Framework Language Library

2351.7M15](/packages/aplus-language)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[akaunting/laravel-language

Language switcher package for Laravel

223285.2k1](/packages/akaunting-laravel-language)[vanderlee/syllable

Text syllable splitting and hyphenation using Frank M. Liang's TeX algorithm.

124432.6k8](/packages/vanderlee-syllable)

PHPackages © 2026

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