feat: UI text internationalization in MD editor.

dev
DebuggerX 3 years ago
parent d2e07cd89d
commit a2553e1419

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

@ -2,3 +2,4 @@ library markdown_editor;
export 'package:markdown_editor_ot/src/editor.dart'; export 'package:markdown_editor_ot/src/editor.dart';
export 'package:markdown_editor_ot/src/preview.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, this.imageSelect,
required this.color, required this.color,
this.getCursorPosition, this.getCursorPosition,
required this.message,
}) : super(key: key); }) : super(key: key);
final ActionType type; final ActionType type;
@ -20,6 +21,8 @@ class ActionImage extends StatefulWidget {
final Color? color; final Color? color;
final String? message;
@override @override
ActionImageState createState() => ActionImageState(); ActionImageState createState() => ActionImageState();
} }
@ -60,7 +63,7 @@ class ActionImageState extends State<ActionImage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Tooltip( return Tooltip(
preferBelow: false, preferBelow: false,
message: _defaultImageAttributes message: widget.message ?? _defaultImageAttributes
.firstWhere((img) => img.type == widget.type) .firstWhere((img) => img.type == widget.type)
.tip, .tip,
child: IconButton( child: IconButton(
@ -243,7 +246,6 @@ enum ActionType {
fontBold, fontBold,
fontItalic, fontItalic,
fontStrikethrough, fontStrikethrough,
fontDeleteLine,
textQuote, textQuote,
list, list,
h1, h1,

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

@ -96,6 +96,7 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
) )
: MdEditor( : MdEditor(
initText: widget.initText, initText: widget.initText,
hintText: LocaleKeys.md_editor_init_text.tr(),
textFocusNode: _focusNode, textFocusNode: _focusNode,
padding: EdgeInsets.symmetric(horizontal: 5), padding: EdgeInsets.symmetric(horizontal: 5),
onComplete: (content) { onComplete: (content) {
@ -106,6 +107,23 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
else else
widget.onComplete(content); 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", "downloaded": "Downloaded",
"liked": "Liked" "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": "我的下载", "downloaded": "我的下载",
"liked": "我的点赞" "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