PHPackages                             websafe/zf-mod-language - 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. websafe/zf-mod-language

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

websafe/zf-mod-language
=======================

A ZF2 module which takes care of detecting an optimal and/or the requested locale for Your application's translator. The locale is computed/detected basing on values found in: Accept-Language header, cookie, session, query parameter and route parameter. Each detection method can be disabled/enabled via configuration.

v0.0.8(12y ago)123[1 issues](https://github.com/websafe/zf-mod-language/issues)MITPHPPHP &gt;=5.4

Since Dec 9Pushed 12y ago1 watchersCompare

[ Source](https://github.com/websafe/zf-mod-language)[ Packagist](https://packagist.org/packages/websafe/zf-mod-language)[ Docs](http://github.com/websafe/zf-mod-language)[ RSS](/packages/websafe-zf-mod-language/feed)WikiDiscussions develop Synced 2d ago

READMEChangelogDependencies (3)Versions (9)Used By (0)

WebsafeZfModLanguage
====================

[](#websafezfmodlanguage)

A ZF2 module which takes care of detecting **an optimal** and|or **the requested** locale for Your application's translator. The locale is computed/detected basing on values found in: Accept-Language headers, cookie, session, query parameter and route parameter. Each detection method can be disabled/enabled via configuration.

Provides:

- The language service accessible via ServiceManager. See: [WebsafeZfModLanguageService](src/WebsafeZfModLanguage/ServiceManager/WebsafeZfModLanguageService.php) and [WebsafeZfModLanguageServiceFactory](src/WebsafeZfModLanguage/ServiceManager/WebsafeZfModLanguageServiceFactory.php).
- A Controller for handling client requests (switching locale/language). See: [WebsafeZfModLanguageController](src/WebsafeZfModLanguage/Controller/WebsafeZfModLanguageController.php).
- View Helpers for showing language selecting menus/dropdowns etc.

Using WebsafeZfModLanguage in Your application
----------------------------------------------

[](#using-websafezfmodlanguage-in-your-application)

In project's root run:

```
vendor/bin/composer.phar require "websafe/zf-mod-language:*"
```

In `config/application.config.php` add `WebsafeZfModLanguage`:

```
    // ...
    'modules' => array(
        // ...
        'Application',
        'WebsafeZfModLanguage',
        // ...
    ),
```

That's all. The module should work now - transparently. Test it on the official [ZendSkeletonApplication](https://github.com/zendframework/ZendSkeletonApplication) and try to modify browsers Accept-Language headers or just add `?language=ja_JP` (or any other locale available in `supported_locales`) in the url.

You should notice a language change, because the default configuration tells the language service to detect the locale in the query too, see options `detect_in_query` and `query_param`.

There's already a basic view helper included, so after enabling the module in `config/application.config.php` You can try to add the following code somewhere in `layout.phtml` or in other view scripts:

```

```

The view helper is currently the only reason for the Controller to exist.

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

[](#configuration)

How locale/language detection is handled.
-----------------------------------------

[](#how-localelanguage-detection-is-handled)

1. The module attaches the [DetectLanguagesListener](src/WebsafeZfModLanguage/EventManager/DetectLanguagesListener.php) to the event manager.
2. The [DetectLanguagesListener](src/WebsafeZfModLanguage/EventManager/DetectLanguagesListener.php) is now waiting for a dispatch event (`MvcEvent::EVENT_DISPATCH`)...
3. When the dispatch event occurs, [DetectLanguagesListener](src/WebsafeZfModLanguage/EventManager/DetectLanguagesListener.php) forwards the event to the language service [WebsafeZfModLanguageService](src/WebsafeZfModLanguage/ServiceManager/WebsafeZfModLanguageService.php).

```
1. The language service collects data for locale detection:

   + Retrieve languages requested by the client/browser via
     [Accept-Language] headers. Add all results ordered by priority
     to the `detectedLanguages` array.

   + Retrieve locale stored in cookie (name of cookie is configurable).
     Prepend the retrieved locale to the front of `detectedLanguages`.

   + Retrieve locale stored in session (container name and session
     variable name are configurable).
     Prepend the retrieved locale to the front of `detectedLanguages`.

   + Retrieve locale provided in query parameter (parameter name  is
     configurable).
     Prepend the retrieved locale to the front of `detectedLanguages`.

   + Retrieve locale provided in route parameter (parameter name is
     configurable).
     Prepend the retrieved locale to the front of `detectedLanguages`.

1. The language service iterates through `detectedLanguages` and stops
   iterating after the first detected locale that exists in
   [supported_locales]. The matched locale is now accessible via
   `$sm->get('WebsafeZfModLanguageService')->getCurrentLocale()`.

1. The language service applies the current locale to the `translator`
   service.

```

###  Health Score

19

↓

LowBetter than 10% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

7

Last Release

4538d ago

### Community

Maintainers

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

---

Top Contributors

[![websafe](https://avatars.githubusercontent.com/u/412013?v=4)](https://github.com/websafe "websafe (21 commits)")

---

Tags

languagemoduletranslatorlocalezf2websafedetecting

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/websafe-zf-mod-language/health.svg)

```
[![Health](https://phpackages.com/badges/websafe-zf-mod-language/health.svg)](https://phpackages.com/packages/websafe-zf-mod-language)
```

###  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)[aplus/language

Aplus Framework Language Library

2351.7M15](/packages/aplus-language)[lunetics/locale-bundle

A Bundle for switching Languages

1861.1M8](/packages/lunetics-locale-bundle)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[vanderlee/syllable

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

124432.6k8](/packages/vanderlee-syllable)[vluzrmos/language-detector

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

109554.8k3](/packages/vluzrmos-language-detector)

PHPackages © 2026

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