sokil/locale-bundle

Localization and internationalization in Symfony app

0.2 2017-05-05 21:30 UTC

This package is auto-updated.

Last update: 2024-11-28 02:19:01 UTC


README

Installation

composer.phar require sokil/locale-bundle

Configure next parameters in ./app/config/config.yml:

locale:
    query_parameter: lang
    cookie_parameter: lang
    path_parameter: false
    locales: # mapping of languages to locales
        uk: uk_UA.utf8
        en: en_US.utf8

Current language resolving

Servise locale.preferred_language_listener used to set current language from cookie, request URL or Accept-Language request header. It enabled by default, if bundle registered.

Switch languages

Action setAction from controller Sokil\LocaleBundle\Controller\LangController used to set current lang.

Locales provider

Service locale.supported_locales_provider used to get list of all supported languages with localised names of language.

To access locales provider from twig template, add global twig variable in ./app/config/config.yaml:

twig:
    globals:
        locales_provider: "@locale.supported_locales_provider"