You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sanity CMS中block类型本地化遇报错,求解决方案及详细文档

Sanity CMS中Block类型的本地化实现方案

问题原因

你直接给block类型的字段添加了fieldset属性,但Sanity的block类型本身不支持该配置项,因此触发错误提示。

解决方案

场景1:本地化富文本(最常用)

富文本内容通常以array类型包裹block对象,array类型支持fieldset属性,修改后的代码如下:

export default {
  title: '本地化富文本',
  name: 'localeBlock',
  type: 'object',
  fieldsets: [
    {
      title: '翻译内容',
      name: 'translations',
      options: {
        collapsible: true,
      },
    },
  ],
  fields: supportedLanguages.map(lang => ({
    title: lang.title,
    name: lang.id,
    type: 'array',
    of: [{ type: 'block' }],
    fieldset: lang.isDefault ? null : 'translations',
  })),
}

场景2:本地化单个Block(特殊场景)

若确实需要单个block的本地化,可将其嵌套在object类型字段中,再为该object字段设置fieldset:

export default {
  title: '本地化单个Block',
  name: 'localeBlock',
  type: 'object',
  fieldsets: [
    {
      title: '翻译内容',
      name: 'translations',
      options: {
        collapsible: true,
      },
    },
  ],
  fields: supportedLanguages.map(lang => ({
    title: lang.title,
    name: lang.id,
    type: 'object',
    fields: [{ name: 'content', type: 'block' }],
    fieldset: lang.isDefault ? null : 'translations',
  })),
}

深入本地化资料参考

  • Sanity官方Discord社区:有大量开发者分享的本地化实践案例,覆盖复杂字段类型的实现方案。
  • Sanity官方示例项目(如电商Studio):包含完整的本地化配置,可参考字段结构与组织方式。
  • 社区插件(如sanity-plugin-intl-input):提供便捷的本地化工具,简化多语言字段配置流程。

内容的提问来源于stack exchange,提问作者RCKT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 02:56:52