Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-app-operator-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanbaoming
jiedao-app-operator-master
Commits
089e73bd
Commit
089e73bd
authored
Jan 06, 2024
by
dragondean@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善翻译
parent
18983f23
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
190 additions
and
20 deletions
+190
-20
collectI18nMessages.js
collectI18nMessages.js
+31
-19
en_US.json
src/i18n/languages/en_US.json
+159
-1
No files found.
collectI18nMessages.js
View file @
089e73bd
...
@@ -40,26 +40,30 @@ const translateText = (text, fromLang = 'zh', toLang = 'en') => {
...
@@ -40,26 +40,30 @@ const translateText = (text, fromLang = 'zh', toLang = 'en') => {
'
Content-Length
'
:
querystring
.
stringify
(
params
).
length
'
Content-Length
'
:
querystring
.
stringify
(
params
).
length
}
}
};
};
try
{
const
req
=
https
.
request
(
options
,
(
res
)
=>
{
const
req
=
https
.
request
(
options
,
(
res
)
=>
{
let
data
=
''
;
let
data
=
''
;
res
.
on
(
'
data
'
,
(
chunk
)
=>
{
res
.
on
(
'
data
'
,
(
chunk
)
=>
{
data
+=
chunk
;
data
+=
chunk
;
});
res
.
on
(
'
end
'
,
()
=>
{
console
.
log
(
'
翻译结果:
'
,
data
);
resolve
(
JSON
.
parse
(
data
).
trans_result
[
0
].
dst
)
});
});
});
res
.
on
(
'
end
'
,
()
=>
{
req
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
'
翻译结果:
'
,
data
);
console
.
error
(
err
);
resolve
(
JSON
.
parse
(
data
).
trans_result
[
0
].
dst
)
});
});
});
req
.
on
(
'
error
'
,
(
err
)
=>
{
req
.
write
(
querystring
.
stringify
(
params
));
console
.
error
(
err
);
req
.
end
();
});
}
catch
(
e
)
{
console
.
log
(
text
+
"
翻译失败:
"
+
e
)
}
req
.
write
(
querystring
.
stringify
(
params
));
req
.
end
();
})
})
};
};
...
@@ -96,10 +100,18 @@ async function translate(obj){
...
@@ -96,10 +100,18 @@ async function translate(obj){
// 对未翻译内容调用百度翻译进行翻译操作,有变量的不做处理
// 对未翻译内容调用百度翻译进行翻译操作,有变量的不做处理
for
(
let
text
in
obj
){
for
(
let
text
in
obj
){
if
(
obj
[
text
]
||
text
.
includes
(
'
{
'
))
continue
if
(
obj
[
text
]
||
text
.
includes
(
'
{
'
))
continue
const
textEn
=
await
translateText
(
text
)
try
{
console
.
log
(
`
${
text
}
=>
${
textEn
}
\n`
)
const
textEn
=
await
translateText
(
text
)
obj
[
text
]
=
textEn
console
.
log
(
`
${
text
}
=>
${
textEn
}
\n`
)
autoTransCnt
++
obj
[
text
]
=
textEn
autoTransCnt
++
// 每次翻译后保存一次,防止意外退出导致的数据丢失
fs
.
writeFileSync
(
savePath
,
JSON
.
stringify
(
obj
,
null
,
4
))
}
catch
(
e
)
{
console
.
log
(
text
+
"
翻译失败:
"
+
e
)
}
// 账号请求频率限制1ps
// 账号请求频率限制1ps
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
1000
))
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
1000
))
...
...
src/i18n/languages/en_US.json
View file @
089e73bd
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment