2017 © Pedro Peláez
 

library zf-linguo

Zend Framework 2 Module that provides multi-language routes capability

image

agopaul/zf-linguo

Zend Framework 2 Module that provides multi-language routes capability

  • Sunday, July 19, 2015
  • by agopaul
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Linguo

True multi-lingual routes support for ZF2, (*1)

This zf2 module helps dealing with fully-localized URLS, (*2)

Example

Consider you have an action with two completely localized URLs, (*3)

GET /en/contacts
GET /it/contatti

module/Application/config/config.php, (*4)

<?php
return array(
    "router" => array(
        "router_class" => "Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack", // Add this
        'routes' => => array(

            // Route
            'contacts' => array(
                'type' => 'Linguo\Library\Mvc\Router\Http\MultiLangSegment', // Change this
                'options' => array(
                    'route' => '/:lang/{contacts}',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller' => 'Site',
                        'action' => 'contacts'
                    ),
                ),
            ),

        ),
    ),
);

Configuration

config/application.config.php, (*5)

<?php
return array(
    'modules' => array(
        'Linguo',

        // Your modules here
    )
)

config/autoload/linguo.php, (*6)

"linguo" => array(
    "langMap" => array(
        // locale - slug pair
        "en_US" => "en",
        "it_IT" => "it",
    )
)

module/Application/Module.php, (*7)

<?php
/**
 * On bootstrap
 * @param MvcEvent $e
 */
public function onBootstrap(MvcEvent $e){

    /* @var $eventManager EventManager */
    $eventManager = $e->getApplication()->getEventManager();

    // Set translator locale based on the request URL
    $eventManager->attach($this->getServiceLocator()->get('Linguo\Library\Translator\SetLocaleFromUrlStrategy'));
}

Limitations

  • The language parameter must be named :lang
  • The route isn't very optimized (for conservative reasons), it might be slower than the Segment route.

The Versions

19/07 2015

dev-master

9999999-dev https://www.github.com/agopaul/zf-linguo

Zend Framework 2 Module that provides multi-language routes capability

  Sources   Download

The Requires

  • php >=5.4

 

The Development Requires

zf2 module i18n