插件语言读取优化

feat/task1-c-wallet
gongfuxiang 2023-05-07 23:16:02 +08:00
parent c348d32266
commit dc94722dac
1 changed files with 15 additions and 13 deletions

View File

@ -199,25 +199,26 @@ function MyLang($key, $vars = [], $lang = '', $plugins = '')
// 是否插件语言、未指定则处理 // 是否插件语言、未指定则处理
if(empty($plugins)) if(empty($plugins))
{ {
$pluginsname = MyInput('pluginsname'); // 获取最新一条回溯跟踪
if(empty($pluginsname) && RequestController() != 'plugins') $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
if(!empty($backtrace) && !empty($backtrace[0]) && !empty($backtrace[0]['file']))
{ {
// 获取最新一条回溯跟踪 $str = 'app/plugins/';
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); $loc = stripos($backtrace[0]['file'], $str);
if(!empty($backtrace) && !empty($backtrace[0]) && !empty($backtrace[0]['file'])) if($loc !== false)
{ {
$str = 'app/plugins/'; $temp = explode($str, $backtrace[0]['file']);
$loc = stripos($backtrace[0]['file'], $str); if(count($temp) > 1)
if($loc !== false)
{ {
$temp = explode($str, $backtrace[0]['file']); $pluginsname = explode('/', $temp[1])[0];
if(count($temp) > 1)
{
$pluginsname = explode('/', $temp[1])[0];
}
} }
} }
} }
// 空则参数读取
if(empty($pluginsname))
{
$pluginsname = MyInput('pluginsname');
}
} else { } else {
$pluginsname = $plugins; $pluginsname = $plugins;
} }
@ -225,6 +226,7 @@ function MyLang($key, $vars = [], $lang = '', $plugins = '')
{ {
$plugins_dir = APP_PATH.'plugins'.DS.$pluginsname.DS.'lang'.DS; $plugins_dir = APP_PATH.'plugins'.DS.$pluginsname.DS.'lang'.DS;
array_unshift($arr_file, $plugins_dir.$current_lang.'.php'); array_unshift($arr_file, $plugins_dir.$current_lang.'.php');
array_unshift($arr_file, $plugins_dir.'common'.DS.$current_lang.'.php');
array_unshift($arr_file, $plugins_dir.$request_module.DS.$current_lang.'.php'); array_unshift($arr_file, $plugins_dir.$request_module.DS.$current_lang.'.php');
} }