PHPackages                             douyasi/locator - 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. douyasi/locator

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

douyasi/locator
===============

Browser Preferred Language Detector

1.0.3(9y ago)46.8k1MITPHPPHP &gt;=5.5.9

Since Jul 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/douyasi/locator)[ Packagist](https://packagist.org/packages/douyasi/locator)[ Docs](http://douyasi.com)[ RSS](/packages/douyasi-locator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (5)Used By (0)

Locator
=======

[](#locator)

[![Latest Stable Version](https://camo.githubusercontent.com/978f7d68b9dde74e479dd5feabe7ea488c532a932a5bb8c788be9585880107f0/68747470733a2f2f706f7365722e707567782e6f72672f646f75796173692f6c6f6361746f722f762f737461626c652e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/douyasi/locator)[![Latest Unstable Version](https://camo.githubusercontent.com/98bf403fadbf1fa997b9b1451eec760dd02e056037bfdad54891100be43712f4/68747470733a2f2f706f7365722e707567782e6f72672f646f75796173692f6c6f6361746f722f762f756e737461626c652e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/douyasi/locator)[![License](https://camo.githubusercontent.com/2ef9fa2f14794da666407555f552bf438eba33961d40e5678b3dc3cacddb5234/68747470733a2f2f706f7365722e707567782e6f72672f646f75796173692f6c6f6361746f722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/douyasi/locator)[![Total Downloads](https://camo.githubusercontent.com/6cef311440da1f99be5e6dda272520b9a364f42dc77f7421bca7419923bada9d/68747470733a2f2f706f7365722e707567782e6f72672f646f75796173692f6c6f6361746f722f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/douyasi/locator)

Description
-----------

[](#description)

Browser Preferred Language Detector, detect by browser `Accept-Language` request header.

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

[](#installation)

Get [Composer](https://getcomposer.org/), then run in terminal:

```
cd /path/to/your-project
composer require "douyasi/locator:~1.0"
```

Usage
-----

[](#usage)

### Example in Laravel

[](#example-in-laravel)

```
Route::get('test', function () {
    $detector = app('Douyasi\Locator\PreferredLanguageDetector');
    return $detector->detect(['zh-CN', 'en']);
    //return $detector->get();
    //return $detector->get_languages(['zh-CN,zh', 'en', 'zh-TW'], ['0.8', '0.6', '0.4']);
});
```

> You can use `$detector->detect(['zh-CN', 'en'])` to replace `Request::getPreferredLanguage(['zh-CN', 'en'])` in Laravel.

API
---

[](#api)

### Detect your browser preferred language:

[](#detect-your-browser-preferred-language)

```
$langs = ['zh-CN', 'en'];  //available languages (i18n array) in your web project
$detector->detect($langs);  //return 'zh-CN' or 'en', according to your browser language preference.

```

### Get browser preferrend languages:

[](#get-browser-preferrend-languages)

```
$detector->get();

```

You can get some data (json format) like blow:

```
[
    {
        "priority": 80,
        "tags": "zh-CN,zh",
        "locales": [
            {
                "language": "zh",
                "region": "CN",
                "script": "",
                "variant1": "",
                "variant2": "",
                "variant3": "",
                "private1": "",
                "private2": "",
                "private3": ""
            },
            {
                "language": "zh",
                "script": "",
                "region": "",
                "variant1": "",
                "variant2": "",
                "variant3": "",
                "private1": "",
                "private2": "",
                "private3": ""
            }
        ]
    },
    {
        "priority": 60,
        "tags": "en",
        "locales": [
            {
                "language": "en",
                "script": "",
                "region": "",
                "variant1": "",
                "variant2": "",
                "variant3": "",
                "private1": "",
                "private2": "",
                "private3": ""
            }
        ]
    },
]
```

Reference
---------

[](#reference)

- [http-accept-language](https://github.com/BaguettePHP/http-accept-language)

Copyright
---------

[](#copyright)

>
>
> Copyright (c) 2016 douyasi org by ycrao

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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

3

Last Release

3638d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f0bca08de3586af706a2ada29662ba46249150dce37ee138180020329eac204?d=identicon)[raoyc](/maintainers/raoyc)

---

Top Contributors

[![ycrao](https://avatars.githubusercontent.com/u/3280204?v=4)](https://github.com/ycrao "ycrao (11 commits)")

---

Tags

accept-languagebrowser-preferred-languagelanguagepreferenceslaravellocalizationi18nlanguagelumendetectorlocatoryascmf

### Embed Badge

![Health badge](/badges/douyasi-locator/health.svg)

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

###  Alternatives

[vluzrmos/language-detector

Detect the language for your application using browser preferences, subdomains or route prefixes.

109567.5k3](/packages/vluzrmos-language-detector)[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)[pmochine/laravel-tongue

🎉 Finally a subdomain localization that works how you want it to work. 🌐

4158.4k](/packages/pmochine-laravel-tongue)[jrmajor/fluent

Fluent localization system for PHP

2718.0k7](/packages/jrmajor-fluent)

PHPackages © 2026

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