This commit is contained in:
gongfuxiang
2023-08-27 16:59:15 +08:00
parent dff4d19e23
commit 636daec54b
1431 changed files with 14160 additions and 231820 deletions

View File

@ -625,11 +625,11 @@ class Devtest extends Common
*/
public function PluginsFanyi()
{
// if(input('pwd') != 'shopxo520')
// {
// die('非法访问');
// }
// die('禁止访问');
if(input('pwd') != 'shopxo520')
{
die('非法访问');
}
die('禁止访问');
// 需要翻译的语言、参考 config/lang.php文件
$to = 'en';
@ -724,6 +724,114 @@ class Devtest extends Common
}
die('success:'.$success.', fail:'.$fail);
}
/**
* 语言翻译生成自定义文件片段
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2023-03-24
* @desc description
*/
public function MyFanyi()
{
if(input('pwd') != 'shopxo520')
{
die('非法访问');
}
die('禁止访问');
// 需要翻译的语言、参考 config/lang.php文件
$to = 'cht';
$to_name = '瑞典语';
// 待翻译的目录
$arr = [
APP_PATH.'lang'.DS,
];
// 获取数据
$zh_data = [];
foreach($arr as $dir)
{
if(!is_dir($dir))
{
continue;
}
$zh_file = $dir.'zh-new.php';
if(!file_exists($zh_file))
{
continue;
}
$temp = require $zh_file;
$zh_data = array_merge($zh_data, $this->FanyiData($temp));
}
// 翻译数据 并 生成数据
$params = [];
$vers = get_class_vars(get_class());
foreach($vers as $k=>$v)
{
if(property_exists($this, $k))
{
$params[$k] = $this->$k;
}
}
$params['data_request']['to'] = $to;
$params['data_request']['q'] = implode("\n", $zh_data);
//$params['data_request']['q'] = "你好\n我是龚";
$fanyi = PluginsControlCall('multilingual', 'index', 'fanyi', 'index', $params, 1);
if(isset($fanyi['code']) && $fanyi['code'] != 0)
{
die($fanyi['msg']);
}
$fanyi_data = (!empty($fanyi['data']) && !empty($fanyi['data']['trans_result'])) ? $fanyi['data']['trans_result'] : [];
if(empty($fanyi_data))
{
die('没有翻译数据');
}
// 替换数据
$search = array_map(function($item)
{
return "'".$item."'";
}, array_column($fanyi_data, 'src'));
$replace = array_map(function($item)
{
return "'".str_replace("'", '', $item)."'";
}, array_column($fanyi_data, 'dst'));
// 加入标题名称
$search[] = '公共语言包-中文';
$search[] = '模块语言包-中文';
$replace[] = '公共语言包-'.$to_name;
$replace[] = '模块语言包-'.$to_name;
// 开始生成文件并替换数据
$success = 0;
$fail = 0;
foreach($arr as $dir)
{
// 复制文件
$zh_file = $dir.'zh-new.php';
if(!file_exists($zh_file))
{
continue;
}
$to_file = $dir.$to.'-new.php';
if(!\base\FileUtil::CopyFile($zh_file, $to_file, true))
{
continue;
}
// 生成文件并替换
$content = file_get_contents($to_file);
if(file_put_contents($to_file, str_replace($search, $replace, $content)) !== false)
{
$success++;
} else {
$fail++;
}
}
die('success:'.$success.', fail:'.$fail);
}
// 翻译数据递归获取
public function FanyiData($data)
{