dev-master
9999999-dev https://github.com/rezzza/LocaleVoterBundleFetch locale of project through voters
MIT
The Requires
- php >=5.3.2
The Development Requires
bundle symfony locale
Fetch locale of project through voters
Fetch locale of project through voters., (*1)
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
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)
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'; } } }
Fetch locale of project through voters
MIT
bundle symfony locale