2017 © Pedro Peláez
 

symfony-bundle locale-voter-bundle

Fetch locale of project through voters

image

rezzza/locale-voter-bundle

Fetch locale of project through voters

  • Tuesday, November 20, 2012
  • by steph_py
  • Repository
  • 2 Watchers
  • 5 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

LocaleVoterBundle

DEPRECATED

Use LocaleBundle instead.

Fetch locale of project through voters., (*1)

Installation

Using composer:, (*2)

    "rezzza/locale-voter-bundle": "1.0.*",

Then, (*3)

composer update "rezzza/locale-voter-bundle"

Add on you AppKernel:, (*4)

    $bundles = array(
        ...
        new Rezzza\LocaleVoterBundle\RezzzaLocaleVoterBundle(),
        ...
    )

Define configuration on your config.yml:, (*5)

rezzza_locale_voter:
    strategy: request        # only one strategy available, you can set null to manually decide of locale.
    default_locale: %locale% # set fallback locale.
    locales: ['en', 'fr']    # Define valid locales.
    voters:                  # A list of voter. Order define priority.
        - rezzza.locale_voter.request_parameter.voter
        - rezzza.locale_voter.accept_language.voter

Usage

With default configuration defined above, it'll look at _locale GET parameter in first time, if it does not match, it will look at accept language headers. locale voted (defined on voters on default) will be setted on request., (*6)

You can easily define new voters or define your own strategy., (*7)

Write a Voter

You have just to inherit from VoterInterface and add the service id of the voter on the configuration., (*8)

Example of voter:, (*9)

<?php

namespace Acme\DoudaBundle\Locale\Voter;

use Rezzza\LocaleVoterBundle\Locale\Context\LocaleContextInterface;
use Rezzza\LocaleVoterBundle\Locale\Voter\AbstractVoter;

class MyVoter extends AbstractVoter implements VoterInterface
{
    /**
     * {@inheritdoc}
     */
    public function vote(LocaleContextInterface $context)
    {
        $request = $context->getRequest();

        // suggestLocale will check if locale is supported.
        if ($request->get('chuck') === 'testa' && $this->suggestLocale('NOPE')) {
            return 'NOPE';
        }
    }

}

Todo

  • Write tests.

The Versions

20/11 2012

dev-master

9999999-dev https://github.com/rezzza/LocaleVoterBundle

Fetch locale of project through voters

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

bundle symfony locale