2017 © Pedro Peláez
 

library 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.

image

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.

  • Tuesday, December 10, 2013
  • by websafe
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

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., (*1)

Provides:, (*2)

Using WebsafeZfModLanguage in Your application

In project's root run:, (*6)

~~~~ bash vendor/bin/composer.phar require "websafe/zf-mod-language:*", (*7)



In `config/application.config.php` add `WebsafeZfModLanguage`: ~~~~ php // ... 'modules' => array( // ... 'Application', 'WebsafeZfModLanguage', // ... ),

That's all. The module should work now - transparently. Test it on the official 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., (*8)

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., (*9)

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:, (*10)

~~~~ php languageSelect();?> ~~~~, (*11)

The view helper is currently the only reason for the Controller to exist., (*12)

Configuration

How locale/language detection is handled.

  1. The module attaches the DetectLanguagesListener to the event manager., (*13)

  2. The DetectLanguagesListener is now waiting for a dispatch event (MvcEvent::EVENT_DISPATCH)..., (*14)

    1. When the dispatch event occurs, DetectLanguagesListener forwards the event to the language service WebsafeZfModLanguageService., (*15)

    2. The language service collects data for locale detection:, (*16)

    • Retrieve languages requested by the client/browser via [Accept-Language] headers. Add all results ordered by priority to the detectedLanguages array., (*17)

    • Retrieve locale stored in cookie (name of cookie is configurable). Prepend the retrieved locale to the front of detectedLanguages., (*18)

    • Retrieve locale stored in session (container name and session variable name are configurable). Prepend the retrieved locale to the front of detectedLanguages., (*19)

    • Retrieve locale provided in query parameter (parameter name is configurable). Prepend the retrieved locale to the front of detectedLanguages., (*20)

    • Retrieve locale provided in route parameter (parameter name is configurable). Prepend the retrieved locale to the front of detectedLanguages., (*21)

    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()., (*22)

    2. The language service applies the current locale to the translator service., (*23)

The Versions

10/12 2013

dev-master

9999999-dev http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

10/12 2013

dev-develop

dev-develop http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

10/12 2013

v0.0.7

0.0.7.0 http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

10/12 2013

v0.0.8

0.0.8.0 http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

10/12 2013

v0.0.6

0.0.6.0 http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

09/12 2013

v0.0.5

0.0.5.0 http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

09/12 2013

v0.0.4

0.0.4.0 http://github.com/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.

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

09/12 2013

v0.0.3

0.0.3.0 http://github.com/websafe/zf-mod-language

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

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting

09/12 2013

v0.0.2

0.0.2.0 http://github.com/websafe/zf-mod-language

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

  Sources   Download

MIT

The Requires

 

The Development Requires

language zf2 module translator locale websafe detecting