2017 © Pedro Peláez
 

symfony-bundle locale-bundle

Raindrop Locale Symfony2 Bundle

image

raindrop/locale-bundle

Raindrop Locale Symfony2 Bundle

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Raindrop Locale Bundle

Build Status, (*1)

This bundle is a fork of LuneticsLocaleBundle which allows you to guess the Locale from different parameters in your Symfony2 applications., (*2)

Installation

Add the package to your dependencies

``` yaml "require": { "raindrop/locale-bundle": "dev-master", .... },, (*3)


### Register the bundle in your kernel ``` php public function registerBundles() { $bundles = array( // ... new Raindrop\LocaleBundle\RaindropLocaleBundle(), );

Update your packages

php composer.phar update raindrop/locale-bundle

Configuration

Allowed locales for your application

You need to define at least one valid locale that is valid for your application, (*4)

``` yaml raindrop_locale: allowed_locales: - en - fr - de, (*5)


#### Strict Mode ``` yaml raindrop_locale: strict_mode: true # defaults to false

You can enable strict_mode, where only the exact allowed locales will be matched. For example:, (*6)

  • If your user has a browser locale with de_DE and de, and you only explicitly allow de, the locale de will be chosen.
  • If your user has a browser locale with de and you only explicitly allow de_DE, no locale will be detected.

We encourage you to use the non-strict mode, that'll also choose the best region locale for your user., (*7)

Guessers

You need to activate and define the order of the locale guessers. This is done in one step in the configuration :, (*8)

``` yaml raindrop_locale: guessing_order: - session - cookie - browser - query - router, (*9)

With the example above, the guessers will be called in the order you defined as 1. session 2. cookie 2. router 3. browser.

Note that the session and cookie guessers only retrieve previously identified and saved locales by the router or browser guesser.

If you use the _locale parameter as attribute/parameter in your routes, you should use the query and router guesser first.

``` yaml
raindrop_locale:
  guessing_order:
    - query
    - router
    - session
    - cookie
    - browser

Locale Cookies / Session

The session and cookie guesser is usually used when you do not use locales in the uri's and you guess it from the user browser preferences. When doing this,, (*10)

it is good to set session and/or cookie as the first guesser to not try to detect the locale at each request., (*11)

If you use the cookie guesser, it will be automatically read from the cookie and write changes into the cookie anytime the locale has changed (Even from another guesser), (*12)

``` yaml raindrop_locale: cookie: set_on_change: true, (*13)

This is most useful for unregistered and returning visitors.

#### Session

The session guesser will automatically save a previously identified locale into the session and retrieve it from the session. This guesser should always be first in your `guessing_order` configuration if you don't use the router guesser.


### FilterLocaleSwitchEvent / LocaleUpdateListener
The `LocaleGuesserManager` dispatches a `LocaleBundleEvents::onLocalChange` if you use either the 'session' or `cookie` guesser. The LocaleUpdateListeners checks if the locale has changed and updates the session or cookie.


For example, if you don't use route / query parameters for locales, you could build an own listener for your user login, which dispatches a `LocaleBundleEvents::onLocalChange` event to set the locale for your user. You just have to use the `FilterLocaleSwitchEvent` and set the locale.

``` php
$locale = $user->getLocale();
$localeSwitchEvent = new FilterLocaleSwitchEvent($locale);
$this->dispatcher->dispatch(LocaleBundleEvents::onLocaleChange, $localeSwitchEvent);

Custom Guessers

Read more about creating your own guesser here:, (*14)

Read the full documentation for creating a custom Locale Guesser, (*15)

Switch to another locale

You can render a default locale switcher, simply by calling the twig function in your template :, (*16)

html {{ locale_switcher() }}, (*17)

Read the full documentation for the switcher, (*18)

The Versions

15/03 2013

dev-develop

dev-develop https://github.com/raindropdevs

Raindrop Locale Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

language cookie locale multilanguage session

15/03 2013

dev-master

9999999-dev https://github.com/raindropdevs

Raindrop Locale Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

language cookie locale multilanguage session

01/03 2013

01.04.02

01.04.02.0 https://github.com/raindropdevs

Raindrop Locale Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

language cookie locale multilanguage session

03/02 2013

01.01.00

01.01.00.0

Raindrop Locale Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

language cookie locale multilanguage session