fix: i18n create empty entries error#1278
Conversation
WalkthroughThis change updates the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/plugins/i18n/src/composable/useTranslate.ts (2)
227-230: Consider applying the same fallback pattern here.For consistency, I recommend applying the same fallback pattern to handle potentially undefined values in the
batchCreateI18nfunction:const entries = Object.entries(langs).map(([key, message]) => ({ key, - contents: Object.fromEntries(locales.map(({ lang }) => [lang, message[lang]])) + contents: Object.fromEntries(locales.map(({ lang }) => [lang, message[lang] || ''])) }))This would prevent similar issues when batch creating entries with missing language values.
65-65: Consider adding a comment for future reference.To help future developers understand the purpose of this fallback mechanism, consider adding a brief comment:
+ // Ensure each language has at least an empty string to prevent errors when creating entries const contents = Object.fromEntries(locales.map(({ lang }) => [lang, obj[lang] || '']))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/plugins/i18n/src/composable/useTranslate.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: push-check
🔇 Additional comments (1)
packages/plugins/i18n/src/composable/useTranslate.ts (1)
65-65: Good fix for the empty entries error.This change ensures that when
obj[lang]is undefined or falsy, it defaults to an empty string. This effectively fixes the issue where creating empty entries results in an error if thecontentin the request body lacks properties.
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
i18n插件中创建空词条,
content中的属性会设置成undefined,导致请求体中的content没有属性,请求接口会报错(看下方current behavior截图)方案:创建空词条时,给
content中的属性设置空字符串(看下方new behavior截图)有关联的pr #1254 ,这个pr修复了初始化词条不加载的问题
What is the current behavior?
What is the new behavior?
Does this PR introduce a breaking change?
Other information