想了个折衷的办法 勉强算是解决了语言包的问题
define('ES_LANG', i18nInit());
//初始化
function i18nInit()
{
$langs = ['zh-cn', 'en-us'];
$i18n = [];
$divider = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' ? '\\' : '/';
foreach ($langs as $l => $lang) {
$file = getBasePath() . "{$divider}resource{$divider}translations{$divider}{$lang}{$divider}messages.json";
if (is_file($file)) {
$result = json_decode(file_get_contents($file), true) ?: [];
$i18n[$lang] = array_change_key_case($result);
}
}
return $i18n;
}
//base_path
function getBasePath()
{
$path = base_path();
if (strpos($path, 'phar://') === 0) {
$parts = explode('/', $path);
$package = array_pop($parts);
return substr($path, 7, - (strlen($package) + 1));
} else {
return $path;
}
}
//调用
function lang(string $set, string $lang = null)
{
$_lang = $lang ?: request()->header('lang') ?: 'zh-cn';
return $set ? (ES_LANG[$_lang][$set] ?: $set) : '';
}
接下来再看看怎么做个内部重启的按钮
语言包不能放bin外面