Skip to content

Commit f1b3b50

Browse files
authored
fix: preview compatibility i18n is null (opentiny#912)
* fix: preview compatibility i18n is null * fix: fix review
1 parent bc501cf commit f1b3b50

File tree

1 file changed

+11
-1
lines changed
  • packages/design-core/src/preview/src/preview

1 file changed

+11
-1
lines changed

packages/design-core/src/preview/src/preview/generate.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ const generateUtils = (list) => {
134134
return strs.join('\n')
135135
}
136136

137+
const compatibleI18n = (i18n) => {
138+
if (!i18n || typeof i18n !== 'object') {
139+
return { en_US: {}, zh_CN: {} }
140+
}
141+
i18n.en_US = i18n.en_US && typeof i18n.en_US === 'object' ? i18n.en_US : {}
142+
i18n.zh_CN = i18n.zh_CN && typeof i18n.zh_CN === 'object' ? i18n.zh_CN : {}
143+
144+
return i18n
145+
}
146+
137147
/**
138148
* 处理css文件依赖
139149
* @param {*} code 源代码
@@ -145,7 +155,7 @@ export const processAppJsCode = (code, cssList) => {
145155
}
146156

147157
export default (data) => {
148-
const locales = generateDefaultExport(data.i18n)
158+
const locales = generateDefaultExport(compatibleI18n(data.i18n))
149159
const dataSource = generateDefaultExport(data.dataSource)
150160
const stores = generateStores(data.globalState)
151161
const bridge = generateBridge(data.bridge)

0 commit comments

Comments
 (0)