首页 > 解决方案 > 使用 Laravel 5.8 获​​取所有本地化字符串

问题描述

如何获取文件语言的所有本地化字符串?

当我使用Lang::get();时,我得到一个错误。我需要获取组密钥。但是我怎样才能得到所有的语言字符串,以及组和键呢?

标签: phplaravel

解决方案


在您的config/filesystems.php文件中添加以下内容:

'lang' => [
        'driver' => 'local',
        'root' => base_path('resources/lang/en'),
    ],

然后,您可以使用此磁盘遍历所有文件,并从每个文件中获取内容:

foreach (Storage::disk('lang')->files('') as $file)
{
    dd(Lang::get(explode('.php', $file)[0])); // you can use something else then explode to get just the name of the file without the extension
}

推荐阅读