admin管理员组文章数量:1405299
Im trying to setup custom labels for blockType in react-draft-wysiwyg
.
According to this pool request
I should be able to add displayName
property to editor toolbar configuration object.
I tried to implement this like that, but unfortunately it does not work.
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,
ponent: undefined,
dropdownClassName: undefined,
},
I would like to achieve a customizable label this will allow me to have multi language support in my editor.
Im trying to setup custom labels for blockType in react-draft-wysiwyg
.
According to this pool request
I should be able to add displayName
property to editor toolbar configuration object.
I tried to implement this like that, but unfortunately it does not work.
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,
ponent: undefined,
dropdownClassName: undefined,
},
I would like to achieve a customizable label this will allow me to have multi language support in my editor.
Share edited Mar 30, 2019 at 17:50 Space asked Mar 26, 2019 at 8:47 SpaceSpace 1882 silver badges13 bronze badges1 Answer
Reset to default 7After some researching I found the solution for my issue.
Editor ponent has a prop to provide localization object. This localization object has a key for custom labels in case we are missing something from the provided localization.
We can use it like that:
<Editor
...
localization={{ locale: 'en', translations: editorLabels }}
/>
const editorLabels = {
// Generic
'generic.add': 'Add',
'generic.cancel': 'Cancel',
// BlockType
'ponents.controls.blocktype.h1': 'Heading 1',
'ponents.controls.blocktype.h2': 'Heading 2',
'ponents.controls.blocktype.h3': 'Heading 3',
'ponents.controls.blocktype.h4': 'Heading 4',
'ponents.controls.blocktype.h5': 'Heading 5',
'ponents.controls.blocktype.h6': 'Heading 6',
'ponents.controls.blocktype.blockquote': 'Blockquote',
'ponents.controls.blocktype.code': 'Code',
'ponents.controls.blocktype.blocktype': 'Block Type',
'ponents.controls.blocktype.normal': 'Normal',
// Color Picker
'ponents.controls.colorpicker.colorpicker': 'Color Picker',
'ponents.controls.colorpicker.text': 'Text',
'ponents.controls.colorpicker.background': 'Highlight',
// Embedded
'ponents.controls.embedded.embedded': 'Embedded',
'ponents.controls.embedded.embeddedlink': 'Embedded Link',
'ponents.controls.embedded.enterlink': 'Enter link',
// Emoji
'ponents.controls.emoji.emoji': 'Emoji',
// FontFamily
'ponents.controls.fontfamily.fontfamily': 'Font',
// FontSize
'ponents.controls.fontsize.fontsize': 'Font Size',
// History
'ponents.controls.history.history': 'History',
'ponents.controls.history.undo': 'Undo',
'ponents.controls.history.redo': 'Redo',
// Image
'ponents.controls.image.image': 'Image',
'ponents.controls.image.fileUpload': 'File Upload',
'ponents.controls.image.byURL': 'URL',
'ponents.controls.image.dropFileText': 'Drop the file or click to upload',
// Inline
'ponents.controls.inline.bold': 'Bold',
'ponents.controls.inline.italic': 'Italic',
'ponents.controls.inline.underline': 'Underline',
'ponents.controls.inline.strikethrough': 'Strikethrough',
'ponents.controls.inline.monospace': 'Monospace',
'ponents.controls.inline.superscript': 'Superscript',
'ponents.controls.inline.subscript': 'Subscript',
// Link
'ponents.controls.link.linkTitle': 'Link Title',
'ponents.controls.link.linkTarget': 'Link Target',
'ponents.controls.link.linkTargetOption': 'Open link in new window',
'ponents.controls.link.link': 'Link',
'ponents.controls.link.unlink': 'Unlink',
// List
'ponents.controls.list.list': 'List',
'ponents.controls.list.unordered': 'Unordered',
'ponents.controls.list.ordered': 'Ordered',
'ponents.controls.list.indent': 'Indent',
'ponents.controls.list.outdent': 'Outdent',
// Remove
'ponents.controls.remove.remove': 'Remove',
// TextAlign
'ponents.controls.textalign.textalign': 'Text Align',
'ponents.controls.textalign.left': 'Left',
'ponents.controls.textalign.center': 'Center',
'ponents.controls.textalign.right': 'Right',
'ponents.controls.textalign.justify': 'Justify',
};
本文标签: javascriptQ ReactDraftWysiwyg How to add custom label to blockTypesStack Overflow
版权声明:本文标题:javascript - Q: React-Draft-Wysiwyg How to add custom label to blockTypes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744908442a2631765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论