Files
weipan02_server/application/common.php
你的名字 0483b4b364 1
2025-07-14 10:22:40 +08:00

27 lines
848 B
PHP

<?php
if (!function_exists('json_lang')) {
/**
* 从 JSON 文件中加载语言包
*
* @param string $key 语言包的键
* @param string $lang 语言类型,默认为当前语言
* @return mixed 返回对应的语言值
*/
function json_lang($key, $lang = '') {
$lang = \think\facade\Lang::detect();
// 拼接文件路径
$filePath = '../application/lang' . DIRECTORY_SEPARATOR . $lang . '.json';
// 判断文件是否存在
if (file_exists($filePath)) {
// 读取 JSON 文件并解析为数组
$data = json_decode(file_get_contents($filePath), true);
if (isset($data[$key])) {
return $data[$key];
}
}
// 如果没有找到对应的键,则返回原始键
return $key;
}
}