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
a71fe96f
Commit
a71fe96f
authored
Dec 30, 2022
by
Marcus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
翻译器
parent
5ea56b38
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
25 deletions
+29
-25
translator.js
translator.js
+29
-25
No files found.
translat
e
r.js
→
translat
o
r.js
View file @
a71fe96f
const
fs
=
require
(
'
fs
'
);
const
root
=
"
./src/views
"
let
root
let
allFiles
=
[]
function
getFiles
(
dir
){
if
(
fs
.
lstatSync
(
dir
).
isDirectory
()){
let
files
=
fs
.
readdirSync
(
dir
)
files
.
forEach
(
file
=>
{
let
path
=
dir
+
'
/
'
+
file
...
...
@@ -12,34 +13,39 @@ function getFiles(dir){
allFiles
.
push
(
path
)
}
})
}
else
{
allFiles
.
push
(
dir
)
}
}
root
=
process
.
argv
.
slice
(
2
)[
0
]
if
(
!
root
)
{
return
console
.
log
(
'
需要带上文件或目录地址,例如:node .
\\
translator.js .
\\
src
\\
views
\\
ecw
\\
order
\\
warehousing
\\
'
)
}
getFiles
(
root
)
// allFiles = [
// // 'src/views/system/user/index.vue',
// 'src/views/bpm/model/index.vue'
// // 'src/views/ecw/financial/receiptDetail.vue'
// ]
console
.
log
(
allFiles
)
console
.
log
(
'
共
'
+
allFiles
.
length
+
'
个文件
'
)
allFiles
.
forEach
(
file
=>
{
let
count
=
0
setTimeout
(()
=>
{
let
data
=
fs
.
readFileSync
(
file
,
{
encoding
:
'
utf-8
'
})
console
.
log
(
'
开始翻译:
'
+
file
)
// 找到 <template>([\w\W]*)<\/template>
data
=
data
.
replace
(
/<template>
([\w\W]
*
)
<
\/
template>/g
,
(
template
)
=>
{
// 匹配标签属性 placeholder="请输入部门名称" 并替换为 :placeholder="$t('请输入部门名称')"
return
template
.
replace
(
/
\w
+="
[^\x
00-
\x
ff
]
+"/g
,
(
word
)
=>
{
count
++
const
wordList
=
word
.
split
(
'
=
'
)
return
'
:
'
+
wordList
[
0
].
substring
(
1
)
+
'
="$t(
\'
'
+
wordList
[
1
].
substring
(
1
,
wordList
[
1
].
length
-
1
)
+
'
\'
)"
'
})
// 匹配标签值 <el-button>取 消</el-button> 并替换为 <el-button>{{ $t('取 消') }}</el-button>
.
replace
(
/>
(\s
*
[^\x
00-
\x
ff
]
+
\s
*
)
+</g
,
(
word
)
=>
{
count
++
return
'
>{{ $t(
\'
'
+
word
.
substring
(
1
,
word
.
length
-
1
).
trim
()
+
'
\'
) }}<
'
})
})
...
...
@@ -50,27 +56,25 @@ allFiles.forEach(file => {
// 单引号字符串 \'(\s*[^\x00-\xff]+\s*)+\' ,其中(?<!([(=]))和(?!\))表示前后没有括号和前=用于防止重复转换
let
s
=
script
.
replace
(
/
(?<
!
([
(=
]))(?<
!
(\$
t
\())
'
[^\x
00-
\x
ff
]
+'
(?!\))
/g
,
s
=>
{
count
++
return
'
this.$t(
'
+
s
+
'
)
'
})
// 双引号字符串 \"(\s*[^\x00-\xff]+\s*)+\"
s
=
s
.
replace
(
/
(?<
!
([
(=
]))
"
[^\x
00-
\x
ff
]
+"
(?!\))
/g
,
s
=>
{
count
++
return
'
this.$t(
'
+
s
+
'
)
'
})
// `字符串 \`(\s*[^\x00-\xff]+\s*)+\`
s
=
s
.
replace
(
/
(?<
!
([
(=
]))
`
[^\x
00-
\x
ff
]
+`
(?!\))
/g
,
s
=>
{
count
++
return
'
this.$t(
'
+
s
+
'
)
'
})
return
s
})
console
.
log
(
'
准备保存:
'
+
file
)
fs
.
writeFileSync
(
file
,
data
)
console
.
log
(
'
已翻译:
'
+
file
)
},
0
)
console
.
log
(
'
[
'
+
file
+
'
]修改
'
+
count
+
'
处
'
)
})
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