From c11b2440f91b99d40bca18b675c66a22b6e160c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=A6=8F=E6=9C=8B?= Date: Mon, 16 Aug 2021 19:20:01 +0800 Subject: [PATCH] feat: i18n --- packages/basic-modules/src/index.ts | 3 + packages/basic-modules/src/locale/en.ts | 90 +++++++++++++++++++ packages/basic-modules/src/locale/index.ts | 11 +++ packages/basic-modules/src/locale/zh-CN.ts | 90 +++++++++++++++++++ .../modules/blockquote/menu/BlockquoteMenu.ts | 4 +- .../modules/code-block/menu/CodeBlockMenu.ts | 4 +- .../src/modules/color/menu/BaseMenu.ts | 6 +- .../src/modules/color/menu/BgColorMenu.ts | 3 +- .../src/modules/color/menu/ColorMenu.ts | 3 +- .../modules/divider/menu/InsertDividerMenu.ts | 4 +- .../src/modules/emotion/menu/EmotionMenu.ts | 4 +- .../font-size-family/menu/FontFamilyMenu.ts | 6 +- .../font-size-family/menu/FontSizeMenu.ts | 6 +- .../modules/full-screen/menu/FullScreen.ts | 4 +- .../modules/header/menu/HeaderSelectMenu.ts | 6 +- .../src/modules/image/menu/DeleteImage.ts | 4 +- .../src/modules/image/menu/EditImage.ts | 11 +-- .../src/modules/image/menu/InsertImage.ts | 11 +-- .../src/modules/image/menu/ViewImageLink.ts | 4 +- .../modules/indent/menu/DecreaseIndentMenu.ts | 4 +- .../modules/indent/menu/IncreaseIndentMenu.ts | 4 +- .../modules/justify/menu/JustifyCenterMenu.ts | 4 +- .../justify/menu/JustifyJustifyMenu.ts | 4 +- .../modules/justify/menu/JustifyLeftMenu.ts | 4 +- .../modules/justify/menu/JustifyRightMenu.ts | 4 +- .../line-height/menu/LineHeightMenu.ts | 6 +- .../basic-modules/src/modules/link/helper.ts | 2 +- .../src/modules/link/menu/InsertLink.ts | 16 ++-- .../src/modules/link/menu/UnLink.ts | 4 +- .../src/modules/link/menu/UpdateLink.ts | 7 +- .../src/modules/link/menu/ViewLink.ts | 5 +- .../src/modules/text-style/menu/BoldMenu.ts | 3 +- .../modules/text-style/menu/ClearStyleMenu.ts | 4 +- .../src/modules/text-style/menu/CodeMenu.ts | 3 +- .../src/modules/text-style/menu/ItalicMenu.ts | 3 +- .../src/modules/text-style/menu/SubMenu.ts | 3 +- .../src/modules/text-style/menu/SupMenu.ts | 3 +- .../modules/text-style/menu/ThroughMenu.ts | 3 +- .../modules/text-style/menu/UnderlineMenu.ts | 3 +- .../src/modules/undo-redo/menu/RedoMenu.ts | 4 +- .../src/modules/undo-redo/menu/UndoMenu.ts | 4 +- packages/code-highlight/src/index.ts | 3 + packages/code-highlight/src/locale/en.ts | 10 +++ packages/code-highlight/src/locale/index.ts | 11 +++ packages/code-highlight/src/locale/zh-CN.ts | 10 +++ .../src/module/menu/SelectLangMenu.ts | 4 +- packages/core/package.json | 3 +- packages/core/src/i18n/index.ts | 37 ++++++++ packages/core/src/index.ts | 3 + packages/editor/examples/i18n.html | 47 ++++++++++ packages/editor/examples/index.html | 1 + packages/editor/package.json | 8 +- packages/editor/src/index.ts | 12 ++- .../src/init-default-config/config/toolbar.ts | 11 +-- packages/editor/src/locale/en.ts | 13 +++ packages/editor/src/locale/index.ts | 11 +++ packages/editor/src/locale/zh-CN.ts | 13 +++ packages/list-module/src/index.ts | 5 +- packages/list-module/src/locale/en.ts | 11 +++ packages/list-module/src/locale/index.ts | 11 +++ packages/list-module/src/locale/zh-CN.ts | 11 +++ .../src/module/menu/BulletedListMenu.ts | 3 +- .../src/module/menu/NumberedListMenu.ts | 3 +- packages/table-module/src/index.ts | 4 +- packages/table-module/src/locale/en.ts | 17 ++++ packages/table-module/src/locale/index.ts | 11 +++ packages/table-module/src/locale/zh-CN.ts | 17 ++++ .../table-module/src/module/menu/DeleteCol.ts | 4 +- .../table-module/src/module/menu/DeleteRow.ts | 4 +- .../src/module/menu/DeleteTable.ts | 4 +- .../table-module/src/module/menu/FullWidth.ts | 4 +- .../table-module/src/module/menu/InsertCol.ts | 4 +- .../table-module/src/module/menu/InsertRow.ts | 4 +- .../src/module/menu/InsertTable.ts | 4 +- .../src/module/menu/TableHeader.ts | 4 +- packages/upload-image-module/src/index.ts | 4 +- packages/upload-image-module/src/locale/en.ts | 11 +++ .../upload-image-module/src/locale/index.ts | 11 +++ .../upload-image-module/src/locale/zh-CN.ts | 11 +++ .../src/module/menu/UploadImageMenu.ts | 10 ++- packages/video-module/src/index.ts | 4 +- packages/video-module/src/locale/en.ts | 14 +++ packages/video-module/src/locale/index.ts | 11 +++ packages/video-module/src/locale/zh-CN.ts | 14 +++ .../src/module/menu/DeleteVideoMenu.ts | 4 +- .../src/module/menu/InsertVideoMenu.ts | 12 +-- 86 files changed, 675 insertions(+), 124 deletions(-) create mode 100644 packages/basic-modules/src/locale/en.ts create mode 100644 packages/basic-modules/src/locale/index.ts create mode 100644 packages/basic-modules/src/locale/zh-CN.ts create mode 100644 packages/code-highlight/src/locale/en.ts create mode 100644 packages/code-highlight/src/locale/index.ts create mode 100644 packages/code-highlight/src/locale/zh-CN.ts create mode 100644 packages/core/src/i18n/index.ts create mode 100644 packages/editor/examples/i18n.html create mode 100644 packages/editor/src/locale/en.ts create mode 100644 packages/editor/src/locale/index.ts create mode 100644 packages/editor/src/locale/zh-CN.ts create mode 100644 packages/list-module/src/locale/en.ts create mode 100644 packages/list-module/src/locale/index.ts create mode 100644 packages/list-module/src/locale/zh-CN.ts create mode 100644 packages/table-module/src/locale/en.ts create mode 100644 packages/table-module/src/locale/index.ts create mode 100644 packages/table-module/src/locale/zh-CN.ts create mode 100644 packages/upload-image-module/src/locale/en.ts create mode 100644 packages/upload-image-module/src/locale/index.ts create mode 100644 packages/upload-image-module/src/locale/zh-CN.ts create mode 100644 packages/video-module/src/locale/en.ts create mode 100644 packages/video-module/src/locale/index.ts create mode 100644 packages/video-module/src/locale/zh-CN.ts diff --git a/packages/basic-modules/src/index.ts b/packages/basic-modules/src/index.ts index ce7f397b7..10b10c9d6 100644 --- a/packages/basic-modules/src/index.ts +++ b/packages/basic-modules/src/index.ts @@ -5,6 +5,9 @@ import './assets/index.less' +// 配置多语言 +import './locale/index' + import wangEditorParagraphModule from './modules/paragraph' import wangEditorTextStyleModule from './modules/text-style' import wangEditorHeaderModule from './modules/header' diff --git a/packages/basic-modules/src/locale/en.ts b/packages/basic-modules/src/locale/en.ts new file mode 100644 index 000000000..c7906d316 --- /dev/null +++ b/packages/basic-modules/src/locale/en.ts @@ -0,0 +1,90 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + // 通用的词 + common: { + ok: 'OK', + }, + + blockQuote: { + title: 'Quote', + }, + codeBlock: { + title: 'Code block', + }, + color: { + color: 'Font color', + bgColor: 'Back color', + default: 'Default color', + clear: 'Clear back color', + }, + divider: { + title: 'Divider', + }, + emotion: { + title: 'Emotion', + }, + fontSize: { + title: 'Font size', + default: 'Default', + }, + fontFamily: { + title: 'Font family', + default: 'Default', + }, + fullScreen: { + title: 'Full screen', + }, + header: { + title: 'Header', + text: 'Text', + }, + image: { + netImage: 'Net image', + delete: 'Delete image', + edit: 'Edit image', + viewLink: 'View link', + src: 'Image src', + desc: 'Description', + link: 'Image link', + }, + indent: { + decrease: 'Decrease', + increase: 'Increase', + }, + justify: { + left: 'Left', + right: 'Right', + center: 'Center', + justify: 'Justify', + }, + lineHeight: { + title: 'Line height', + default: 'Default', + }, + link: { + insert: 'Insert link', + text: 'Link text', + url: 'Link source', + unLink: 'Unlink', + update: 'Update link', + view: 'View link', + }, + textStyle: { + bold: 'Bold', + clear: 'Clear styles', + code: 'Inline code', + italic: 'Italic', + sub: 'Sub', + sup: 'Sup', + through: 'Through', + underline: 'Underline', + }, + undo: { + undo: 'undo', + redo: 'Redo', + }, +} diff --git a/packages/basic-modules/src/locale/index.ts b/packages/basic-modules/src/locale/index.ts new file mode 100644 index 000000000..22f6ec6cb --- /dev/null +++ b/packages/basic-modules/src/locale/index.ts @@ -0,0 +1,11 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import { i18nAddResources } from '@wangeditor/core' +import enResources from './en' +import zhResources from './zh-CN' + +i18nAddResources('en', enResources) +i18nAddResources('zh-CN', zhResources) diff --git a/packages/basic-modules/src/locale/zh-CN.ts b/packages/basic-modules/src/locale/zh-CN.ts new file mode 100644 index 000000000..a1397dda1 --- /dev/null +++ b/packages/basic-modules/src/locale/zh-CN.ts @@ -0,0 +1,90 @@ +/** + * @description i18n zh-CN + * @author wangfupeng + */ + +export default { + // 通用的词 + common: { + ok: '确定', + }, + + blockQuote: { + title: '引用', + }, + codeBlock: { + title: '代码块', + }, + color: { + color: '文字颜色', + bgColor: '背景色', + default: '默认颜色', + clear: '清除背景色', + }, + divider: { + title: '分割线', + }, + emotion: { + title: '表情', + }, + fontSize: { + title: '字号', + default: '默认字号', + }, + fontFamily: { + title: '字体', + default: '默认字体', + }, + fullScreen: { + title: '全屏', + }, + header: { + title: '标题', + text: '正文', + }, + image: { + netImage: '网络图片', + delete: '删除图片', + edit: '编辑图片', + viewLink: '查看链接', + src: '图片地址', + desc: '图片描述', + link: '图片链接', + }, + indent: { + decrease: '减少缩进', + increase: '增加缩进', + }, + justify: { + left: '左对齐', + right: '右对齐', + center: '居中对齐', + justify: '两端对齐', + }, + lineHeight: { + title: '行高', + default: '默认行高', + }, + link: { + insert: '插入链接', + text: '链接文本', + url: '链接地址', + unLink: '取消链接', + update: '修改链接', + view: '查看链接', + }, + textStyle: { + bold: '粗体', + clear: '清除格式', + code: '行内代码', + italic: '斜体', + sub: '上标', + sup: '下标', + through: '删除线', + underline: '下划线', + }, + undo: { + undo: '撤销', + redo: '重做', + }, +} diff --git a/packages/basic-modules/src/modules/blockquote/menu/BlockquoteMenu.ts b/packages/basic-modules/src/modules/blockquote/menu/BlockquoteMenu.ts index 61da1380f..7c6b88615 100644 --- a/packages/basic-modules/src/modules/blockquote/menu/BlockquoteMenu.ts +++ b/packages/basic-modules/src/modules/blockquote/menu/BlockquoteMenu.ts @@ -4,11 +4,11 @@ */ import { Editor, Transforms } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { QUOTE_SVG } from '../../../constants/icon-svg' class BlockquoteMenu implements IButtonMenu { - readonly title = '引用' + readonly title = t('blockQuote.title') readonly iconSvg = QUOTE_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/code-block/menu/CodeBlockMenu.ts b/packages/basic-modules/src/modules/code-block/menu/CodeBlockMenu.ts index 83b6695ef..9c9214840 100644 --- a/packages/basic-modules/src/modules/code-block/menu/CodeBlockMenu.ts +++ b/packages/basic-modules/src/modules/code-block/menu/CodeBlockMenu.ts @@ -4,12 +4,12 @@ */ import { Editor, Element, Transforms, Node } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { CODE_BLOCK_SVG } from '../../../constants/icon-svg' import { CodeElement } from '../custom-types' class CodeBlockMenu implements IButtonMenu { - readonly title = '代码块' + readonly title = t('codeBlock.title') readonly iconSvg = CODE_BLOCK_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/color/menu/BaseMenu.ts b/packages/basic-modules/src/modules/color/menu/BaseMenu.ts index 0f298b4ed..7e645e631 100644 --- a/packages/basic-modules/src/modules/color/menu/BaseMenu.ts +++ b/packages/basic-modules/src/modules/color/menu/BaseMenu.ts @@ -4,7 +4,7 @@ */ import { Editor, Range } from 'slate' -import { IDropPanelMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IDropPanelMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import $, { Dom7Array } from '../../../utils/dom' import { CLEAN_SVG } from '../../../constants/icon-svg' @@ -110,8 +110,8 @@ abstract class BaseMenu implements IDropPanelMenu { // 清除颜色 let clearText = '' - if (mark === 'color') clearText = '默认颜色' - if (mark === 'bgColor') clearText = '清除背景色' + if (mark === 'color') clearText = t('color.default') + if (mark === 'bgColor') clearText = t('color.clear') const $clearLi = $(`
  • ${CLEAN_SVG} diff --git a/packages/basic-modules/src/modules/color/menu/BgColorMenu.ts b/packages/basic-modules/src/modules/color/menu/BgColorMenu.ts index b39f036d5..c665cba6e 100644 --- a/packages/basic-modules/src/modules/color/menu/BgColorMenu.ts +++ b/packages/basic-modules/src/modules/color/menu/BgColorMenu.ts @@ -3,11 +3,12 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { BG_COLOR_SVG } from '../../../constants/icon-svg' class BgColorMenu extends BaseMenu { - readonly title = '背景颜色' + readonly title = t('color.bgColor') readonly iconSvg = BG_COLOR_SVG readonly mark = 'bgColor' } diff --git a/packages/basic-modules/src/modules/color/menu/ColorMenu.ts b/packages/basic-modules/src/modules/color/menu/ColorMenu.ts index 412c30d56..9b73e4348 100644 --- a/packages/basic-modules/src/modules/color/menu/ColorMenu.ts +++ b/packages/basic-modules/src/modules/color/menu/ColorMenu.ts @@ -3,11 +3,12 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { FONT_COLOR_SVG } from '../../../constants/icon-svg' class ColorMenu extends BaseMenu { - readonly title = '文字颜色' + readonly title = t('color.color') readonly iconSvg = FONT_COLOR_SVG readonly mark = 'color' } diff --git a/packages/basic-modules/src/modules/divider/menu/InsertDividerMenu.ts b/packages/basic-modules/src/modules/divider/menu/InsertDividerMenu.ts index 7a50a29d2..9cf62b6c1 100644 --- a/packages/basic-modules/src/modules/divider/menu/InsertDividerMenu.ts +++ b/packages/basic-modules/src/modules/divider/menu/InsertDividerMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { DIVIDER_SVG } from '../../../constants/icon-svg' import { DividerElement } from '../custom-types' class InsertDividerMenu implements IButtonMenu { - readonly title = '分割线' + readonly title = t('divider.title') readonly iconSvg = DIVIDER_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/emotion/menu/EmotionMenu.ts b/packages/basic-modules/src/modules/emotion/menu/EmotionMenu.ts index 064ea9e44..a8f2437f0 100644 --- a/packages/basic-modules/src/modules/emotion/menu/EmotionMenu.ts +++ b/packages/basic-modules/src/modules/emotion/menu/EmotionMenu.ts @@ -4,12 +4,12 @@ */ import { Editor } from 'slate' -import { IDropPanelMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IDropPanelMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import $, { Dom7Array } from '../../../utils/dom' import { EMOTION_SVG } from '../../../constants/icon-svg' class EmotionMenu implements IDropPanelMenu { - readonly title = '表情' + readonly title = t('emotion.title') readonly iconSvg = EMOTION_SVG readonly tag = 'button' readonly showDropPanel = true // 点击 button 时显示 dropPanel diff --git a/packages/basic-modules/src/modules/font-size-family/menu/FontFamilyMenu.ts b/packages/basic-modules/src/modules/font-size-family/menu/FontFamilyMenu.ts index 47a1d2541..0e8971ac0 100644 --- a/packages/basic-modules/src/modules/font-size-family/menu/FontFamilyMenu.ts +++ b/packages/basic-modules/src/modules/font-size-family/menu/FontFamilyMenu.ts @@ -3,12 +3,12 @@ * @author wangfupeng */ -import { IDomEditor, IOption } from '@wangeditor/core' +import { IDomEditor, IOption, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { FONT_FAMILY_SVG } from '../../../constants/icon-svg' class FontFamilyMenu extends BaseMenu { - readonly title = '字体' + readonly title = t('fontFamily.title') readonly iconSvg = FONT_FAMILY_SVG readonly mark = 'fontFamily' readonly selectPanelWidth = 150 @@ -21,7 +21,7 @@ class FontFamilyMenu extends BaseMenu { // 生成 options options.push({ - text: '默认字体', + text: t('fontFamily.default'), value: '', // this.getValue(editor) 未找到结果时,会返回 '' ,正好对应到这里 }) fontFamilyList.forEach((family: string | { name: string; value: string }) => { diff --git a/packages/basic-modules/src/modules/font-size-family/menu/FontSizeMenu.ts b/packages/basic-modules/src/modules/font-size-family/menu/FontSizeMenu.ts index 3c1ed28ef..2b2c7ea83 100644 --- a/packages/basic-modules/src/modules/font-size-family/menu/FontSizeMenu.ts +++ b/packages/basic-modules/src/modules/font-size-family/menu/FontSizeMenu.ts @@ -3,12 +3,12 @@ * @author wangfupeng */ -import { IDomEditor, IOption } from '@wangeditor/core' +import { IDomEditor, IOption, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { FONT_SIZE_SVG } from '../../../constants/icon-svg' class FontSizeMenu extends BaseMenu { - readonly title = '字号' + readonly title = t('fontSize.title') readonly iconSvg = FONT_SIZE_SVG readonly mark = 'fontSize' @@ -20,7 +20,7 @@ class FontSizeMenu extends BaseMenu { // 生成 options options.push({ - text: '默认字号', + text: t('fontSize.default'), value: '', // this.getValue(editor) 未找到结果时,会返回 '' ,正好对应到这里 }) fontSizeList.forEach((size: string) => { diff --git a/packages/basic-modules/src/modules/full-screen/menu/FullScreen.ts b/packages/basic-modules/src/modules/full-screen/menu/FullScreen.ts index b589a7ee4..682222a9e 100644 --- a/packages/basic-modules/src/modules/full-screen/menu/FullScreen.ts +++ b/packages/basic-modules/src/modules/full-screen/menu/FullScreen.ts @@ -3,11 +3,11 @@ * @author wangfupeng */ -import { IButtonMenu, IDomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, t } from '@wangeditor/core' import { FULL_SCREEN_SVG } from '../../../constants/icon-svg' class FullScreen implements IButtonMenu { - title = '全屏' + title = t('fullScreen.title') iconSvg = FULL_SCREEN_SVG tag = 'button' diff --git a/packages/basic-modules/src/modules/header/menu/HeaderSelectMenu.ts b/packages/basic-modules/src/modules/header/menu/HeaderSelectMenu.ts index 3050357db..a79031d15 100644 --- a/packages/basic-modules/src/modules/header/menu/HeaderSelectMenu.ts +++ b/packages/basic-modules/src/modules/header/menu/HeaderSelectMenu.ts @@ -3,12 +3,12 @@ * @author wangfupeng */ -import { ISelectMenu, IDomEditor, IOption } from '@wangeditor/core' +import { ISelectMenu, IDomEditor, IOption, t } from '@wangeditor/core' import { HEADER_SVG } from '../../../constants/icon-svg' import { getHeaderType, isMenuDisabled, setHeaderType } from '../helper' class HeaderSelectMenu implements ISelectMenu { - readonly title = '标题' + readonly title = t('header.title') readonly iconSvg = HEADER_SVG readonly tag = 'select' readonly width = 60 @@ -42,7 +42,7 @@ class HeaderSelectMenu implements ISelectMenu { text: 'H5', styleForRenderMenuList: { 'font-size': '13px', 'font-weight': 'bold' }, }, - { value: 'paragraph', text: '正文' }, + { value: 'paragraph', text: t('header.text') }, ] // 获取 value ,设置 selected diff --git a/packages/basic-modules/src/modules/image/menu/DeleteImage.ts b/packages/basic-modules/src/modules/image/menu/DeleteImage.ts index cb3f091b4..60dddff33 100644 --- a/packages/basic-modules/src/modules/image/menu/DeleteImage.ts +++ b/packages/basic-modules/src/modules/image/menu/DeleteImage.ts @@ -4,11 +4,11 @@ */ import { Transforms } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { TRASH_SVG } from '../../../constants/icon-svg' class DeleteImage implements IButtonMenu { - readonly title = '删除图片' + readonly title = t('image.delete') readonly iconSvg = TRASH_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/image/menu/EditImage.ts b/packages/basic-modules/src/modules/image/menu/EditImage.ts index ff1307af9..c40aad07c 100644 --- a/packages/basic-modules/src/modules/image/menu/EditImage.ts +++ b/packages/basic-modules/src/modules/image/menu/EditImage.ts @@ -10,6 +10,7 @@ import { DomEditor, genModalInputElems, genModalButtonElems, + t, } from '@wangeditor/core' import $, { Dom7Array } from '../../../utils/dom' import { genRandomStr } from '../../../utils/util' @@ -25,7 +26,7 @@ function genDomID(): string { } class EditImage implements IModalMenu { - readonly title = '编辑图片' + readonly title = t('image.edit') readonly iconSvg = PENCIL_SVG readonly tag = 'button' readonly showModal = true // 点击 button 时显示 modal @@ -80,10 +81,10 @@ class EditImage implements IModalMenu { } // 获取 input button elem - const [$srcContainer, $inputSrc] = genModalInputElems('图片地址', srcInputId) - const [$altContainer, $inputAlt] = genModalInputElems('描述文字', altInputId) - const [$hrefContainer, $inputHref] = genModalInputElems('图片链接', hrefInputId) - const [$buttonContainer] = genModalButtonElems(buttonId, '确定') + const [$srcContainer, $inputSrc] = genModalInputElems(t('image.src'), srcInputId) + const [$altContainer, $inputAlt] = genModalInputElems(t('image.desc'), altInputId) + const [$hrefContainer, $inputHref] = genModalInputElems(t('image.link'), hrefInputId) + const [$buttonContainer] = genModalButtonElems(buttonId, t('common.ok')) if (this.$content == null) { // 第一次渲染 diff --git a/packages/basic-modules/src/modules/image/menu/InsertImage.ts b/packages/basic-modules/src/modules/image/menu/InsertImage.ts index 710267a0a..830e2e35d 100644 --- a/packages/basic-modules/src/modules/image/menu/InsertImage.ts +++ b/packages/basic-modules/src/modules/image/menu/InsertImage.ts @@ -10,6 +10,7 @@ import { DomEditor, genModalInputElems, genModalButtonElems, + t, } from '@wangeditor/core' import $, { Dom7Array } from '../../../utils/dom' import { genRandomStr } from '../../../utils/util' @@ -24,7 +25,7 @@ function genDomID(): string { } class InsertImage implements IModalMenu { - readonly title = '网络图片' + readonly title = t('image.netImage') readonly iconSvg = IMAGE_SVG readonly tag = 'button' readonly showModal = true // 点击 button 时显示 modal @@ -84,10 +85,10 @@ class InsertImage implements IModalMenu { const { srcInputId, altInputId, hrefInputId, buttonId } = this // 获取 input button elem - const [$srcContainer, $inputSrc] = genModalInputElems('图片地址', srcInputId) - const [$altContainer, $inputAlt] = genModalInputElems('描述文字', altInputId) - const [$hrefContainer, $inputHref] = genModalInputElems('图片链接', hrefInputId) - const [$buttonContainer] = genModalButtonElems(buttonId, '确定') + const [$srcContainer, $inputSrc] = genModalInputElems(t('image.src'), srcInputId) + const [$altContainer, $inputAlt] = genModalInputElems(t('image.desc'), altInputId) + const [$hrefContainer, $inputHref] = genModalInputElems(t('image.link'), hrefInputId) + const [$buttonContainer] = genModalButtonElems(buttonId, t('common.ok')) if (this.$content == null) { // 第一次渲染 diff --git a/packages/basic-modules/src/modules/image/menu/ViewImageLink.ts b/packages/basic-modules/src/modules/image/menu/ViewImageLink.ts index bb612918a..ca61baaab 100644 --- a/packages/basic-modules/src/modules/image/menu/ViewImageLink.ts +++ b/packages/basic-modules/src/modules/image/menu/ViewImageLink.ts @@ -3,12 +3,12 @@ * @author wangfupeng */ -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { EXTERNAL_SVG } from '../../../constants/icon-svg' import { ImageElement } from '../custom-types' class ViewImageLink implements IButtonMenu { - readonly title = '查看链接' + readonly title = t('image.viewLink') readonly iconSvg = EXTERNAL_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/indent/menu/DecreaseIndentMenu.ts b/packages/basic-modules/src/modules/indent/menu/DecreaseIndentMenu.ts index a70d089f7..e449de2f9 100644 --- a/packages/basic-modules/src/modules/indent/menu/DecreaseIndentMenu.ts +++ b/packages/basic-modules/src/modules/indent/menu/DecreaseIndentMenu.ts @@ -4,13 +4,13 @@ */ import { Transforms, Element } from 'slate' -import { IDomEditor } from '@wangeditor/core' +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { INDENT_LEFT_SVG } from '../../../constants/icon-svg' import { IndentElement } from '../custom-types' class DecreaseIndentMenu extends BaseMenu { - readonly title = '减少缩进' + readonly title = t('indent.decrease') readonly iconSvg = INDENT_LEFT_SVG isDisabled(editor: IDomEditor): boolean { diff --git a/packages/basic-modules/src/modules/indent/menu/IncreaseIndentMenu.ts b/packages/basic-modules/src/modules/indent/menu/IncreaseIndentMenu.ts index 5c6a45c4d..ebc6a6afe 100644 --- a/packages/basic-modules/src/modules/indent/menu/IncreaseIndentMenu.ts +++ b/packages/basic-modules/src/modules/indent/menu/IncreaseIndentMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms, Element } from 'slate' -import { IDomEditor } from '@wangeditor/core' +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { INDENT_RIGHT_SVG } from '../../../constants/icon-svg' class IncreaseIndentMenu extends BaseMenu { - readonly title = '增加缩进' + readonly title = t('indent.increase') readonly iconSvg = INDENT_RIGHT_SVG isDisabled(editor: IDomEditor): boolean { diff --git a/packages/basic-modules/src/modules/justify/menu/JustifyCenterMenu.ts b/packages/basic-modules/src/modules/justify/menu/JustifyCenterMenu.ts index 6fca99046..712d88063 100644 --- a/packages/basic-modules/src/modules/justify/menu/JustifyCenterMenu.ts +++ b/packages/basic-modules/src/modules/justify/menu/JustifyCenterMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms, Element } from 'slate' -import { IDomEditor } from '@wangeditor/core' +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { JUSTIFY_CENTER_SVG } from '../../../constants/icon-svg' class JustifyCenterMenu extends BaseMenu { - readonly title = '居中对齐' + readonly title = t('justify.center') readonly iconSvg = JUSTIFY_CENTER_SVG exec(editor: IDomEditor, value: string | boolean): void { diff --git a/packages/basic-modules/src/modules/justify/menu/JustifyJustifyMenu.ts b/packages/basic-modules/src/modules/justify/menu/JustifyJustifyMenu.ts index 9c8cc3984..edee9d8e6 100644 --- a/packages/basic-modules/src/modules/justify/menu/JustifyJustifyMenu.ts +++ b/packages/basic-modules/src/modules/justify/menu/JustifyJustifyMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms, Element } from 'slate' -import { IDomEditor } from '@wangeditor/core' +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { JUSTIFY_JUSTIFY_SVG } from '../../../constants/icon-svg' class JustifyJustifyMenu extends BaseMenu { - readonly title = '两端对齐' + readonly title = t('justify.justify') readonly iconSvg = JUSTIFY_JUSTIFY_SVG exec(editor: IDomEditor, value: string | boolean): void { diff --git a/packages/basic-modules/src/modules/justify/menu/JustifyLeftMenu.ts b/packages/basic-modules/src/modules/justify/menu/JustifyLeftMenu.ts index d9fe7209c..51b3ad2b3 100644 --- a/packages/basic-modules/src/modules/justify/menu/JustifyLeftMenu.ts +++ b/packages/basic-modules/src/modules/justify/menu/JustifyLeftMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms, Element } from 'slate' -import { IDomEditor } from '@wangeditor/core' +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { JUSTIFY_LEFT_SVG } from '../../../constants/icon-svg' class JustifyLeftMenu extends BaseMenu { - readonly title = '左对齐' + readonly title = t('justify.left') readonly iconSvg = JUSTIFY_LEFT_SVG exec(editor: IDomEditor, value: string | boolean): void { diff --git a/packages/basic-modules/src/modules/justify/menu/JustifyRightMenu.ts b/packages/basic-modules/src/modules/justify/menu/JustifyRightMenu.ts index 3c28203bf..0c7107ae0 100644 --- a/packages/basic-modules/src/modules/justify/menu/JustifyRightMenu.ts +++ b/packages/basic-modules/src/modules/justify/menu/JustifyRightMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms, Element } from 'slate' -import { IDomEditor } from '@wangeditor/core' +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { JUSTIFY_RIGHT_SVG } from '../../../constants/icon-svg' class JustifyRightMenu extends BaseMenu { - readonly title = '右对齐' + readonly title = t('justify.right') readonly iconSvg = JUSTIFY_RIGHT_SVG exec(editor: IDomEditor, value: string | boolean): void { diff --git a/packages/basic-modules/src/modules/line-height/menu/LineHeightMenu.ts b/packages/basic-modules/src/modules/line-height/menu/LineHeightMenu.ts index f8743902e..c95a158e5 100644 --- a/packages/basic-modules/src/modules/line-height/menu/LineHeightMenu.ts +++ b/packages/basic-modules/src/modules/line-height/menu/LineHeightMenu.ts @@ -4,12 +4,12 @@ */ import { Editor, Node, Element, Transforms } from 'slate' -import { ISelectMenu, IDomEditor, DomEditor, IOption } from '@wangeditor/core' +import { ISelectMenu, IDomEditor, DomEditor, IOption, t } from '@wangeditor/core' import { LINE_HEIGHT_SVG } from '../../../constants/icon-svg' import { LineHeightElement } from '../custom-types' class LineHeightMenu implements ISelectMenu { - readonly title = '行高' + readonly title = t('lineHeight.title') readonly iconSvg = LINE_HEIGHT_SVG readonly tag = 'select' readonly width = 80 @@ -22,7 +22,7 @@ class LineHeightMenu implements ISelectMenu { // 生成 options options.push({ - text: '默认行高', + text: t('lineHeight.default'), value: '', // this.getValue(editor) 未找到结果时,会返回 '' ,正好对应到这里 }) lineHeightList.forEach((height: string) => { diff --git a/packages/basic-modules/src/modules/link/helper.ts b/packages/basic-modules/src/modules/link/helper.ts index 993f74905..13764036b 100644 --- a/packages/basic-modules/src/modules/link/helper.ts +++ b/packages/basic-modules/src/modules/link/helper.ts @@ -46,7 +46,7 @@ export function isMenuDisabled(editor: IDomEditor): boolean { if (editor.isVoid(elem)) return true if (['pre', 'code', 'link'].includes(type)) return true }) - if (notMatch) return true // disbled + if (notMatch) return true // disabled return false // enable } diff --git a/packages/basic-modules/src/modules/link/menu/InsertLink.ts b/packages/basic-modules/src/modules/link/menu/InsertLink.ts index 1fb91d7f8..4dd7999b1 100644 --- a/packages/basic-modules/src/modules/link/menu/InsertLink.ts +++ b/packages/basic-modules/src/modules/link/menu/InsertLink.ts @@ -4,7 +4,13 @@ */ import { Editor, Range, Node } from 'slate' -import { IModalMenu, IDomEditor, genModalInputElems, genModalButtonElems } from '@wangeditor/core' +import { + IModalMenu, + IDomEditor, + genModalInputElems, + genModalButtonElems, + t, +} from '@wangeditor/core' import $, { Dom7Array } from '../../../utils/dom' import { genRandomStr } from '../../../utils/util' import { LINK_SVG } from '../../../constants/icon-svg' @@ -18,7 +24,7 @@ function genDomID(): string { } class InsertLinkMenu implements IModalMenu { - readonly title = '插入链接' + readonly title = t('link.insert') readonly iconSvg = LINK_SVG readonly tag = 'button' readonly showModal = true // 点击 button 时显示 modal @@ -56,9 +62,9 @@ class InsertLinkMenu implements IModalMenu { const { textInputId, urlInputId, buttonId } = this // 获取 input button elem - const [$textContainer, $inputText] = genModalInputElems('链接文本', textInputId) - const [$urlContainer, $inputUrl] = genModalInputElems('链接网址', urlInputId) - const [$buttonContainer] = genModalButtonElems(buttonId, '确定') + const [$textContainer, $inputText] = genModalInputElems(t('link.text'), textInputId) + const [$urlContainer, $inputUrl] = genModalInputElems(t('link.url'), urlInputId) + const [$buttonContainer] = genModalButtonElems(buttonId, t('common.ok')) if (this.$content == null) { // 第一次渲染 diff --git a/packages/basic-modules/src/modules/link/menu/UnLink.ts b/packages/basic-modules/src/modules/link/menu/UnLink.ts index 6a2074743..d801eb8bf 100644 --- a/packages/basic-modules/src/modules/link/menu/UnLink.ts +++ b/packages/basic-modules/src/modules/link/menu/UnLink.ts @@ -4,11 +4,11 @@ */ import { Transforms } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { UN_LINK_SVG } from '../../../constants/icon-svg' class UnLink implements IButtonMenu { - readonly title = '取消链接' + readonly title = t('link.unLink') readonly iconSvg = UN_LINK_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/link/menu/UpdateLink.ts b/packages/basic-modules/src/modules/link/menu/UpdateLink.ts index 562358610..059b39698 100644 --- a/packages/basic-modules/src/modules/link/menu/UpdateLink.ts +++ b/packages/basic-modules/src/modules/link/menu/UpdateLink.ts @@ -10,6 +10,7 @@ import { DomEditor, genModalInputElems, genModalButtonElems, + t, } from '@wangeditor/core' import $, { Dom7Array } from '../../../utils/dom' import { genRandomStr } from '../../../utils/util' @@ -25,7 +26,7 @@ function genDomID(): string { } class UpdateLinkMenu implements IModalMenu { - readonly title = '修改链接' + readonly title = t('link.update') readonly iconSvg = PENCIL_SVG readonly tag = 'button' readonly showModal = true // 点击 button 时显示 modal @@ -82,8 +83,8 @@ class UpdateLinkMenu implements IModalMenu { const { urlInputId, buttonId } = this // 获取 input button elem - const [$urlContainer, $inputUrl] = genModalInputElems('链接网址', urlInputId) - const [$buttonContainer] = genModalButtonElems(buttonId, '确定') + const [$urlContainer, $inputUrl] = genModalInputElems(t('link.url'), urlInputId) + const [$buttonContainer] = genModalButtonElems(buttonId, t('common.ok')) if (this.$content == null) { // 第一次渲染 diff --git a/packages/basic-modules/src/modules/link/menu/ViewLink.ts b/packages/basic-modules/src/modules/link/menu/ViewLink.ts index f4f7383c3..ead689771 100644 --- a/packages/basic-modules/src/modules/link/menu/ViewLink.ts +++ b/packages/basic-modules/src/modules/link/menu/ViewLink.ts @@ -3,12 +3,12 @@ * @author wangfupeng */ -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { EXTERNAL_SVG } from '../../../constants/icon-svg' import { LinkElement } from '../custom-types' class ViewLink implements IButtonMenu { - readonly title = '查看链接' + readonly title = t('link.view') readonly iconSvg = EXTERNAL_SVG readonly tag = 'button' @@ -47,7 +47,6 @@ class ViewLink implements IButtonMenu { if (!value || typeof value !== 'string') { throw new Error(`View link failed, link url is '${value}'`) - return } // 查看链接 diff --git a/packages/basic-modules/src/modules/text-style/menu/BoldMenu.ts b/packages/basic-modules/src/modules/text-style/menu/BoldMenu.ts index 51c308f7e..b0f982eec 100644 --- a/packages/basic-modules/src/modules/text-style/menu/BoldMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/BoldMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { BOLD_SVG } from '../../../constants/icon-svg' class BoldMenu extends BaseMenu { readonly mark = 'bold' - readonly title = '加粗' + readonly title = t('textStyle.bold') readonly iconSvg = BOLD_SVG readonly hotkey = 'mod+b' } diff --git a/packages/basic-modules/src/modules/text-style/menu/ClearStyleMenu.ts b/packages/basic-modules/src/modules/text-style/menu/ClearStyleMenu.ts index 681ba17cb..c2373abc1 100644 --- a/packages/basic-modules/src/modules/text-style/menu/ClearStyleMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/ClearStyleMenu.ts @@ -4,12 +4,12 @@ */ import { Editor, Text } from 'slate' -import { IButtonMenu, IDomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, t } from '@wangeditor/core' import { ERASER_SVG } from '../../../constants/icon-svg' import { isMenuDisabled, removeMarks } from '../helper' class ClearStyleMenu implements IButtonMenu { - readonly title = '清除格式' + readonly title = t('textStyle.clear') readonly iconSvg = ERASER_SVG readonly tag = 'button' diff --git a/packages/basic-modules/src/modules/text-style/menu/CodeMenu.ts b/packages/basic-modules/src/modules/text-style/menu/CodeMenu.ts index 91534f9eb..f9bd87c64 100644 --- a/packages/basic-modules/src/modules/text-style/menu/CodeMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/CodeMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { CODE_SVG } from '../../../constants/icon-svg' class CodeMenu extends BaseMenu { readonly mark = 'code' - readonly title = '行内代码' + readonly title = t('textStyle.code') readonly iconSvg = CODE_SVG readonly hotkey = 'mod+e' } diff --git a/packages/basic-modules/src/modules/text-style/menu/ItalicMenu.ts b/packages/basic-modules/src/modules/text-style/menu/ItalicMenu.ts index 7ce7f9f5c..9e34abd67 100644 --- a/packages/basic-modules/src/modules/text-style/menu/ItalicMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/ItalicMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { ITALIC_SVG } from '../../../constants/icon-svg' class ItalicMenu extends BaseMenu { readonly mark = 'italic' - readonly title = '斜体' + readonly title = t('textStyle.italic') readonly iconSvg = ITALIC_SVG readonly hotkey = 'mod+i' } diff --git a/packages/basic-modules/src/modules/text-style/menu/SubMenu.ts b/packages/basic-modules/src/modules/text-style/menu/SubMenu.ts index 00c99511d..88c7fb46a 100644 --- a/packages/basic-modules/src/modules/text-style/menu/SubMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/SubMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { SUB_SVG } from '../../../constants/icon-svg' class SubMenu extends BaseMenu { readonly mark = 'sub' - readonly title = '下标' + readonly title = t('textStyle.sub') readonly iconSvg = SUB_SVG readonly hotkey = '' } diff --git a/packages/basic-modules/src/modules/text-style/menu/SupMenu.ts b/packages/basic-modules/src/modules/text-style/menu/SupMenu.ts index b5113d257..47cff5ea1 100644 --- a/packages/basic-modules/src/modules/text-style/menu/SupMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/SupMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { SUP_SVG } from '../../../constants/icon-svg' class SupMenu extends BaseMenu { readonly mark = 'sup' - readonly title = '上标' + readonly title = t('textStyle.sup') readonly iconSvg = SUP_SVG readonly hotkey = '' } diff --git a/packages/basic-modules/src/modules/text-style/menu/ThroughMenu.ts b/packages/basic-modules/src/modules/text-style/menu/ThroughMenu.ts index 3f8c9cf08..2bd08a170 100644 --- a/packages/basic-modules/src/modules/text-style/menu/ThroughMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/ThroughMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { THROUGH_SVG } from '../../../constants/icon-svg' class ThroughMenu extends BaseMenu { readonly mark = 'through' - readonly title = '删除线' + readonly title = t('textStyle.through') readonly iconSvg = THROUGH_SVG readonly hotkey = 'mod+shift+x' } diff --git a/packages/basic-modules/src/modules/text-style/menu/UnderlineMenu.ts b/packages/basic-modules/src/modules/text-style/menu/UnderlineMenu.ts index 788e29904..f95a56c1f 100644 --- a/packages/basic-modules/src/modules/text-style/menu/UnderlineMenu.ts +++ b/packages/basic-modules/src/modules/text-style/menu/UnderlineMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { UNDER_LINE_SVG } from '../../../constants/icon-svg' class UnderlineMenu extends BaseMenu { readonly mark = 'underline' - readonly title = '下划线' + readonly title = t('textStyle.underline') readonly iconSvg = UNDER_LINE_SVG readonly hotkey = 'mod+u' } diff --git a/packages/basic-modules/src/modules/undo-redo/menu/RedoMenu.ts b/packages/basic-modules/src/modules/undo-redo/menu/RedoMenu.ts index cbbfb2523..48af32088 100644 --- a/packages/basic-modules/src/modules/undo-redo/menu/RedoMenu.ts +++ b/packages/basic-modules/src/modules/undo-redo/menu/RedoMenu.ts @@ -3,11 +3,11 @@ * @author wangfupeng */ -import { IButtonMenu, IDomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, t } from '@wangeditor/core' import { REDO_SVG } from '../../../constants/icon-svg' class RedoMenu implements IButtonMenu { - title = '重做' + title = t('undo.redo') iconSvg = REDO_SVG tag = 'button' diff --git a/packages/basic-modules/src/modules/undo-redo/menu/UndoMenu.ts b/packages/basic-modules/src/modules/undo-redo/menu/UndoMenu.ts index 7e1075da0..e195fabf3 100644 --- a/packages/basic-modules/src/modules/undo-redo/menu/UndoMenu.ts +++ b/packages/basic-modules/src/modules/undo-redo/menu/UndoMenu.ts @@ -3,11 +3,11 @@ * @author wangfupeng */ -import { IButtonMenu, IDomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, t } from '@wangeditor/core' import { UNDO_SVG } from '../../../constants/icon-svg' class UndoMenu implements IButtonMenu { - title = '撤销' + title = t('undo.undo') iconSvg = UNDO_SVG tag = 'button' diff --git a/packages/code-highlight/src/index.ts b/packages/code-highlight/src/index.ts index 3a6e775a8..b2f121fcc 100644 --- a/packages/code-highlight/src/index.ts +++ b/packages/code-highlight/src/index.ts @@ -5,6 +5,9 @@ import './assets/index.less' +// 配置多语言 +import './locale/index' + import wangEditorCodeHighlightModule from './module/index' import wangEditorCodeHighLightDecorate from './decorate' diff --git a/packages/code-highlight/src/locale/en.ts b/packages/code-highlight/src/locale/en.ts new file mode 100644 index 000000000..d79d010bd --- /dev/null +++ b/packages/code-highlight/src/locale/en.ts @@ -0,0 +1,10 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + highLightModule: { + selectLang: 'Language', + }, +} diff --git a/packages/code-highlight/src/locale/index.ts b/packages/code-highlight/src/locale/index.ts new file mode 100644 index 000000000..22f6ec6cb --- /dev/null +++ b/packages/code-highlight/src/locale/index.ts @@ -0,0 +1,11 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import { i18nAddResources } from '@wangeditor/core' +import enResources from './en' +import zhResources from './zh-CN' + +i18nAddResources('en', enResources) +i18nAddResources('zh-CN', zhResources) diff --git a/packages/code-highlight/src/locale/zh-CN.ts b/packages/code-highlight/src/locale/zh-CN.ts new file mode 100644 index 000000000..2da1d89ca --- /dev/null +++ b/packages/code-highlight/src/locale/zh-CN.ts @@ -0,0 +1,10 @@ +/** + * @description i18n zh-CN + * @author wangfupeng + */ + +export default { + highLightModule: { + selectLang: '选择语言', + }, +} diff --git a/packages/code-highlight/src/module/menu/SelectLangMenu.ts b/packages/code-highlight/src/module/menu/SelectLangMenu.ts index 2be3f0cec..2863f5935 100644 --- a/packages/code-highlight/src/module/menu/SelectLangMenu.ts +++ b/packages/code-highlight/src/module/menu/SelectLangMenu.ts @@ -4,12 +4,12 @@ */ import { Transforms, Element } from 'slate' -import { ISelectMenu, IDomEditor, IOption, DomEditor } from '@wangeditor/core' +import { ISelectMenu, IDomEditor, IOption, DomEditor, t } from '@wangeditor/core' import { JS_SVG } from '../../constants/svg' import { CodeElement } from '../../custom-types' class SelectLangMenu implements ISelectMenu { - readonly title = '选择语言' + readonly title = t('highLightModule.selectLang') readonly iconSvg = JS_SVG readonly tag = 'select' readonly width = 95 diff --git a/packages/core/package.json b/packages/core/package.json index b733de7bf..5ddaec563 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -61,7 +61,8 @@ "html-void-elements": "^2.0.0", "scroll-into-view-if-needed": "^2.2.28", "slate-history": "^0.62.0", - "xml-formatter": "^2.4.0" + "xml-formatter": "^2.4.0", + "i18next": "^20.4.0" }, "devDependencies": { "@types/event-emitter": "^0.3.3", diff --git a/packages/core/src/i18n/index.ts b/packages/core/src/i18n/index.ts new file mode 100644 index 000000000..7d7356d6d --- /dev/null +++ b/packages/core/src/i18n/index.ts @@ -0,0 +1,37 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import i18next from 'i18next' + +i18next.init({ + lng: 'zh-CN', + // debug: true, + resources: {}, // 资源为空,随后添加 +}) + +/** + * 添加多语言配置 + * @param lng 语言 + * @param resources 多语言配置 + */ +// TODO 补充到文档 +export function i18nAddResources(lng: string, resources: object) { + i18next.addResourceBundle(lng, 'translation', resources, true, true) +} + +/** + * 设置语言 + * @param lng 语言 + */ +export function i18nChangeLanguage(lng: string) { + i18next.changeLanguage('en') +} + +/** + * 翻译 + */ +export const t = i18next.t.bind(i18next) + +export default i18next diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2c8ece5c4..12a7e9876 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -32,6 +32,9 @@ export * from './menus/index' // upload export * from './upload/index' +// i18n +export * from './i18n/index' + export interface IModuleConf { // 注册菜单 menus: Array diff --git a/packages/editor/examples/i18n.html b/packages/editor/examples/i18n.html new file mode 100644 index 000000000..83fb1cc5c --- /dev/null +++ b/packages/editor/examples/i18n.html @@ -0,0 +1,47 @@ + + + + + + + i18n + + + + + + +

    i18n demo

    + + +
    +
    +
    +
    + + + + + + \ No newline at end of file diff --git a/packages/editor/examples/index.html b/packages/editor/examples/index.html index a96309cb7..087e20bdc 100644 --- a/packages/editor/examples/index.html +++ b/packages/editor/examples/index.html @@ -32,6 +32,7 @@

    wangEditor demo

  • 多编辑器
  • 获取标题/滚动到标题
  • 大文件 - 几万个字
  • +
  • i18n
  • 代码高亮
  • 批量销毁 - 测试内存泄漏
  • diff --git a/packages/editor/package.json b/packages/editor/package.json index a597017cf..07864cf97 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -2,7 +2,13 @@ "name": "@wangeditor/editor-cattle", "version": "0.2.3", "description": "Web rich text editor, Web 富文本编辑器", - "keywords": ["wangeditor", "rich text", "editor", "富文本", "编辑器"], + "keywords": [ + "wangeditor", + "rich text", + "editor", + "富文本", + "编辑器" + ], "author": "wangfupeng1988 ", "contributors": [], "homepage": "https://www.wangeditor.com/", diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts index 97ff2a326..587c857c9 100644 --- a/packages/editor/src/index.ts +++ b/packages/editor/src/index.ts @@ -6,6 +6,9 @@ import './assets/index.less' import '@wangeditor/core/dist/css/style.css' +// 配置多语言 +import './locale/index' + // 兼容浏览器 import './utils/browser-polyfill' // 兼容 node 环境 @@ -20,7 +23,14 @@ import Boot from './Boot' export { Boot } // 导出 core API 和接口(注意,此处按需导出,不可直接用 `*` ) -export { DomEditor, IDomEditor, IEditorConfig, IToolbarConfig, Toolbar } from '@wangeditor/core' +export { + DomEditor, + IDomEditor, + IEditorConfig, + IToolbarConfig, + Toolbar, + i18nChangeLanguage, +} from '@wangeditor/core' // 导出 slate API 和接口 (需重命名,加 `Slate` 前缀) export { diff --git a/packages/editor/src/init-default-config/config/toolbar.ts b/packages/editor/src/init-default-config/config/toolbar.ts index f5d978ed7..a0da0f001 100644 --- a/packages/editor/src/init-default-config/config/toolbar.ts +++ b/packages/editor/src/init-default-config/config/toolbar.ts @@ -3,6 +3,7 @@ * @author wangfupeng */ +import { t } from '@wangeditor/core' import { INDENT_RIGHT_SVG, JUSTIFY_LEFT_SVG, IMAGE_SVG, MORE_SVG } from '../../constants/svg' export function genDefaultToolbarKeys() { @@ -18,7 +19,7 @@ export function genDefaultToolbarKeys() { 'italic', { key: 'group-more-style', // 以 group 开头 - title: '更多样式', + title: t('editor.more'), iconSvg: MORE_SVG, menuKeys: ['through', 'code', 'sup', 'sub', 'clearStyle'], }, @@ -33,13 +34,13 @@ export function genDefaultToolbarKeys() { 'numberedList', { key: 'group-justify', // 以 group 开头 - title: '对齐', + title: t('editor.justify'), iconSvg: JUSTIFY_LEFT_SVG, menuKeys: ['justifyLeft', 'justifyRight', 'justifyCenter', 'justifyJustify'], }, { key: 'group-indent', // 以 group 开头 - title: '缩进', + title: t('editor.indent'), iconSvg: INDENT_RIGHT_SVG, menuKeys: ['indent', 'delIndent'], }, @@ -51,7 +52,7 @@ export function genDefaultToolbarKeys() { // 'viewLink', { key: 'group-image', // 以 group 开头 - title: '图片', + title: t('editor.image'), iconSvg: IMAGE_SVG, menuKeys: ['insertImage', 'uploadImage'], }, @@ -97,7 +98,7 @@ export function genSimpleToolbarKeys() { 'insertLink', { key: 'group-image', // 以 group 开头 - title: '图片', + title: t('editor.image'), iconSvg: IMAGE_SVG, menuKeys: ['insertImage', 'uploadImage'], }, diff --git a/packages/editor/src/locale/en.ts b/packages/editor/src/locale/en.ts new file mode 100644 index 000000000..f84d49c60 --- /dev/null +++ b/packages/editor/src/locale/en.ts @@ -0,0 +1,13 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + editor: { + more: 'More', + justify: 'Justify', + indent: 'Indent', + image: 'Image', + }, +} diff --git a/packages/editor/src/locale/index.ts b/packages/editor/src/locale/index.ts new file mode 100644 index 000000000..22f6ec6cb --- /dev/null +++ b/packages/editor/src/locale/index.ts @@ -0,0 +1,11 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import { i18nAddResources } from '@wangeditor/core' +import enResources from './en' +import zhResources from './zh-CN' + +i18nAddResources('en', enResources) +i18nAddResources('zh-CN', zhResources) diff --git a/packages/editor/src/locale/zh-CN.ts b/packages/editor/src/locale/zh-CN.ts new file mode 100644 index 000000000..68321c23f --- /dev/null +++ b/packages/editor/src/locale/zh-CN.ts @@ -0,0 +1,13 @@ +/** + * @description i18n zh-CN + * @author wangfupeng + */ + +export default { + editor: { + more: '更多', + justify: '对齐', + indent: '缩进', + image: '图片', + }, +} diff --git a/packages/list-module/src/index.ts b/packages/list-module/src/index.ts index cb9f362a2..a32d617ab 100644 --- a/packages/list-module/src/index.ts +++ b/packages/list-module/src/index.ts @@ -5,6 +5,9 @@ import './assets/index.less' -import wangEditorListModule from './module/index' +// 配置多语言 +import './locale/index' +// 导出 module +import wangEditorListModule from './module/index' export default wangEditorListModule diff --git a/packages/list-module/src/locale/en.ts b/packages/list-module/src/locale/en.ts new file mode 100644 index 000000000..86f1027f0 --- /dev/null +++ b/packages/list-module/src/locale/en.ts @@ -0,0 +1,11 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + listModule: { + unOrderedList: 'Unordered list', + orderedList: 'Ordered list', + }, +} diff --git a/packages/list-module/src/locale/index.ts b/packages/list-module/src/locale/index.ts new file mode 100644 index 000000000..22f6ec6cb --- /dev/null +++ b/packages/list-module/src/locale/index.ts @@ -0,0 +1,11 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import { i18nAddResources } from '@wangeditor/core' +import enResources from './en' +import zhResources from './zh-CN' + +i18nAddResources('en', enResources) +i18nAddResources('zh-CN', zhResources) diff --git a/packages/list-module/src/locale/zh-CN.ts b/packages/list-module/src/locale/zh-CN.ts new file mode 100644 index 000000000..c779d2359 --- /dev/null +++ b/packages/list-module/src/locale/zh-CN.ts @@ -0,0 +1,11 @@ +/** + * @description i18n zh-CN + * @author wangfupeng + */ + +export default { + listModule: { + unOrderedList: '无序列表', + orderedList: '有序列表', + }, +} diff --git a/packages/list-module/src/module/menu/BulletedListMenu.ts b/packages/list-module/src/module/menu/BulletedListMenu.ts index 324510251..2110cdb76 100644 --- a/packages/list-module/src/module/menu/BulletedListMenu.ts +++ b/packages/list-module/src/module/menu/BulletedListMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { BULLETED_LIST_SVG } from '../../constants/svg' class BulletedListMenu extends BaseMenu { readonly type = 'bulleted-list' - readonly title = '无序列表' + readonly title = t('listModule.unOrderedList') readonly iconSvg = BULLETED_LIST_SVG } diff --git a/packages/list-module/src/module/menu/NumberedListMenu.ts b/packages/list-module/src/module/menu/NumberedListMenu.ts index 9e0eb19c9..c53214b64 100644 --- a/packages/list-module/src/module/menu/NumberedListMenu.ts +++ b/packages/list-module/src/module/menu/NumberedListMenu.ts @@ -3,12 +3,13 @@ * @author wangfupeng */ +import { IDomEditor, t } from '@wangeditor/core' import BaseMenu from './BaseMenu' import { NUMBERED_LIST_SVG } from '../../constants/svg' class NumberedListMenu extends BaseMenu { readonly type = 'numbered-list' - readonly title = '有序列表' + readonly title = t('listModule.orderedList') readonly iconSvg = NUMBERED_LIST_SVG } diff --git a/packages/table-module/src/index.ts b/packages/table-module/src/index.ts index a949156cf..1fec86c6c 100644 --- a/packages/table-module/src/index.ts +++ b/packages/table-module/src/index.ts @@ -5,6 +5,8 @@ import './assets/index.less' -import wangEditorTableModule from './module/index' +// 配置多语言 +import './locale/index' +import wangEditorTableModule from './module/index' export default wangEditorTableModule diff --git a/packages/table-module/src/locale/en.ts b/packages/table-module/src/locale/en.ts new file mode 100644 index 000000000..7a8e6d370 --- /dev/null +++ b/packages/table-module/src/locale/en.ts @@ -0,0 +1,17 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + tableModule: { + deleteCol: 'Delete column', + deleteRow: 'Delete row', + deleteTable: 'Delete table', + widthJustify: 'Width justify', + insertCol: 'Insert column', + insertRow: 'Insert row', + insertTable: 'Insert table', + header: 'Header', + }, +} diff --git a/packages/table-module/src/locale/index.ts b/packages/table-module/src/locale/index.ts new file mode 100644 index 000000000..22f6ec6cb --- /dev/null +++ b/packages/table-module/src/locale/index.ts @@ -0,0 +1,11 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import { i18nAddResources } from '@wangeditor/core' +import enResources from './en' +import zhResources from './zh-CN' + +i18nAddResources('en', enResources) +i18nAddResources('zh-CN', zhResources) diff --git a/packages/table-module/src/locale/zh-CN.ts b/packages/table-module/src/locale/zh-CN.ts new file mode 100644 index 000000000..24fa19d35 --- /dev/null +++ b/packages/table-module/src/locale/zh-CN.ts @@ -0,0 +1,17 @@ +/** + * @description i18n zh-CN + * @author wangfupeng + */ + +export default { + tableModule: { + deleteCol: '删除列', + deleteRow: '删除行', + deleteTable: '删除表格', + widthJustify: '宽度自适应', + insertCol: '插入列', + insertRow: '插入行', + insertTable: '插入表格', + header: '表头', + }, +} diff --git a/packages/table-module/src/module/menu/DeleteCol.ts b/packages/table-module/src/module/menu/DeleteCol.ts index 6e7691915..7f01a64c8 100644 --- a/packages/table-module/src/module/menu/DeleteCol.ts +++ b/packages/table-module/src/module/menu/DeleteCol.ts @@ -5,11 +5,11 @@ import isEqual from 'lodash.isequal' import { Editor, Element, Transforms, Range, Node } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { DEL_COL_SVG } from '../../constants/svg' class DeleteCol implements IButtonMenu { - readonly title = '删除列' + readonly title = t('tableModule.deleteCol') readonly iconSvg = DEL_COL_SVG readonly tag = 'button' diff --git a/packages/table-module/src/module/menu/DeleteRow.ts b/packages/table-module/src/module/menu/DeleteRow.ts index 37515d3bf..4000dac10 100644 --- a/packages/table-module/src/module/menu/DeleteRow.ts +++ b/packages/table-module/src/module/menu/DeleteRow.ts @@ -4,11 +4,11 @@ */ import { Editor, Transforms, Range } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { DEL_ROW_SVG } from '../../constants/svg' class DeleteRow implements IButtonMenu { - readonly title = '删除行' + readonly title = t('tableModule.deleteRow') readonly iconSvg = DEL_ROW_SVG readonly tag = 'button' diff --git a/packages/table-module/src/module/menu/DeleteTable.ts b/packages/table-module/src/module/menu/DeleteTable.ts index 7d584dc01..4073c55ab 100644 --- a/packages/table-module/src/module/menu/DeleteTable.ts +++ b/packages/table-module/src/module/menu/DeleteTable.ts @@ -4,11 +4,11 @@ */ import { Transforms } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { TRASH_SVG } from '../../constants/svg' class DeleteTable implements IButtonMenu { - readonly title = '删除表格' + readonly title = t('tableModule.deleteTable') readonly iconSvg = TRASH_SVG readonly tag = 'button' diff --git a/packages/table-module/src/module/menu/FullWidth.ts b/packages/table-module/src/module/menu/FullWidth.ts index 3a3b8cba2..c1ff6c5d1 100644 --- a/packages/table-module/src/module/menu/FullWidth.ts +++ b/packages/table-module/src/module/menu/FullWidth.ts @@ -4,12 +4,12 @@ */ import { Transforms, Range } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { FULL_WIDTH_SVG } from '../../constants/svg' import { TableCellElement, TableRowElement, TableElement } from '../custom-types' class TableFullWidth implements IButtonMenu { - readonly title = '宽度自适应' + readonly title = t('tableModule.widthJustify') readonly iconSvg = FULL_WIDTH_SVG readonly tag = 'button' diff --git a/packages/table-module/src/module/menu/InsertCol.ts b/packages/table-module/src/module/menu/InsertCol.ts index f9f2add29..05a6a7f7a 100644 --- a/packages/table-module/src/module/menu/InsertCol.ts +++ b/packages/table-module/src/module/menu/InsertCol.ts @@ -5,12 +5,12 @@ import isEqual from 'lodash.isequal' import { Editor, Element, Transforms, Range, Node } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { ADD_COL_SVG } from '../../constants/svg' import { TableCellElement } from '../custom-types' class InsertCol implements IButtonMenu { - readonly title = '插入列' + readonly title = t('tableModule.insertCol') readonly iconSvg = ADD_COL_SVG readonly tag = 'button' diff --git a/packages/table-module/src/module/menu/InsertRow.ts b/packages/table-module/src/module/menu/InsertRow.ts index c044fec72..4c34a3c29 100644 --- a/packages/table-module/src/module/menu/InsertRow.ts +++ b/packages/table-module/src/module/menu/InsertRow.ts @@ -4,12 +4,12 @@ */ import { Editor, Transforms, Range, Path } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { ADD_ROW_SVG } from '../../constants/svg' import { TableRowElement, TableCellElement } from '../custom-types' class InsertRow implements IButtonMenu { - readonly title = '插入行' + readonly title = t('tableModule.insertRow') readonly iconSvg = ADD_ROW_SVG readonly tag = 'button' diff --git a/packages/table-module/src/module/menu/InsertTable.ts b/packages/table-module/src/module/menu/InsertTable.ts index df39b21f8..ca1607982 100644 --- a/packages/table-module/src/module/menu/InsertTable.ts +++ b/packages/table-module/src/module/menu/InsertTable.ts @@ -4,7 +4,7 @@ */ import { Editor, Transforms, Range, Node } from 'slate' -import { IDropPanelMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IDropPanelMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import $, { Dom7Array } from '../../utils/dom' import { genRandomStr } from '../../utils/util' import { TABLE_SVG } from '../../constants/svg' @@ -43,7 +43,7 @@ function genDomID(): string { } class InsertTable implements IDropPanelMenu { - title = '插入表格' + title = t('tableModule.insertTable') iconSvg = TABLE_SVG tag = 'button' showDropPanel = true // 点击 button 时显示 dropPanel diff --git a/packages/table-module/src/module/menu/TableHeader.ts b/packages/table-module/src/module/menu/TableHeader.ts index 549aa712f..d8caee252 100644 --- a/packages/table-module/src/module/menu/TableHeader.ts +++ b/packages/table-module/src/module/menu/TableHeader.ts @@ -4,12 +4,12 @@ */ import { Transforms, Range } from 'slate' -import { IButtonMenu, IDomEditor, DomEditor } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor/core' import { TABLE_HEADER_SVG } from '../../constants/svg' import { TableElement } from '../custom-types' class TableHeader implements IButtonMenu { - readonly title = '表头' + readonly title = t('tableModule.header') readonly iconSvg = TABLE_HEADER_SVG readonly tag = 'button' diff --git a/packages/upload-image-module/src/index.ts b/packages/upload-image-module/src/index.ts index 95b2828d0..81f332799 100644 --- a/packages/upload-image-module/src/index.ts +++ b/packages/upload-image-module/src/index.ts @@ -5,6 +5,8 @@ import './assets/index.less' -import wangEditorUploadImageModule from './module/index' +// 配置多语言 +import './locale/index' +import wangEditorUploadImageModule from './module/index' export default wangEditorUploadImageModule diff --git a/packages/upload-image-module/src/locale/en.ts b/packages/upload-image-module/src/locale/en.ts new file mode 100644 index 000000000..6d8e96d3a --- /dev/null +++ b/packages/upload-image-module/src/locale/en.ts @@ -0,0 +1,11 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + uploadImgModule: { + uploadImage: 'Upload Image', + uploadError: '{{fileName}} upload error', + }, +} diff --git a/packages/upload-image-module/src/locale/index.ts b/packages/upload-image-module/src/locale/index.ts new file mode 100644 index 000000000..22f6ec6cb --- /dev/null +++ b/packages/upload-image-module/src/locale/index.ts @@ -0,0 +1,11 @@ +/** + * @description i18n entry + * @author wangfupeng + */ + +import { i18nAddResources } from '@wangeditor/core' +import enResources from './en' +import zhResources from './zh-CN' + +i18nAddResources('en', enResources) +i18nAddResources('zh-CN', zhResources) diff --git a/packages/upload-image-module/src/locale/zh-CN.ts b/packages/upload-image-module/src/locale/zh-CN.ts new file mode 100644 index 000000000..148930d7c --- /dev/null +++ b/packages/upload-image-module/src/locale/zh-CN.ts @@ -0,0 +1,11 @@ +/** + * @description i18n zh-CN + * @author wangfupeng + */ + +export default { + uploadImgModule: { + uploadImage: '上传图片', + uploadError: '{{fileName}} 上传出错', + }, +} diff --git a/packages/upload-image-module/src/module/menu/UploadImageMenu.ts b/packages/upload-image-module/src/module/menu/UploadImageMenu.ts index 79a1e3ce0..9cab48d24 100644 --- a/packages/upload-image-module/src/module/menu/UploadImageMenu.ts +++ b/packages/upload-image-module/src/module/menu/UploadImageMenu.ts @@ -4,7 +4,7 @@ */ import Uppy, { UppyFile } from '@uppy/core' -import { IButtonMenu, IDomEditor, DomEditor, createUploader } from '@wangeditor/core' +import { IButtonMenu, IDomEditor, t, createUploader } from '@wangeditor/core' import { insertImageNode } from '@wangeditor/basic-modules' import { UPLOAD_IMAGE_SVG } from '../../constants/svg' import { isMenuDisabled } from '../helper' @@ -12,7 +12,7 @@ import $ from '../../utils/dom' import { IUploadConfigForImage } from './config' class UploadImage implements IButtonMenu { - readonly title = '上传图片' + readonly title = t('uploadImgModule.uploadImage') readonly iconSvg = UPLOAD_IMAGE_SVG readonly tag = 'button' private uppy: Uppy.Uppy<'strict'> | null = null @@ -156,9 +156,11 @@ class UploadImage implements IButtonMenu { // onError 提示错误 const errorHandler = (file: any, err: any, res: any) => { - console.error(`'${file.name} upload error`, err, res) + const fileName = file.name + console.error(`'${fileName} upload error`, err, res) - let info = `'${file.name}' 上传错误\n'${file.name}' upload error` + const info = t('uploadImgModule.uploadError', { fileName }) + // let info = `'${file.name}' 上传错误\n'${file.name}' upload error` editor.alert(info, 'error') // 回调函数 diff --git a/packages/video-module/src/index.ts b/packages/video-module/src/index.ts index e967fb219..6df002395 100644 --- a/packages/video-module/src/index.ts +++ b/packages/video-module/src/index.ts @@ -5,6 +5,8 @@ import './assets/index.less' -import wangEditorVideoModule from './module/index' +// 配置多语言 +import './locale/index' +import wangEditorVideoModule from './module/index' export default wangEditorVideoModule diff --git a/packages/video-module/src/locale/en.ts b/packages/video-module/src/locale/en.ts new file mode 100644 index 000000000..8dfa83a3c --- /dev/null +++ b/packages/video-module/src/locale/en.ts @@ -0,0 +1,14 @@ +/** + * @description i18n en + * @author wangfupeng + */ + +export default { + videoModule: { + delete: 'Delete', + insertVideo: 'Insert video', + videoSrc: 'video source', + insertPlaceHolder: 'video file url, or third-party