PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
← All changes | app/Http/Middleware/SetLocale.php +24 -0 2.0.1 → 2.1.1 View file →
@@ -1,0 +1,24 @@
1 +<?php
2 +
3 +declare(strict_types=1);
4 +
5 +namespace Metricool\Http\Middleware;
6 +
7 +use Metricool\Vendor\Carbon\Carbon;
8 +use Metricool\Interfaces\MiddlewareInterface;
9 +
10 +/**
11 + * Set the locale for the current request. The locale is determined by the user's locale, or the site's locale if the user is not logged in.
12 + */
13 +class SetLocale implements MiddlewareInterface
14 +{
15 + public function handle(\WP_REST_Request $request, callable $next)
16 + {
17 + $locale = get_user_locale() ?: get_locale();
18 + switch_to_locale($locale);
19 +
20 + Carbon::setLocale($locale);
21 +
22 + return $next($request);
23 + }
24 +}