切换导航条
此项目
正在载入...
登录
周海龙
/
shopk-main
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
邓超
2 years ago
提交
1bec10cd953d10f687f6397273a8ebda930124b8
1 个父辈
d69c5ab1
翻译
显示空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
79 行增加
和
11 行删除
.gitignore
app/Console/Commands/Demo.php
app/Fun.php
.gitignore
查看文件 @
1bec10c
...
...
@@ -12,3 +12,4 @@ npm-debug.log
yarn-error.log
composer.lock
.idea
resources/lang/auto
...
...
app/Console/Commands/Demo.php
0 → 100644
查看文件 @
1bec10c
<?php
namespace
App\Console\Commands
;
use
App\Fun
;
use
Illuminate\Console\Command
;
class
Demo
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'demo'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Command description'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return int
*/
public
function
handle
()
{
echo
Fun
::
translate
(
"hello' word"
,
'de'
);
}
}
...
...
app/Fun.php
查看文件 @
1bec10c
...
...
@@ -145,21 +145,45 @@ class Fun {
* @author:dc
* @time 2022/11/16 17:43
*/
private
function
translate
(
$texts
,
$tls
){
if
(
is_string
(
$texts
))
{
$texts
=
[
$texts
];
public
static
function
translate
(
$texts
,
$tls
){
static
$langs
=
[];
if
(
!
empty
(
$langs
[
$texts
])){
return
$langs
[
$texts
];
}
if
(
is_string
(
$tls
))
{
$tls
=
[
$tls
];
// 缓存的语言文件
$file
=
resource_path
(
'lang/auto/'
.
$tls
.
'.php'
);
if
(
!
is_file
(
$file
)){
@
mkdir
(
dirname
(
$file
),
0775
,
true
);
file_put_contents
(
$file
,
"<?php"
.
PHP_EOL
);
}
$data
=
[
'texts'
=>
$texts
,
require_once
$file
;
// 已翻译过的
$langs
=
$_lang
??
[];
if
(
!
empty
(
$langs
[
$texts
])){
return
$langs
[
$texts
];
}
$response
=
Http
::
post
(
'https://translate.hbb618.cn/translates'
,
[
'texts'
=>
[
$texts
],
'sl'
=>
'en'
,
'tls'
=>
$tls
,
];
$response
=
Http
::
post
(
'https://translate.hbb618.cn/translates'
,
$data
);
'tls'
=>
[
$tls
],
])
->
json
();
$response
=
$response
[
0
][
'texts'
]
??
''
;
$langs
[
$texts
]
=
$response
;
// 写入文件
file_put_contents
(
$file
,
"
\$
_lang['"
.
str_replace
(
"'"
,
"\'"
,
$texts
)
.
"'] = '"
.
str_replace
(
"'"
,
"\'"
,
$response
)
.
"';"
.
PHP_EOL
,
FILE_APPEND
);
return
$response
->
json
()
;
return
$response
;
}
}
...
...
请
注册
或
登录
后发表评论