Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
0ebdc0ce
U
uni-app
项目概览
良好的行为成为习惯
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
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
},
{})
...
...
packages/uni-migration/bin/uni-migration.js
100644 → 100755
浏览文件 @
0ebdc0ce
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
))
...
...
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
=
{
...
...
@@ -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
...
...
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录