-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
101 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { merge } from 'lodash-es' | ||
{{#REPLACE_IMPORTS}} | ||
import {{importName}} from "{{{path}}}"; | ||
{{/REPLACE_IMPORTS}} | ||
|
||
export default [ | ||
{{#REPLACE_LOCALES}} | ||
{ | ||
locale: "{{locale}}", | ||
message: merge({}, {{importNames}}) | ||
}, | ||
{{/REPLACE_LOCALES}} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
import { glob, winPath } from '@fesjs/utils'; | ||
import { join, basename } from 'path'; | ||
import { glob, winPath } from '@fesjs/utils'; | ||
|
||
const ignore = /\.(d\.ts|\.test\.(js|ts))$/; | ||
|
||
const getRouteName = function (path) { | ||
const routeName = winPath(path); | ||
return routeName | ||
.replace(/\//g, '_') | ||
.replace(/@/g, '_') | ||
.replace(/:/g, '_') | ||
.replace(/-/g, '_') | ||
.replace(/\*/g, 'ALL') | ||
.replace(/\[([a-zA-Z]+)\]/, '_$1') | ||
.replace(/\[...([a-zA-Z]*)\]/, 'FUZZYMATCH-$1'); | ||
}; | ||
|
||
export function getLocales(cwd) { | ||
const files = glob | ||
.sync('*.js', { | ||
cwd, | ||
}) | ||
.filter((file) => !file.endsWith('.d.ts') && !file.endsWith('.test.js') && !file.endsWith('.test.jsx')) | ||
.map((fileName) => { | ||
const map = {}; | ||
const files = []; | ||
glob.sync('**/*.js', { | ||
cwd, | ||
}) | ||
.filter((file) => !ignore.test(file)) | ||
.forEach((fileName) => { | ||
const locale = basename(fileName, '.js'); | ||
const importName = locale.replace('-', ''); | ||
return { | ||
const importName = getRouteName(fileName).replace('.js', ''); | ||
const result = { | ||
importName, | ||
locale, | ||
// import语法的路径,必须处理win | ||
path: winPath(join(cwd, fileName)), | ||
}; | ||
files.push(result); | ||
if (!map[locale]) { | ||
map[locale] = []; | ||
} | ||
map[locale].push(importName); | ||
}); | ||
|
||
return files; | ||
return { | ||
locales: Object.keys(map).map((key) => ({ locale: key, importNames: map[key] })), | ||
files, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
|
||
export default { | ||
home: 'home', | ||
store: 'store', | ||
editor: 'editor', | ||
externalLink: 'externalLink', | ||
mock: 'mock' | ||
mock: 'mock', | ||
test: { | ||
b: 1, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
home: 'home', | ||
test: { | ||
a: 1, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
home: '首页', | ||
test: { | ||
a: 1, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
|
||
export default { | ||
home: '首页', | ||
store: '状态管理', | ||
editor: '编辑器', | ||
externalLink: '外部链接', | ||
mock: '代理' | ||
mock: '代理', | ||
test: { | ||
b: 1, | ||
}, | ||
}; |