Locale Helper
=============

The locale helper provides functions to display:
 - country name from the ISO code
 - language name from the ISO code
 - locale name from the ISO code

Detection
---------

The SonataIntlBundle provides a service to automatically detect the user's locale.
``sonata.intl.locale_detector`` will be session-based if you're using Symfony < 2.1.x ; request-based otherwise.

You'll need to handle the locale setting however (in request or session, depending on your Symfony version).


Twig usage
----------

By default, if the second argument is not set then the current locale value is
retrieved by using the request instance.


.. code-block:: jinja

    {{ 'FR' | country }} {# => France (if the current locale in session is 'fr') #}
    {{ 'FR' | country('de') }} {# => Frankreich (force the locale) #}

    {{ 'fr' | language }} => {# français (if the current locale in session is 'fr') #}
    {{ 'fr' | language('en') }} {# => French (force the locale) #}

    {{ 'fr' | locale }} {# => français (if the current locale in session is 'fr') #}
    {{ 'fr' | locale('en') }} {# => French (force the locale) #}
                                                                                                                                                                                                                                                                                                                                                                                                            Configuration
=============

To display dates, this bundle uses timezone detectors to get the
current timezone.

User timezone detector
----------------------

If the SonataUserBundle is enabled, it returns the timezone from the
``Sonata\UserBundle\Modle\User::getTimezone()`` method.


Locale timezone detector
------------------------

The timezone is guessed from the current request locale. You can
configure the locale / timezone mapping in the configuration:

.. code-block:: yaml

    sonata_intl:
        timezone:
            locales:
                fr:    Europe/Paris
                en_UK: Europe/London


Configure timezone detectors
----------------------------

By default, ``user`` then ``locale`` timezone detectors are used. You
can change this in the config:

.. code-block:: yaml

    sonata_intl:
        timezone:
            detectors:
                - sonata.intl.timezone_detector.user
                - sonata.intl.timezone_detector.locale

**IMPORTANT** In order to guess the timezone, the detectors will be
called **in the order they are declared**.


Default timezone
----------------

If no timezone was returned by any detector, a default one will be
returned (from the ``date_default_timezone_get()`` method, configurable
in the ``php.ini`` file).

You can override this default timezone in the configuration:

.. code-block:: yaml

    sonata_intl:
        timezone:
            default: Europe/Paris
