[已解决]多语言报错TypeError

EchoNoch

问题已解决

是手册中

#所有的语言文件都是返回一个数组例如:
// resource/translations/en/messages.php

return [
    'hello' => 'Hello webman',
];

需要加入<?php
改为

// resource/translations/en/messages.php
<?php
return [
    'hello' => 'Hello webman',
];

问题描述

模板中使用多语言时报错

TypeError: Symfony\Component\Translation\Loader\PhpFileLoader::loadResource(): Return value must be of type array, int returned in /vendor/symfony/translation/Loader/PhpFileLoader.php:33

程序代码

trans('login');

报错信息

TypeError: Symfony\Component\Translation\Loader\PhpFileLoader::loadResource(): Return value must be of type array, int returned in /vendor/symfony/translation/Loader/PhpFileLoader.php:33

截图报错信息里报错文件相关代码

#报错文件,错误发生在此处的18行 return require $resource;

namespace Symfony\Component\Translation\Loader;
class PhpFileLoader extends FileLoader
{
    private static ?array $cache = [];

    /**
     * {@inheritdoc}
     */
    protected function loadResource(string $resource): array
    {
        if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOLEAN))) {
            self::$cache = null;
        }

        if (null === self::$cache) {
            return require $resource;
        }

        if (isset(self::$cache[$resource])) {
            return self::$cache[$resource];
        }

        return self::$cache[$resource] = require $resource;
    }
}

操作系统及workerman/webman等框架组件具体版本

最新版本webman
环境为php80 opcache已开启 原生模板
语言包已建立且无误

585 0 0
0个回答

年代过于久远,无法发表回答
🔝