Skip to content

Commit

Permalink
feat: i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfupeng1988 committed Aug 17, 2021
1 parent 44097b0 commit c11b244
Show file tree
Hide file tree
Showing 86 changed files with 675 additions and 124 deletions.
3 changes: 3 additions & 0 deletions packages/basic-modules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
90 changes: 90 additions & 0 deletions packages/basic-modules/src/locale/en.ts
Original file line number Diff line number Diff line change
@@ -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',
},
}
11 changes: 11 additions & 0 deletions packages/basic-modules/src/locale/index.ts
Original file line number Diff line number Diff line change
@@ -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)
90 changes: 90 additions & 0 deletions packages/basic-modules/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -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: '重做',
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
6 changes: 3 additions & 3 deletions packages/basic-modules/src/modules/color/menu/BaseMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 = $(`
<li data-value="0" class="clear">
${CLEAN_SVG}
Expand Down
3 changes: 2 additions & 1 deletion packages/basic-modules/src/modules/color/menu/BgColorMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
3 changes: 2 additions & 1 deletion packages/basic-modules/src/modules/color/menu/ColorMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -20,7 +20,7 @@ class FontSizeMenu extends BaseMenu {

// 生成 options
options.push({
text: '默认字号',
text: t('fontSize.default'),
value: '', // this.getValue(editor) 未找到结果时,会返回 '' ,正好对应到这里
})
fontSizeList.forEach((size: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit c11b244

Please sign in to comment.