4

我正在尝试为 blockType 设置自定义标签react-draft-wysiwyg

根据这个池请求 ,我应该能够将displayName属性添加到编辑器工具栏配置对象。

我试图这样实现,但不幸的是它不起作用。

const documentEditorToolBarOptions = {
  options: [
    'blockType',
  ],
  blockType: {
    inDropdown: true,
    options: [
      'Normal',
      'H1',
      'H2',
      'H3',
      'H4',
      'H5',
      'H6',
      'Blockquote',
    ],
    displayNames: [
      { label: 'Normal', displayName: 'Normal', style: 'unstyled' },
      { label: 'H1', displayName: 'Heading 1', style: 'header-one' },
      { label: 'H2', displayName: 'Heading 2', style: 'header-two' },
      { label: 'H3', displayName: 'Heading 3', style: 'header-three' },
      { label: 'H4', displayName: 'Heading 4', style: 'header-four' },
      { label: 'H5', displayName: 'Heading 5', style: 'header-five' },
      { label: 'H6', displayName: 'Heading 6', style: 'header-six' },
      { label: 'Blockquote', displayName: 'Blockquote', style: 'blockquote' },
    ],
    className: undefined,
    component: undefined,
    dropdownClassName: undefined,
  },

我想实现一个可定制的标签,这将允许我在我的编辑器中获得多语言支持。

4

1 回答 1

5

经过一番研究,我找到了解决问题的方法。

Editor 组件有一个 prop 来提供本地化对象。此本地化对象具有自定义标签的键,以防我们从提供的本地化中丢失某些内容。

我们可以这样使用它:

   <Editor
     ...
     localization={{ locale: 'en', translations: editorLabels }}
    />
const editorLabels = {
  // Generic
  'generic.add': 'Add',
  'generic.cancel': 'Cancel',

  // BlockType
  'components.controls.blocktype.h1': 'Heading 1',
  'components.controls.blocktype.h2': 'Heading 2',
  'components.controls.blocktype.h3': 'Heading 3',
  'components.controls.blocktype.h4': 'Heading 4',
  'components.controls.blocktype.h5': 'Heading 5',
  'components.controls.blocktype.h6': 'Heading 6',
  'components.controls.blocktype.blockquote': 'Blockquote',
  'components.controls.blocktype.code': 'Code',
  'components.controls.blocktype.blocktype': 'Block Type',
  'components.controls.blocktype.normal': 'Normal',

  // Color Picker
  'components.controls.colorpicker.colorpicker': 'Color Picker',
  'components.controls.colorpicker.text': 'Text',
  'components.controls.colorpicker.background': 'Highlight',

  // Embedded
  'components.controls.embedded.embedded': 'Embedded',
  'components.controls.embedded.embeddedlink': 'Embedded Link',
  'components.controls.embedded.enterlink': 'Enter link',

  // Emoji
  'components.controls.emoji.emoji': 'Emoji',

  // FontFamily
  'components.controls.fontfamily.fontfamily': 'Font',

  // FontSize
  'components.controls.fontsize.fontsize': 'Font Size',

  // History
  'components.controls.history.history': 'History',
  'components.controls.history.undo': 'Undo',
  'components.controls.history.redo': 'Redo',

  // Image
  'components.controls.image.image': 'Image',
  'components.controls.image.fileUpload': 'File Upload',
  'components.controls.image.byURL': 'URL',
  'components.controls.image.dropFileText': 'Drop the file or click to upload',

  // Inline
  'components.controls.inline.bold': 'Bold',
  'components.controls.inline.italic': 'Italic',
  'components.controls.inline.underline': 'Underline',
  'components.controls.inline.strikethrough': 'Strikethrough',
  'components.controls.inline.monospace': 'Monospace',
  'components.controls.inline.superscript': 'Superscript',
  'components.controls.inline.subscript': 'Subscript',

  // Link
  'components.controls.link.linkTitle': 'Link Title',
  'components.controls.link.linkTarget': 'Link Target',
  'components.controls.link.linkTargetOption': 'Open link in new window',
  'components.controls.link.link': 'Link',
  'components.controls.link.unlink': 'Unlink',

  // List
  'components.controls.list.list': 'List',
  'components.controls.list.unordered': 'Unordered',
  'components.controls.list.ordered': 'Ordered',
  'components.controls.list.indent': 'Indent',
  'components.controls.list.outdent': 'Outdent',

  // Remove
  'components.controls.remove.remove': 'Remove',

  // TextAlign
  'components.controls.textalign.textalign': 'Text Align',
  'components.controls.textalign.left': 'Left',
  'components.controls.textalign.center': 'Center',
  'components.controls.textalign.right': 'Right',
  'components.controls.textalign.justify': 'Justify',
};
于 2019-03-30T11:14:54.987 回答