Override the locale string UF provides to a legal language identifier [ZN-MDD-14]
This commit is contained in:
@@ -18,6 +18,7 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use UserFrosting\Sprinkle\Core\Log\MixedFormatter;
|
||||
use UserFrosting\Sprinkle\UFTweaks\Twig\HasRoleExtension;
|
||||
use UserFrosting\Sprinkle\UFTweaks\Twig\LocaleOverrideExtension;
|
||||
use UserFrosting\Sprinkle\UFTweaks\Twig\MobileDetectExtension;
|
||||
use UserFrosting\Sprinkle\UFTweaks\Mail\RetryMailer;
|
||||
|
||||
@@ -185,6 +186,7 @@ class ServicesProvider
|
||||
|
||||
$twig->addExtension(new HasRoleExtension($c));
|
||||
$twig->addExtension(new MobileDetectExtension($c));
|
||||
$twig->addExtension(new LocaleOverrideExtension($c));
|
||||
|
||||
return $view;
|
||||
});
|
||||
|
||||
52
src/Twig/LocaleOverrideExtension.php
Normal file
52
src/Twig/LocaleOverrideExtension.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AVSDev UF Tweaks (https://avsdev.uk)
|
||||
*
|
||||
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
|
||||
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
|
||||
*/
|
||||
|
||||
namespace UserFrosting\Sprinkle\UFTweaks\Twig;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Extension\GlobalsInterface;
|
||||
|
||||
/**
|
||||
* Overrides the page language to 'en' only
|
||||
*/
|
||||
class LocaleOverrideExtension extends AbstractExtension implements GlobalsInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $services;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $services
|
||||
*/
|
||||
public function __construct(ContainerInterface $services)
|
||||
{
|
||||
$this->services = $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Twig global variable 'currentLocale'
|
||||
*
|
||||
* @return array[mixed]
|
||||
*/
|
||||
public function getGlobals(): array
|
||||
{
|
||||
$locale = $this->services->locale->getLocaleIndentifier();
|
||||
$parts = explode('_', $locale) ?: [];
|
||||
return [
|
||||
'currentLocale' => $parts[0]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user