Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
0ebdc0ce
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0ebdc0ce
编写于
9月 13, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(i18n): add uni-app.*.json
上级
1fc4725b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
98 addition
and
42 deletion
+98
-42
packages/uni-cli-shared/lib/i18n.js
packages/uni-cli-shared/lib/i18n.js
+35
-8
packages/uni-migration/bin/uni-migration.js
packages/uni-migration/bin/uni-migration.js
+1
-1
packages/webpack-uni-pages-loader/lib/index-new.js
packages/webpack-uni-pages-loader/lib/index-new.js
+21
-9
packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
.../webpack-uni-pages-loader/lib/platforms/app-plus/index.js
+40
-23
packages/webpack-uni-pages-loader/lib/platforms/h5.js
packages/webpack-uni-pages-loader/lib/platforms/h5.js
+1
-1
未找到文件。
packages/uni-cli-shared/lib/i18n.js
浏览文件 @
0ebdc0ce
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
parseJson
}
=
require
(
'
./json
'
)
const
{
getManifestJson
}
=
require
(
'
./manifest
'
)
const
{
parseJson
}
=
require
(
'
./json
'
)
const
{
getManifestJson
}
=
require
(
'
./manifest
'
)
const
delimiters
=
[
'
%
'
,
'
%
'
]
...
...
@@ -36,17 +40,40 @@ function initI18nOptions (
}
}
const
localeJsonRE
=
/uni-app.*.json/
function
isUniAppLocaleFile
(
filepath
)
{
if
(
!
filepath
)
{
return
false
}
return
localeJsonRE
.
test
(
path
.
basename
(
filepath
))
}
function
parseLocaleJson
(
filepath
)
{
let
jsonObj
=
parseJson
(
fs
.
readFileSync
(
filepath
,
'
utf8
'
))
if
(
isUniAppLocaleFile
(
filepath
))
{
jsonObj
=
jsonObj
.
common
||
{}
}
return
jsonObj
}
function
initLocales
(
dir
,
withMessages
=
true
)
{
if
(
!
fs
.
existsSync
(
dir
))
{
return
{}
}
return
fs
.
readdirSync
(
dir
).
reduce
((
res
,
filename
)
=>
{
if
(
path
.
extname
(
filename
)
===
'
.json
'
)
{
try
{
res
[
path
.
basename
(
filename
).
replace
(
'
.json
'
,
''
)]
=
withMessages
?
parseJson
(
fs
.
readFileSync
(
path
.
join
(
dir
,
filename
),
'
utf8
'
))
:
{}
}
catch
(
e
)
{}
const
locale
=
path
.
basename
(
filename
)
.
replace
(
/
(
uni-app.
)?(
.*
)
.json/
,
'
$2
'
)
if
(
withMessages
)
{
Object
.
assign
(
res
[
locale
]
||
(
res
[
locale
]
=
{}),
parseLocaleJson
(
path
.
join
(
dir
,
filename
))
)
}
else
{
res
[
locale
]
=
{}
}
}
return
res
},
{})
...
...
@@ -69,4 +96,4 @@ function resolveI18nLocale (platfrom, locales, locale) {
module
.
exports
=
{
initLocales
,
initI18nOptions
}
}
packages/uni-migration/bin/uni-migration.js
100644 → 100755
浏览文件 @
0ebdc0ce
#!/usr/bin/env node
#!/usr/bin/env node
const
path
=
require
(
'
path
'
)
const
Program
=
require
(
'
commander
'
)
...
...
packages/webpack-uni-pages-loader/lib/index-new.js
浏览文件 @
0ebdc0ce
...
...
@@ -16,7 +16,10 @@ const {
updateProjectJson
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
)
const
{
initTheme
,
parseTheme
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/theme
'
)
const
{
initTheme
,
parseTheme
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/theme
'
)
const
{
// pagesJsonJsFileName,
...
...
@@ -27,11 +30,15 @@ const uniI18n = require('@dcloudio/uni-cli-i18n')
const
parseStyle
=
require
(
'
./util
'
).
parseStyle
const
{
initI18nOptions
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/i18n
'
)
const
{
parseI18nJson
}
=
require
(
'
@dcloudio/uni-i18n
'
)
const
{
initI18nOptions
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/i18n
'
)
const
{
parseI18nJson
}
=
require
(
'
@dcloudio/uni-i18n
'
)
// 将开发者手动设置的 usingComponents 调整名称,方便与自动解析到的 usingComponents 做最后合并
function
renameUsingComponents
(
jsonObj
)
{
function
renameUsingComponents
(
jsonObj
)
{
if
(
jsonObj
.
usingComponents
)
{
jsonObj
.
customUsingComponents
=
jsonObj
.
usingComponents
delete
jsonObj
.
usingComponents
...
...
@@ -39,7 +46,7 @@ function renameUsingComponents (jsonObj) {
return
jsonObj
}
module
.
exports
=
function
(
content
,
map
)
{
module
.
exports
=
function
(
content
,
map
)
{
this
.
cacheable
&&
this
.
cacheable
()
initTheme
()
...
...
@@ -60,6 +67,7 @@ module.exports = function (content, map) {
)
// this.addDependency(pagesJsonJsPath)
this
.
addContextDependency
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
))
this
.
addDependency
(
manifestJsonPath
)
let
pagesJson
=
parsePagesJson
(
content
,
{
...
...
@@ -117,20 +125,24 @@ module.exports = function (content, map) {
true
)
if
(
i18nOptions
)
{
const
{
locale
,
locales
,
delimiters
}
=
i18nOptions
const
{
locale
,
locales
,
delimiters
}
=
i18nOptions
parseI18nJson
(
pagesJson
,
locales
[
locale
],
delimiters
)
}
}
if
(
!
process
.
env
.
UNI_USING_V3
)
{
parsePages
(
pagesJson
,
function
(
page
)
{
function
(
page
)
{
updatePageJson
(
page
.
path
,
renameUsingComponents
(
parseStyle
(
page
.
style
))
)
},
function
(
root
,
page
)
{
function
(
root
,
page
)
{
updatePageJson
(
normalizePath
(
path
.
join
(
root
,
page
.
path
)),
renameUsingComponents
(
parseStyle
(
page
.
style
,
root
))
...
...
@@ -202,4 +214,4 @@ module.exports = function (content, map) {
}
this
.
callback
(
null
,
''
,
map
)
}
}
packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
浏览文件 @
0ebdc0ce
...
...
@@ -3,10 +3,20 @@ const fsExtra = require('fs-extra')
const
path
=
require
(
'
path
'
)
const
merge
=
require
(
'
merge
'
)
const
{
normalizePath
,
getFlexDirection
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
compileI18nJsonStr
}
=
require
(
'
@dcloudio/uni-i18n
'
)
const
{
initI18nOptions
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/i18n
'
)
const
{
hasOwn
,
parseStyle
}
=
require
(
'
../../util
'
)
const
{
normalizePath
,
getFlexDirection
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
compileI18nJsonStr
}
=
require
(
'
@dcloudio/uni-i18n
'
)
const
{
initI18nOptions
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/i18n
'
)
const
{
hasOwn
,
parseStyle
}
=
require
(
'
../../util
'
)
const
wxPageOrientationMapping
=
{
auto
:
[
...
...
@@ -95,7 +105,9 @@ function updateFileFlag (appJson) {
}
module
.
exports
=
function
(
pagesJson
,
userManifestJson
,
isAppView
)
{
const
{
app
}
=
require
(
'
../mp
'
)(
pagesJson
,
userManifestJson
)
const
{
app
}
=
require
(
'
../mp
'
)(
pagesJson
,
userManifestJson
)
const
manifest
=
{
name
:
'
manifest
'
...
...
@@ -123,8 +135,7 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
// 用户配置覆盖默认配置
manifestJson
=
merge
.
recursive
(
true
,
manifestJson
,
{
manifestJson
,
{
id
:
userManifestJson
.
appid
||
''
,
name
:
userManifestJson
.
name
||
''
,
description
:
userManifestJson
.
description
||
''
,
...
...
@@ -133,8 +144,7 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
code
:
userManifestJson
.
versionCode
},
language
:
userManifestJson
.
locale
},
{
},
{
plus
:
userManifestJson
[
'
app-plus
'
]
}
)
...
...
@@ -201,7 +211,10 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
if
(
nvuePages
&&
nvuePages
.
length
)
{
const
pages
=
{}
nvuePages
.
forEach
(({
path
,
style
})
=>
{
nvuePages
.
forEach
(({
path
,
style
})
=>
{
pages
[
path
]
=
{
window
:
parseStyle
(
style
),
nvue
:
true
...
...
@@ -388,14 +401,20 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
return
(
path
.
replace
(
/
\.
html$/
,
'
.nvue
'
)
===
key
||
path
.
replace
(
/
\.
html$/
,
'
.nvue
'
)
+
'
.nvue
'
===
key
||
subNVues
.
find
(({
path
})
=>
path
===
key
.
replace
(
/
\.
nvue$/
,
''
))
subNVues
.
find
(({
path
})
=>
path
===
key
.
replace
(
/
\.
nvue$/
,
''
))
)
})
&&
!
pagesJson
.
pages
.
find
(({
style
=
{}
})
=>
{
!
pagesJson
.
pages
.
find
(({
style
=
{}
})
=>
{
style
=
Object
.
assign
(
style
,
style
[
'
app-plus
'
])
const
subNVues
=
style
.
subNVues
||
[]
return
subNVues
.
find
(
({
path
})
=>
path
===
key
.
replace
(
/
\.
nvue$/
,
''
)
({
path
})
=>
path
===
key
.
replace
(
/
\.
nvue$/
,
''
)
)
})
)
{
...
...
@@ -491,8 +510,7 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
pagesJson
.
tabBar
.
list
&&
pagesJson
.
tabBar
.
list
.
length
)
{
const
tabBar
=
(
manifestJson
.
plus
.
tabBar
=
Object
.
assign
(
{},
const
tabBar
=
(
manifestJson
.
plus
.
tabBar
=
Object
.
assign
({},
pagesJson
.
tabBar
))
const
borderStyles
=
{
...
...
@@ -518,9 +536,9 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
const
item
=
tabBar
.
list
.
find
(
page
=>
page
.
pagePath
===
(
process
.
env
.
UNI_USING_NATIVE
?
appJson
.
entryPagePath
:
entryPagePath
)
(
process
.
env
.
UNI_USING_NATIVE
?
appJson
.
entryPagePath
:
entryPagePath
)
)
if
(
item
)
{
tabBar
.
child
=
[
'
lauchwebview
'
]
...
...
@@ -535,8 +553,8 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
true
)
if
(
i18nOptions
)
{
manifestJson
.
plus
.
tabBar
=
JSON
.
parse
(
compileI18nJsonStr
(
JSON
.
stringify
(
tabBar
),
i18nOptions
)
manifestJson
=
JSON
.
parse
(
compileI18nJsonStr
(
JSON
.
stringify
(
manifestJson
),
i18nOptions
)
)
manifestJson
.
fallbackLocale
=
i18nOptions
.
locale
}
...
...
@@ -579,8 +597,7 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
}
return
require
(
'
./index.v3
'
)(
appJson
,
manifestJson
,
{
manifestJson
,
{
manifest
,
pagesJson
,
normalizeNetworkTimeout
...
...
@@ -589,4 +606,4 @@ module.exports = function (pagesJson, userManifestJson, isAppView) {
)
}
return
[
app
,
manifest
]
}
}
packages/webpack-uni-pages-loader/lib/platforms/h5.js
浏览文件 @
0ebdc0ce
...
...
@@ -458,7 +458,7 @@ global.__uniConfig.sdkConfigs = ${JSON.stringify(sdkConfigs)};
global.__uniConfig.qqMapKey =
${
JSON
.
stringify
(
qqMapKey
)}
;
global.__uniConfig.locale =
${
JSON
.
stringify
(
locale
)}
;
global.__uniConfig.fallbackLocale =
${
JSON
.
stringify
(
manifestJson
.
fallbackLocale
)}
;
global.__uniConfig.locales = locales.keys().reduce((res,key)=>{
res[key.replace(/\\.\\/(.*).json/,'$1')]=locales(key
);return res},{});
global.__uniConfig.locales = locales.keys().reduce((res,key)=>{
const locale=key.replace(/\\.\\/(uni-app.)?(.*).json/,'$2');const messages = locales(key);Object.assign(res[locale]||(res[locale]={}),messages.common||messages
);return res},{});
global.__uniConfig.nvue =
${
JSON
.
stringify
({
'
flex-direction
'
:
getFlexDirection
(
manifestJson
[
'
app-plus
'
])
})}
global.__uniConfig.__webpack_chunk_load__ = __webpack_chunk_load__
${
genRegisterPageVueComponentsCode
(
pageComponents
)}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录