2017 © Pedro Peláez
 

library libra-locale

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

image

libra/libra-locale

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  • Friday, July 11, 2014
  • by duke
  • Repository
  • 1 Watchers
  • 4 Stars
  • 873 Installations
  • PHP
  • 2 Dependents
  • 2 Suggesters
  • 2 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

Libra Locale Module

Description

This module adds locale to yours modules. Also it set default locale site-widely. It makes application locale aware, add locale short aliases like usually used en, fr, ru, instead of long locale tags like en-US.UTF8, en-GB etc., (*1)

Note!

You can easily add this module to your project as LibraLocale keep path for default alias and using any things in the same manner., (*2)

Using

For enabling locale add it modules in application configuration. To disable locale behavior for any module add to root level route of module parameter disable_locale => true in routes options, (*3)

    'router' => array(
        'routes' => array(
            'application' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/application',
                    'disable_locale' => true,
                    'constraints' => array(
                        'alias'      => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ),
                    'defaults' => array(
                        ....
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        ....
                    )
                )
            ),
        ....

After this you can get locale alias from RouteMatch parameter. In Controller by code:, (*4)

    $locale = $this->params('locale');
    //or
    $locale = $this->getEvent()->getRouteMatch()->getParam('locale');

It has a switcher, use by router with param 'to' for locale alias:, (*5)

    echo $this->url('libra-locale/switch', array(), array('query' => array('to' => 'en')));
    echo $this->url('libra-locale/switch', array(), array('query' => array('to' => 'ru')));
    echo $this->url('libra-locale/switch', array(), array('query' => array('to' => 'fr')));

Checking if locales was enabled

To disable locales you can:, (*6)

  • Comment out locale_aware option in route. It should assume working for locale '*' or 'All' locales with enabled module.
  • Disable LibraLocale module.

Then to check if application support locales use:, (*7)

    if (\LibraModuleManager\Module::isModulePresent('LibraLocale')) {
        //put code here
    }

Note: I've just realized there may be added a flag in configuration instead of disabling module. Will be implemented on demand., (*8)

Thanks for using it module., (*9)

Installation

It available via composer package libra/libra-locale. - Add to composer.json required list: "libra/libra-locale": "~0.3.0" - Enable module in config/application.config.php module array by adding line: 'LibraLocale', - Copy vendor/libra/libra-locale/config/libra-locale.global.php.dist to config/autoload/libra-locale.global.php - Enable it for wished module as described in use paragraph above., (*10)

Changelog

0.5.0

After some experience I decided to make default locale path as '/' instead of '/locale/' hence of rare changing of default locale. Pages can be duplicated if you have locale extlang subtag like en-US and en-GB - will be almost identical. So search engines should recognize them as same text in different locales (I hope it'll be in future). There added parameters in configuration to setup redirect behavior. Separator hyphen kept (not underscore) due to (http://www.w3.org/International/articles/language-tags/) and (http://en.wikipedia.org/wiki/IETF_language_tag) and (http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html) new standards. The default locale at '/' will do smoother adding locale in projects without locale., (*11)

BC changes: - By enabling this module locales will be added to all http routes. To disable it add 'disable_locale' => true, parameter to custom route., (*12)

Using: - Getting current locale by \Locale::getDefault(); - Getting current locale alias by $this->params('locale'); in controller action. or by \LibraLocale\Module::$alias; - Getting list of available and allowed aliases and locales by: \LibraLocale\Module::getLocales(), (*13)

Added:
Flag redirect_from_locale_tag that allow redirect from locale tag to alias. Now it will accept as alias that almost unknown. By default = false, but for BC it will be true in libra-cms globals until ver. 0.6.0., (*14)

To get proper links by navigation helper use type in page LibraLocale\Navigation\Page\Uri and LibraLocale\Navigation\Page\Mvc. Or use type of page === null and for service container - LibraLocale\Navigation\Service\DefaultNavigationFactory. It can be done by adding in application.config.php file in 'service_manager' array row:, (*15)

            'Navigation' => 'LibraLocale\Navigation\Service\DefaultNavigationFactory',

The Versions

11/07 2014

dev-master

9999999-dev http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

11/07 2014

0.6.1

0.6.1.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

10/07 2014

0.6.0

0.6.0.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

10/07 2014

0.5.3

0.5.3.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

14/09 2013

dev-dev

dev-dev http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

14/09 2013

0.5.2

0.5.2.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

13/09 2013

0.5.1

0.5.1.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

13/09 2013

0.5.0

0.5.0.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

21/07 2013

0.3.2

0.3.2.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

 

by Vitalii Nagara

zf2 cms zendframework zf libra

11/07 2013

0.3.1

0.3.1.0 http://www.ejoom.com/libra-cms/

Zend Framework 2 Locale Module. It detect locale by individual module and transfer parameter 'locale' to its Controller

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

by Vitalii Nagara

zf2 cms zendframework zf libra

09/09 2012

0.3.0

0.3.0.0 http://www.libra-cms.ejoom.com

Locale module for Libra CMS

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

by Vitalii Nagara

zf2 cms zendframework zf libra