@@ -615,6 +615,73 @@ To add a new rendering strategy - in addition to the core strategies like
615615:class: `Symfony\\ Component\\ HttpKernel\\ Fragment\\ FragmentRendererInterface `,
616616register it as a service, then tag it with ``kernel.fragment_renderer ``.
617617
618+ kernel.locale_aware
619+ -------------------
620+
621+ **Purpose **: To access and use the current :doc: `locale </translation/locale >`
622+
623+ Setting and retrieving the locale can be done via configuration or using
624+ container parameters, listeners, route parameters or the current request.
625+
626+ Thanks to the ``Translation `` contract, the locale can be set via services.
627+
628+ To register your own locale aware service, first create a service that implements
629+ the :class: `Symfony\\ Contracts\\ Translation\\ LocaleAwareInterface ` interface::
630+
631+ // src/Locale/MyCustomLocaleHandler.php
632+ namespace App\Locale;
633+
634+ use Symfony\Contracts\Translation\LocaleAwareInterface;
635+
636+ class MyCustomLocaleHandler implements LocaleAwareInterface
637+ {
638+ public function setLocale($locale)
639+ {
640+ $this->locale = $locale;
641+ }
642+
643+ public function getLocale()
644+ {
645+ return $this->locale;
646+ }
647+ }
648+
649+ If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
650+ your service will be automatically tagged with ``kernel.locale_aware ``. But, you
651+ can also register it manually:
652+
653+ .. configuration-block ::
654+
655+ .. code-block :: yaml
656+
657+ services :
658+ App\Locale\MyCustomLocaleHandler :
659+ tags : [kernel.locale_aware]
660+
661+ .. code-block :: xml
662+
663+ <?xml version =" 1.0" encoding =" UTF-8" ?>
664+ <container xmlns =" http://symfony.com/schema/dic/services"
665+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
666+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
667+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
668+
669+ <services >
670+ <service id =" App\Locale\MyCustomLocaleHandler" >
671+ <tag name =" kernel.locale_aware" />
672+ </service >
673+ </services >
674+ </container >
675+
676+ .. code-block :: php
677+
678+ use App\Locale\MyCustomLocaleHandler;
679+
680+ $container
681+ ->register(LocaleHandler::class)
682+ ->addTag('kernel.locale_aware')
683+ ;
684+
618685 kernel.reset
619686------------
620687
0 commit comments