我在 PHP 数组中有一组翻译。使用 Oscarotero 的 gettext 库,我收到错误:
"Cannot redeclare __() (previously declared in D:\LocaleTesting\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:907)" when the execution of the code $t->register()
$aTranslation = Translations::fromJsonFile(public_path() . '/locale/'.$sLocale.'/LC_MESSAGES/admin.json');
$oTranslator = new Translator();
$oTranslator->loadTranslations($aTranslation);
$oTranslator->register();
此外,我搜索到此错误仅在您的 Laravel 版本为 5.4 及以上版本时才会发生。任何帮助都可以。谢谢你!请Oscarotero/gettext的 github 以获取有关该库的更多信息。
最佳答案
这似乎是库的一个已知问题: https://github.com/oscarotero/Gettext/issues/180
解决这个问题的一种方法是在加载 laravel 助手之前加载翻译器函数(上述问题的解决方案):
I'm using the package with a require before
vendor/autoload.php
onpublic/index.php
andartisan
command.# public/index.php require __DIR__.'/../vendor/gettext/gettext/src/translator_functions.php'; require __DIR__.'/../vendor/autoload.php';
# artisan require __DIR__.'/vendor/gettext/gettext/src/translator_functions.php'; require __DIR__.'/vendor/autoload.php';
关于php - 使用 oscarotero/gettext 翻译库时无法重新声明 Laravel 的 __() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57156029/