PHPackages                             unjudder/locale - 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. unjudder/locale

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

unjudder/locale
===============

Automatic detection of locales for Zend Framework 2

11561PHP

Since Oct 21Pushed 13y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (5)Used By (0)

SlmLocale
=========

[](#slmlocale)

SlmLocale is a Zend Framework 2 module to automatically detect a locale for your application. It uses a variety of pluggable strategies to search for a valid locale. SlmLocale has support for a default locale, a set of supported locales and locale aliases.

SlmLocale supports out of the box several strategies to search for a locale. Through interfaces, other strategies could be created. The set of default stragies is:

1. Use domain name (subdomain or TLD)
2. Use first segment of the path of an uri
3. Use a cookie
4. Use the HTTP Accept-Language header

SlmLocale will also provide an optional integration with ZfcUser, to make it possible to set a default locale in a user "profile".

Strategies
----------

[](#strategies)

The strategies are triggered via an event manager. This gives the option to have strategies look very early and others as late as possible. For example, you might first want to search for a cookie, then for a domain name and as last option in the HTTP Accept-Language header.

The strategies can also be called when a locale is found. This is useful for example to write a cookie with the locale when the locale is found through the HTTP Accept-Language header. Or you might want to perform a redirect to the correct domain when a user stated it preferred a certain locale.

Detector options
----------------

[](#detector-options)

The detector has a few options to tune the detection mechanism. First, there is a default locale. When every strategy sought for a locale, but did not find any, the default locale will be set. There is also a list of supported locales. Your application will probably not support every available locale, so you could define a set and SlmLocale tries to identify the best match. Aliases are possible to transform language codes into full locales. For example you can say if the code "en" is matched, the locale "en-US" will be used.

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

[](#installation)

SlmLocale is available through composer. Add "slm/locale" to your composer.json list. During development of SlmLocale, you can specify the latest available version:

```
"slm/locale": "dev-master"

```

In the `vendor/slm/locale/config` directory you can find a slmlocale.global.php.dist file. You can copy that file to `config/autoload/slmlocale.global.php` (note you have to omit the .dist extension now). In that file you can tune every option from the detector and attach some strategies. To enable SlmLocale, mind to add `"SlmLocale"` to your application.config.php modules list.

Usage
-----

[](#usage)

Open the configuration file (at `config/autoload/slmlocale.global.php`) and there the complete behaviour of SlmLocale can be tuned. Here below every value will be addressed.

### Default locale

[](#default-locale)

If you remove the `//` before the `'default'` line, you are able to set the default locale for your application

```
'default' => 'en-US'

```

### Supported locales

[](#supported-locales)

If you only want to have a specified set of locales your application supports, you can remove the `//` before the `'supported'`. In the array you can specify the list you want to support. Keep in mind the order of the list is important. If a strategy can detect multiple locales (like with the HTTP Accept-Language header) the first match in the list will be chosen.

```
'supported' => array('en-US', 'en-GB', 'en');

```

### Aliased locales

[](#aliased-locales)

\[tbd\]

### Strategy configuration

[](#strategy-configuration)

\[tbd\]

Development
-----------

[](#development)

SlmLocale is at this moment under development and it is not recommended to use SlmLocale in a production environment. All new features of SlmLocale are made with test driven development and continuous integration from Travis-CI.

[![Build Status](https://camo.githubusercontent.com/b069e229580c9f5a4e890a39b769618f912df5eccdcc396b596ffa58db39c505/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a757269616e736c75696d616e2f536c6d4c6f63616c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/juriansluiman/SlmLocale)

If you notice any bugs in SlmLocale, please create an issue in [the tracker](https://github.com/juriansluiman/SlmLocale/issues). At this moment, the `Detector` class is finished. The supplied strategies are all not finished yet:

1. Http Accept-Language strategy: under development
2. Cookie strategy: not started
3. Domain name strategy: under development
4. UtiPathStrategy: not started

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1944f0f08dd9bdcee5094cd7327ac9b415b26ac76f52beabebee10cf68c867e4?d=identicon)[alrik](/maintainers/alrik)

---

Top Contributors

[![basz](https://avatars.githubusercontent.com/u/143068?v=4)](https://github.com/basz "basz (9 commits)")[![alrik](https://avatars.githubusercontent.com/u/1223498?v=4)](https://github.com/alrik "alrik (4 commits)")[![atukai](https://avatars.githubusercontent.com/u/308995?v=4)](https://github.com/atukai "atukai (1 commits)")

### Embed Badge

![Health badge](/badges/unjudder-locale/health.svg)

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

###  Alternatives

[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[statikbe/laravel-chained-translator

The Laravel Chained Translator can combine several translators that can override each others translations.

36149.4k6](/packages/statikbe-laravel-chained-translator)

PHPackages © 2026

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