@@ -639,6 +639,77 @@ To add a new rendering strategy - in addition to the core strategies like
639639:class: `Symfony\\ Component\\ HttpKernel\\ Fragment\\ FragmentRendererInterface `,
640640register it as a service, then tag it with ``kernel.fragment_renderer ``.
641641
642+ kernel.locale_aware
643+ -------------------
644+
645+ .. versionadded :: 4.3
646+
647+ The ``kernel.locale_aware `` tag was introduced in Symfony 4.3.
648+
649+ **Purpose **: To access and use the current :doc: `locale </translation/locale >`
650+
651+ Setting and retrieving the locale can be done via configuration or using
652+ container parameters, listeners, route parameters or the current request.
653+
654+ Thanks to the ``Translation `` contract, the locale can be set via services.
655+
656+ To register your own locale aware service, first create a service that implements
657+ the :class: `Symfony\\ Contracts\\ Translation\\ LocaleAwareInterface ` interface::
658+
659+ // src/Locale/MyCustomLocaleHandler.php
660+ namespace App\Locale;
661+
662+ use Symfony\Contracts\Translation\LocaleAwareInterface;
663+
664+ class MyCustomLocaleHandler implements LocaleAwareInterface
665+ {
666+ public function setLocale($locale)
667+ {
668+ $this->locale = $locale;
669+ }
670+
671+ public function getLocale()
672+ {
673+ return $this->locale;
674+ }
675+ }
676+
677+ If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
678+ your service will be automatically tagged with ``kernel.locale_aware ``. But, you
679+ can also register it manually:
680+
681+ .. configuration-block ::
682+
683+ .. code-block :: yaml
684+
685+ services :
686+ App\Locale\MyCustomLocaleHandler :
687+ tags : [kernel.locale_aware]
688+
689+ .. code-block :: xml
690+
691+ <?xml version =" 1.0" encoding =" UTF-8" ?>
692+ <container xmlns =" http://symfony.com/schema/dic/services"
693+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
694+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
695+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
696+
697+ <services >
698+ <service id =" App\Locale\MyCustomLocaleHandler" >
699+ <tag name =" kernel.locale_aware" />
700+ </service >
701+ </services >
702+ </container >
703+
704+ .. code-block :: php
705+
706+ use App\Locale\MyCustomLocaleHandler;
707+
708+ $container
709+ ->register(LocaleHandler::class)
710+ ->addTag('kernel.locale_aware')
711+ ;
712+
642713 kernel.reset
643714------------
644715
0 commit comments