This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Localization and internationalization in Symfony app

0.2 2017-05-05 21:30 UTC

This package is auto-updated.

Last update: 2021-09-27 19:41:27 UTC



composer.phar require sokil/locale-bundle

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

    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:

        locales_provider: "@locale.supported_locales_provider"