Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preview compatibility i18n is null #912

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/design-core/src/preview/src/preview/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ const generateUtils = (list) => {
return strs.join('\n')
}

const compatibleI18n = (i18n) => {
if (!i18n || typeof i18n !== 'object') {
return { en_US: {}, zh_CN: {} }
}
i18n.en_US = i18n.en_US && typeof i18n.en_US === 'object' ? i18n.en_US : {}
i18n.zh_CN = i18n.zh_CN && typeof i18n.zh_CN === 'object' ? i18n.zh_CN : {}

return i18n
}

/**
* 处理css文件依赖
* @param {*} code 源代码
Expand All @@ -145,7 +155,7 @@ export const processAppJsCode = (code, cssList) => {
}

export default (data) => {
const locales = generateDefaultExport(data.i18n)
const locales = generateDefaultExport(compatibleI18n(data.i18n))
const dataSource = generateDefaultExport(data.dataSource)
const stores = generateStores(data.globalState)
const bridge = generateBridge(data.bridge)
Expand Down