Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
099cc1b3
U
uni-app
项目概览
ChenYFan_OHHH
/
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,发现更多精彩内容 >>
提交
099cc1b3
编写于
9月 13, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(i18n): support locale/uni-app.*.json
上级
5b322033
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
514 addition
and
494 deletion
+514
-494
packages/uni-app-vite/src/plugins/manifestJson.ts
packages/uni-app-vite/src/plugins/manifestJson.ts
+6
-0
packages/uni-app-vite/src/plugins/pagesJson.ts
packages/uni-app-vite/src/plugins/pagesJson.ts
+6
-0
packages/uni-cli-shared/package.json
packages/uni-cli-shared/package.json
+1
-0
packages/uni-cli-shared/src/i18n.ts
packages/uni-cli-shared/src/i18n.ts
+35
-3
packages/uni-cli-shared/src/json/app/manifest/i18n.ts
packages/uni-cli-shared/src/json/app/manifest/i18n.ts
+4
-8
packages/uni-cli-shared/src/json/app/manifest/index.ts
packages/uni-cli-shared/src/json/app/manifest/index.ts
+2
-2
packages/uni-cli-shared/src/json/app/pages/locale.ts
packages/uni-cli-shared/src/json/app/pages/locale.ts
+0
-18
packages/uni-h5-vite/src/plugins/pagesJson.ts
packages/uni-h5-vite/src/plugins/pagesJson.ts
+1
-1
packages/uni-stat/dist/uni-stat.cjs.js
packages/uni-stat/dist/uni-stat.cjs.js
+1
-1
packages/uni-stat/dist/uni-stat.es.js
packages/uni-stat/dist/uni-stat.es.js
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/json.ts
packages/vite-plugin-uni/src/configResolved/plugins/json.ts
+6
-2
yarn.lock
yarn.lock
+451
-458
未找到文件。
packages/uni-app-vite/src/plugins/manifestJson.ts
浏览文件 @
099cc1b3
...
...
@@ -3,6 +3,7 @@ import { Plugin } from 'vite'
import
{
defineUniManifestJsonPlugin
,
getLocaleFiles
,
normalizeAppManifestJson
,
parseJson
,
parsePagesJsonOnce
,
...
...
@@ -21,6 +22,11 @@ export function uniManifestJsonPlugin(): Plugin {
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json
'
)
)
getLocaleFiles
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
)
).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
})
manifestJson
=
normalizeAppManifestJson
(
parseJson
(
code
),
parsePagesJsonOnce
(
...
...
packages/uni-app-vite/src/plugins/pagesJson.ts
浏览文件 @
099cc1b3
...
...
@@ -7,6 +7,7 @@ import {
normalizeAppConfigService
,
normalizePagesJson
,
parseManifestJsonOnce
,
getLocaleFiles
,
}
from
'
@dcloudio/uni-cli-shared
'
export
function
uniPagesJsonPlugin
():
Plugin
{
...
...
@@ -20,6 +21,11 @@ export function uniPagesJsonPlugin(): Plugin {
return
}
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
pages.json
'
))
getLocaleFiles
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
)
).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
})
pagesJson
=
normalizePagesJson
(
code
,
process
.
env
.
UNI_PLATFORM
)
// TODO subpackages
pagesJson
.
pages
.
forEach
((
page
)
=>
{
...
...
packages/uni-cli-shared/package.json
浏览文件 @
099cc1b3
...
...
@@ -24,6 +24,7 @@
"compare-versions"
:
"^3.6.0"
,
"debug"
:
"^4.3.1"
,
"estree-walker"
:
"^2.0.2"
,
"fast-glob"
:
"^3.2.7"
,
"fs-extra"
:
"^10.0.0"
,
"hash-sum"
:
"^2.0.0"
,
"jsonc-parser"
:
"^3.0.0"
,
...
...
packages/uni-cli-shared/src/i18n.ts
浏览文件 @
099cc1b3
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
sync
}
from
'
fast-glob
'
import
{
extend
}
from
'
@vue/shared
'
import
{
I18N_JSON_DELIMITERS
,
once
}
from
'
@dcloudio/uni-shared
'
import
{
parseJson
,
parseManifestJsonOnce
}
from
'
./json
'
import
{
M
}
from
'
./messages
'
...
...
@@ -39,6 +42,27 @@ export function initI18nOptions(
export
const
initI18nOptionsOnce
=
once
(
initI18nOptions
)
const
localeJsonRE
=
/uni-app.*.json/
export
function
isUniAppLocaleFile
(
filepath
:
string
)
{
if
(
!
filepath
)
{
return
false
}
return
localeJsonRE
.
test
(
path
.
basename
(
filepath
))
}
function
parseLocaleJson
(
filepath
:
string
)
{
let
jsonObj
=
parseJson
(
fs
.
readFileSync
(
filepath
,
'
utf8
'
))
if
(
isUniAppLocaleFile
(
filepath
))
{
jsonObj
=
jsonObj
.
common
||
{}
}
return
jsonObj
}
export
function
getLocaleFiles
(
cwd
:
string
)
{
return
sync
(
'
*.json
'
,
{
cwd
,
absolute
:
true
})
}
export
function
initLocales
(
dir
:
string
,
withMessages
:
boolean
=
true
)
{
if
(
!
fs
.
existsSync
(
dir
))
{
return
{}
...
...
@@ -46,9 +70,17 @@ export function initLocales(dir: string, withMessages: boolean = true) {
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
'
))
:
{}
const
locale
=
path
.
basename
(
filename
)
.
replace
(
/
(
uni-app.
)?(
.*
)
.json/
,
'
$2
'
)
if
(
withMessages
)
{
extend
(
res
[
locale
]
||
(
res
[
locale
]
=
{}),
parseLocaleJson
(
path
.
join
(
dir
,
filename
))
)
}
else
{
res
[
locale
]
=
{}
}
}
catch
(
e
)
{}
}
return
res
...
...
packages/uni-cli-shared/src/json/app/manifest/i18n.ts
浏览文件 @
099cc1b3
...
...
@@ -9,14 +9,10 @@ export function initI18n(manifestJson: Record<string, any>) {
true
)
if
(
i18nOptions
)
{
if
(
manifestJson
.
plus
.
tabBar
)
{
manifestJson
.
plus
.
tabBar
=
JSON
.
parse
(
compileI18nJsonStr
(
JSON
.
stringify
(
manifestJson
.
plus
.
tabBar
),
i18nOptions
)
)
}
manifestJson
=
JSON
.
parse
(
compileI18nJsonStr
(
JSON
.
stringify
(
manifestJson
),
i18nOptions
)
)
manifestJson
.
fallbackLocale
=
i18nOptions
.
locale
}
return
manifestJson
}
packages/uni-cli-shared/src/json/app/manifest/index.ts
浏览文件 @
099cc1b3
...
...
@@ -33,8 +33,8 @@ export function normalizeAppManifestJson(
manifestJson
,
pagesJson
)
initI18n
(
manifestJson
)
return
manifestJson
return
initI18n
(
manifestJson
)
}
export
*
from
'
./env
'
...
...
packages/uni-cli-shared/src/json/app/pages/locale.ts
已删除
100644 → 0
浏览文件 @
5b322033
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
parseJson
}
from
'
../../json
'
export
function
getLocales
(
inputDir
:
string
)
{
const
localesDir
=
path
.
resolve
(
inputDir
,
'
locale
'
)
if
(
fs
.
existsSync
(
localesDir
))
{
return
fs
.
readdirSync
(
localesDir
).
reduce
((
res
,
filename
)
=>
{
if
(
path
.
extname
(
filename
)
===
'
.json
'
)
{
res
[
filename
.
replace
(
'
.json
'
,
''
)]
=
parseJson
(
fs
.
readFileSync
(
path
.
join
(
localesDir
,
filename
),
'
utf8
'
))
||
{}
}
return
res
},
{}
as
Record
<
string
,
Record
<
string
,
string
>>
)
}
return
{}
}
packages/uni-h5-vite/src/plugins/pagesJson.ts
浏览文件 @
099cc1b3
...
...
@@ -262,7 +262,7 @@ delete ${globalName}['____'+appid+'____']
nvue,
locale,
fallbackLocale,
locales:Object.keys(locales).reduce((res,name)=>{
res[name.replace(/\\.\\/locale\\/(.*).json/,'$1')]=locales[name].default
;return res},{}),
locales:Object.keys(locales).reduce((res,name)=>{
const locale=name.replace(/\\.\\/locale\\/(uni-app.)?(.*).json/,'$2');extend(res[locale]||(res[locale]={}),locales[name].default)
;return res},{}),
router,
})
`
...
...
packages/uni-stat/dist/uni-stat.cjs.js
浏览文件 @
099cc1b3
'
use strict
'
;
var
version
=
"
3.0.0-alpha-3000020210
827004
"
;
var
version
=
"
3.0.0-alpha-3000020210
913001
"
;
const
STAT_VERSION
=
version
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
...
...
packages/uni-stat/dist/uni-stat.es.js
浏览文件 @
099cc1b3
var
version
=
"
3.0.0-alpha-3000020210
827004
"
;
var
version
=
"
3.0.0-alpha-3000020210
913001
"
;
const
STAT_VERSION
=
version
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
...
...
packages/vite-plugin-uni/src/configResolved/plugins/json.ts
浏览文件 @
099cc1b3
import
{
Plugin
}
from
'
vite
'
import
{
parse
}
from
'
jsonc-parser
'
import
{
preJs
}
from
'
@dcloudio/uni-cli-shared
'
import
{
preJs
,
isUniAppLocaleFile
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
const
jsonExtRE
=
/
\.
json
(
$|
\?)(?!
commonjs-proxy
)
/
...
...
@@ -17,8 +17,12 @@ export function uniJsonPlugin(options: VitePluginUniResolvedOptions): Plugin {
if
(
code
.
includes
(
'
#endif
'
))
{
code
=
preJs
(
code
)
}
let
jsonObj
=
parse
(
code
)
if
(
isUniAppLocaleFile
(
id
))
{
jsonObj
=
jsonObj
.
common
||
{}
}
return
{
code
:
JSON
.
stringify
(
parse
(
code
)
),
code
:
JSON
.
stringify
(
jsonObj
),
map
:
null
,
}
},
...
...
yarn.lock
浏览文件 @
099cc1b3
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录