File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1062,17 +1062,32 @@ of:
1062
1062
$this->localeSwitcher->reset();
1063
1063
1064
1064
// you can also run some code with a certain locale, without
1065
- // changing the locale for the rest of the application
1065
+ // changing the locale for the rest of the application.
1066
1066
$this->localeSwitcher->runWithLocale('es', function() {
1067
1067
1068
1068
// e.g. render here some Twig templates using 'es' (Spanish) locale
1069
1069
1070
1070
});
1071
1071
1072
+ // you can optionally declare an argument in your callback to receive the
1073
+ // injected locale
1074
+ $this->localeSwitcher->runWithLocale('es', function(string $locale) {
1075
+
1076
+ // here, the $locale argument will be set to 'es'
1077
+
1078
+ });
1079
+
1072
1080
// ...
1073
1081
}
1074
1082
}
1075
1083
1084
+ .. versionadded :: 6.4
1085
+
1086
+ The support of declaring an argument in the callback to inject the locale
1087
+ being used in the
1088
+ :method: `Symfony\\ Component\\ Translation\\ LocaleSwitcher::runWithLocale `
1089
+ method was introduced in Symfony 6.4.
1090
+
1076
1091
When using :ref: `autowiring <services-autowire >`, type-hint any controller or
1077
1092
service argument with the :class: `Symfony\\ Component\\ Translation\\ LocaleSwitcher `
1078
1093
class to inject the locale switcher service. Otherwise, configure your services
You can’t perform that action at this time.
0 commit comments