在为zend framework设置翻译的说明中,它以硬编码方式传递区域设置。
我试图在自定义中间件中设置区域设置。由于配置在第一个中间件之前被聚合,所以我不能使该区域设置成为动态的。
https://docs.zendframework.com/tutorials/i18n/
'translator' => [
'locale' => 'en_US',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => getcwd() . '/data/language',
'pattern' => '%s.mo',
],
],
],
我的中间件是这样的:
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$locale = null;
if (isset($_GET[self::LOCALE_GET_NAME])) {
$locale = $_GET[self::LOCALE_GET_NAME];
} else if (!$locale && isset($_COOKIE[self::LOCALE_COOKIE_NAME])) {
$locale = $_COOKIE[self::LOCALE_COOKIE_NAME];
//...
$handler->handle($request->withAttribute(self::LOCALE_ATTRIBUTE_NAME, $locale))
我也试过用
Locale::setDefault()
但是a)被警告不要这样做,因为它不是线程安全的b)它仍然没有在配置聚合器之前得到处理。
我一定是在做什么蠢事。我无法想象这个价值应该是那样的。