feat: UI text internationalization in MD editor.

dev
DebuggerX 3 years ago
parent d2e07cd89d
commit a2553e1419

@ -124,9 +124,9 @@
- [x] 方案下载功能实现
- [ ] 方案应用功能实现
- [x] 方案应用功能实现
- [ ] BugFix
- [ ] MD 编辑器中的UI文本国际化
- [x] MD 编辑器中的UI文本国际化
- [ ] 编写帮助说明文档
- [ ] 浅色模式界面优化
- [ ] 打包上架 Deepin/UOS 应用商店

@ -2,3 +2,4 @@ library markdown_editor;
export 'package:markdown_editor_ot/src/editor.dart';
export 'package:markdown_editor_ot/src/preview.dart';
export 'package:markdown_editor_ot/src/action.dart';

@ -11,6 +11,7 @@ class ActionImage extends StatefulWidget {
this.imageSelect,
required this.color,
this.getCursorPosition,
required this.message,
}) : super(key: key);
final ActionType type;
@ -20,6 +21,8 @@ class ActionImage extends StatefulWidget {
final Color? color;
final String? message;
@override
ActionImageState createState() => ActionImageState();
}
@ -60,7 +63,7 @@ class ActionImageState extends State<ActionImage> {
Widget build(BuildContext context) {
return Tooltip(
preferBelow: false,
message: _defaultImageAttributes
message: widget.message ?? _defaultImageAttributes
.firstWhere((img) => img.type == widget.type)
.tip,
child: IconButton(
@ -243,7 +246,6 @@ enum ActionType {
fontBold,
fontItalic,
fontStrikethrough,
fontDeleteLine,
textQuote,
list,
h1,

@ -24,6 +24,7 @@ class MdEditor extends StatefulWidget {
this.appendBottomWidget,
this.splitWidget,
this.textFocusNode,
required this.actionMessages,
required this.onComplete,
}) : super(key: key);
@ -51,6 +52,8 @@ class MdEditor extends StatefulWidget {
final OnComplete onComplete;
final Map<ActionType, String> actionMessages;
@override
State<StatefulWidget> createState() => MdEditorState();
}
@ -186,6 +189,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
widgets.add(ActionImage(
type: ActionType.done,
message: widget.actionMessages[ActionType.done],
color: widget.actionIconColor,
tap: (t, s, i, [p]) {
widget.onComplete(getText());
@ -194,6 +198,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
widgets.add(ActionImage(
type: ActionType.undo,
message: widget.actionMessages[ActionType.undo],
color: widget.actionIconColor,
tap: (t, s, i, [p]) {
_editPerform.undo();
@ -201,6 +206,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
));
widgets.add(ActionImage(
type: ActionType.redo,
message: widget.actionMessages[ActionType.redo],
color: widget.actionIconColor,
tap: (t, s, i, [p]) {
_editPerform.redo();
@ -237,6 +243,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.image),
widget: ActionImage(
type: ActionType.image,
message: widget.actionMessages[ActionType.image],
color: widget.actionIconColor,
tap: _disposeText,
imageSelect: widget.imageSelect,
@ -247,6 +254,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.link),
widget: ActionImage(
type: ActionType.link,
message: widget.actionMessages[ActionType.link],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -255,6 +263,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.fontBold),
widget: ActionImage(
type: ActionType.fontBold,
message: widget.actionMessages[ActionType.fontBold],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -263,6 +272,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.fontItalic),
widget: ActionImage(
type: ActionType.fontItalic,
message: widget.actionMessages[ActionType.fontItalic],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -271,6 +281,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.fontStrikethrough),
widget: ActionImage(
type: ActionType.fontStrikethrough,
message: widget.actionMessages[ActionType.fontStrikethrough],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -279,6 +290,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.textQuote),
widget: ActionImage(
type: ActionType.textQuote,
message: widget.actionMessages[ActionType.textQuote],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -287,6 +299,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.list),
widget: ActionImage(
type: ActionType.list,
message: widget.actionMessages[ActionType.list],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -295,6 +308,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.h4),
widget: ActionImage(
type: ActionType.h4,
message: widget.actionMessages[ActionType.h4],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -303,6 +317,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.h5),
widget: ActionImage(
type: ActionType.h5,
message: widget.actionMessages[ActionType.h5],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -311,6 +326,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.h1),
widget: ActionImage(
type: ActionType.h1,
message: widget.actionMessages[ActionType.h1],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -319,6 +335,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.h2),
widget: ActionImage(
type: ActionType.h2,
message: widget.actionMessages[ActionType.h2],
color: widget.actionIconColor,
tap: _disposeText,
),
@ -327,6 +344,7 @@ class MdEditorState extends State<MdEditor> with AutomaticKeepAliveClientMixin {
sortValue: getSortValue(ActionType.h3),
widget: ActionImage(
type: ActionType.h3,
message: widget.actionMessages[ActionType.h3],
color: widget.actionIconColor,
tap: _disposeText,
),

@ -96,6 +96,7 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
)
: MdEditor(
initText: widget.initText,
hintText: LocaleKeys.md_editor_init_text.tr(),
textFocusNode: _focusNode,
padding: EdgeInsets.symmetric(horizontal: 5),
onComplete: (content) {
@ -106,6 +107,23 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
else
widget.onComplete(content);
},
actionMessages: {
ActionType.done: LocaleKeys.md_editor_done.tr(),
ActionType.undo: LocaleKeys.md_editor_undo.tr(),
ActionType.redo: LocaleKeys.md_editor_redo.tr(),
ActionType.image: LocaleKeys.md_editor_image.tr(),
ActionType.link: LocaleKeys.md_editor_link.tr(),
ActionType.fontBold: LocaleKeys.md_editor_font_bold.tr(),
ActionType.fontItalic: LocaleKeys.md_editor_font_italic.tr(),
ActionType.fontStrikethrough: LocaleKeys.md_editor_font_strikethrough.tr(),
ActionType.textQuote: LocaleKeys.md_editor_text_quote.tr(),
ActionType.list: LocaleKeys.md_editor_list.tr(),
ActionType.h1: LocaleKeys.md_editor_h1.tr(),
ActionType.h2: LocaleKeys.md_editor_h2.tr(),
ActionType.h3: LocaleKeys.md_editor_h3.tr(),
ActionType.h4: LocaleKeys.md_editor_h4.tr(),
ActionType.h5: LocaleKeys.md_editor_h5.tr(),
},
),
);
}),

@ -185,5 +185,23 @@
"downloaded": "Downloaded",
"liked": "Liked"
}
},
"md_editor": {
"init_text": "Please enter a description",
"done": "Done",
"undo": "Undo",
"redo": "redo",
"image": "Image",
"link": "Link",
"font_bold": "FontBold",
"font_italic": "FontItalic",
"font_strikethrough": "FontStrikethrough",
"text_quote": "TextQuote",
"list": "List",
"h1": "H1",
"h2": "H2",
"h3": "H3",
"h4": "H4",
"h5": "H5"
}
}

@ -185,5 +185,23 @@
"downloaded": "我的下载",
"liked": "我的点赞"
}
},
"md_editor": {
"init_text": "请输入描述",
"done": "完成",
"undo": "撤销",
"redo": "重做",
"image": "图片",
"link": "链接",
"font_bold": "加粗",
"font_italic": "斜体",
"font_strikethrough": "删除线",
"text_quote": "文字引用",
"list": "无序列表",
"h1": "一级标题",
"h2": "二级标题",
"h3": "三级标题",
"h4": "四级标题",
"h5": "五级标题"
}
}
Loading…
Cancel
Save