Skip to content

Commit c1f154a

Browse files
committed
feat: set locale option and api #1159
1 parent 9b7d13a commit c1f154a

File tree

9 files changed

+20
-3
lines changed

9 files changed

+20
-3
lines changed

docs/en/guide/option.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ new Editor(container, IEditorData | IElement[], {
1515
```typescript
1616
interface IEditorOption {
1717
mode?: EditorMode // Editor mode: Edit, Clean (Visual aids are not displayed, For example: page break), ReadOnly, Form (Only editable within the control), Print (Visual aids are not displayed, Unwritten content control), Design (Do not handle configurations such as non deletable and read-only). default: Edit
18+
locale?: string // Language. default: zhCN
1819
defaultType?: string // Default element type. default: TEXT
1920
defaultColor?: string // Default color. default: #000000
2021
defaultFont?: string // Default font. default: Microsoft YaHei

docs/guide/option.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ new Editor(container, IEditorData | IElement[], {
1515
```typescript
1616
interface IEditorOption {
1717
mode?: EditorMode // 编辑器模式:编辑、清洁(不显示视觉辅助元素。如:分页符)、只读、表单(仅控件内可编辑)、打印(不显示辅助元素、未书写控件及前后括号)、设计模式(不可删除、只读等配置不控制)。默认:编辑
18+
locale?: string // 多语言类型。默认:zhCN
1819
defaultType?: string // 默认元素类型。默认:TEXT
1920
defaultColor?: string // 默认字体颜色。默认:#000000
2021
defaultFont?: string // 默认字体。默认:Microsoft YaHei

src/editor/core/command/Command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class Command {
8989
public executeDeleteElementById: CommandAdapt['deleteElementById']
9090
public executeSetValue: CommandAdapt['setValue']
9191
public executeRemoveControl: CommandAdapt['removeControl']
92+
public executeTranslate: CommandAdapt['translate']
9293
public executeSetLocale: CommandAdapt['setLocale']
9394
public executeLocationCatalog: CommandAdapt['locationCatalog']
9495
public executeWordTool: CommandAdapt['wordTool']
@@ -238,6 +239,7 @@ export class Command {
238239
this.executeDeleteElementById = adapt.deleteElementById.bind(adapt)
239240
this.executeSetValue = adapt.setValue.bind(adapt)
240241
this.executeRemoveControl = adapt.removeControl.bind(adapt)
242+
this.executeTranslate = adapt.translate.bind(adapt)
241243
this.executeSetLocale = adapt.setLocale.bind(adapt)
242244
this.executeLocationCatalog = adapt.locationCatalog.bind(adapt)
243245
this.executeWordTool = adapt.wordTool.bind(adapt)

src/editor/core/command/CommandAdapt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,10 @@ export class CommandAdapt {
19901990
}
19911991
}
19921992

1993+
public translate(path: string): string {
1994+
return this.i18n.t(path)
1995+
}
1996+
19931997
public setLocale(payload: string) {
19941998
this.i18n.setLocale(payload)
19951999
}

src/editor/core/contextmenu/menus/hyperlinkMenus.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export const hyperlinkMenus: IRegisterContextMenu[] = [
4646
)
4747
},
4848
callback: (command: Command, context: IContextMenuContext) => {
49-
const url = window.prompt('编辑链接', context.startElement?.url)
49+
const url = window.prompt(
50+
command.executeTranslate('contextmenu.hyperlink.edit'),
51+
context.startElement?.url
52+
)
5053
if (url) {
5154
command.executeEditHyperlink(url)
5255
}

src/editor/core/draw/Draw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class Draw {
213213
this.pageContainer = this._createPageContainer()
214214
this._createPage(0)
215215

216-
this.i18n = new I18n()
216+
this.i18n = new I18n(options.locale)
217217
this.historyManager = new HistoryManager(this)
218218
this.position = new Position(this)
219219
this.zone = new Zone(this)

src/editor/core/i18n/I18n.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import { mergeObject } from '../../utils'
55
import { DeepPartial } from '../../interface/Common'
66

77
export class I18n {
8+
private currentLocale: string
9+
810
private langMap: Map<string, ILang> = new Map([
911
['zhCN', zhCN],
1012
['en', en]
1113
])
1214

13-
private currentLocale = 'zhCN'
15+
constructor(locale: string) {
16+
this.currentLocale = locale
17+
}
1418

1519
public registerLangMap(locale: string, lang: DeepPartial<ILang>) {
1620
const sourceLang = this.langMap.get(locale)

src/editor/interface/Editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface IEditorData {
3838

3939
export interface IEditorOption {
4040
mode?: EditorMode
41+
locale?: string
4142
defaultType?: string
4243
defaultColor?: string
4344
defaultFont?: string

src/editor/utils/option.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export function mergeOption(
150150

151151
return {
152152
mode: EditorMode.EDIT,
153+
locale: 'zhCN',
153154
defaultType: 'TEXT',
154155
defaultColor: '#000000',
155156
defaultFont: 'Microsoft YaHei',

0 commit comments

Comments
 (0)