File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -1073,6 +1073,27 @@ of:
1073
1073
}
1074
1074
}
1075
1075
1076
+ .. tip ::
1077
+
1078
+ If you need to get the locale used in the callback of the
1079
+ ``runWithLocale() `` method, you can declare the ``$locale `` special
1080
+ argument like this::
1081
+
1082
+ public function someMethod(): void
1083
+ {
1084
+ // "es" will be injected in the `$locale` argument when the callback is executed
1085
+ $this->localeSwitcher->runWithLocale('es', function(string $locale) {
1086
+ // ...
1087
+ });
1088
+
1089
+ // ...
1090
+ }
1091
+
1092
+ .. versionadded :: 6.4
1093
+
1094
+ Declaring a ``$locale `` argument in the callback to inject the locale
1095
+ being used was introduced in Symfony 6.4.
1096
+
1076
1097
When using :ref: `autowiring <services-autowire >`, type-hint any controller or
1077
1098
service argument with the :class: `Symfony\\ Component\\ Translation\\ LocaleSwitcher `
1078
1099
class to inject the locale switcher service. Otherwise, configure your services
You can’t perform that action at this time.
0 commit comments