Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DoorLock
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
朱建香
DoorLock
Commits
2f8c449e
Commit
2f8c449e
authored
Mar 09, 2018
by
朱建香
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
4
parent
cab2ddcc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
0 deletions
+108
-0
custom/custom01/config/lang.js
+9
-0
custom/custom01/core/I18NPackage.js
+99
-0
No files found.
custom/custom01/config/lang.js
0 → 100644
View file @
2f8c449e
const
path
=
require
(
'path'
);
const
srcPath
=
path
.
join
(
__dirname
,
".."
,
"src"
);
const
outputPath
=
"../resources/lang/"
;
module
.
exports
=
{
lang
:[
"zh"
,
"en"
],
group
:
srcPath
,
output
:
outputPath
};
\ No newline at end of file
custom/custom01/core/I18NPackage.js
0 → 100644
View file @
2f8c449e
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
config
=
require
(
'../config/lang'
);
const
srcPath
=
path
.
join
(
__dirname
,
".."
,
"src"
);
const
langPath
=
path
.
join
(
srcPath
,
"lang"
);
const
componentPath
=
path
.
join
(
srcPath
,
"lang"
,
"component"
);
let
allFilePath
=
[];
function
getAllLang
(...
dirs
){
let
langGroup
=
{};
for
(
let
dir
of
dirs
){
if
(
fs
.
existsSync
(
dir
)){
for
(
let
lang
of
config
.
lang
){
let
lPath
=
path
.
join
(
dir
,
"/"
,
`
${
lang
}
.json`
);
if
(
fs
.
existsSync
(
lPath
)){
let
arr
;
if
(
langGroup
[
lang
]
!=
null
){
arr
=
langGroup
[
lang
];
}
else
{
arr
=
new
Array
();
}
arr
.
push
(
lPath
);
langGroup
[
lang
]
=
arr
;
allFilePath
.
push
(
lPath
);
}
}
}
}
return
langGroup
;
}
let
langGroup
;
const
watch
=
require
(
'watch'
);
class
I18NPackage
{
constructor
(
options
){
this
.
options
=
options
;
this
.
watching
=
false
;
}
apply
(
compiler
){
langGroup
=
getAllLang
(
langPath
,
componentPath
);
compiler
.
plugin
(
"watch-run"
,
(
compilation
,
callback
)
=>
{
if
(
!
this
.
watching
){
this
.
watching
=
true
;
langGroup
=
getAllLang
(
langPath
,
componentPath
);
const
onChange
=
()
=>
{
langGroup
=
getAllLang
(
langPath
,
componentPath
);
compiler
.
run
((
err
)
=>
{
if
(
err
)
{
throw
err
;
}
});
};
watch
.
createMonitor
(
srcPath
,
(
monitor
)
=>
{
monitor
.
files
[
path
.
join
(
srcPath
,
".json"
)];
monitor
.
on
(
"created"
,
onChange
);
monitor
.
on
(
"changed"
,
onChange
);
monitor
.
on
(
"removed"
,
onChange
);
callback
();
});
}
});
compiler
.
plugin
(
'emit'
,
function
(
compilation
,
callback
)
{
let
createFileName
=
[];
try
{
for
(
let
key
of
Object
.
keys
(
langGroup
)){
let
path
=
langGroup
[
key
];
let
obj
=
{};
for
(
let
filePath
of
path
){
obj
=
Object
.
assign
(
obj
,
JSON
.
parse
(
fs
.
readFileSync
(
filePath
,
'utf8'
)));
}
let
filelist
=
JSON
.
stringify
(
obj
);
// Insert this list into the Webpack build as a new file asset:
let
fileName
=
`../resources/lang/
${
key
}
.json`
;
compilation
.
assets
[
fileName
]
=
{
source
:
function
()
{
return
filelist
;
},
size
:
function
()
{
return
filelist
.
length
;
}
};
createFileName
.
push
(
fileName
);
}
}
catch
(
err
){
console
.
log
(
err
)
}
console
.
log
(
"lang file merge success."
)
for
(
let
file
of
createFileName
){
console
.
log
(
file
)
}
callback
();
});
}
}
module
.
exports
=
I18NPackage
;
\ No newline at end of file
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