From e64bee1e1ecf9ee334c3c2485cc82d240395a302 Mon Sep 17 00:00:00 2001 From: ydf <4960943+ydf@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20wangEditor=20v4=20?= =?UTF-8?q?=E7=9A=84=20=E5=9B=BD=E9=99=85=E5=8C=96=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8Csupport=20eng=20(#923)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [il8] 增加html 编辑器的英文模式 * [template] add window.lang * [wangeditor v4] 更新多语音 * [i18n] update eng langure * [i18n] update eng langure * update releaseBook langure --------- Co-authored-by: admin --- .gitignore | 2 +- Dockerfile | 2 +- static/js/editor.js | 10 ++- static/js/html-editor.js | 104 ++++++++++++++++++---- static/js/quill.js | 59 +++++++++++- views/document/html_edit_template.tpl | 32 +++---- views/document/new_html_edit_template.tpl | 1 + 7 files changed, 169 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 0226ab6b..51e184ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.o *.a *.so - +.DS_Store # Folders _obj _test diff --git a/Dockerfile b/Dockerfile index 98bf9a95..45a3a382 100644 --- a/Dockerfile +++ b/Dockerfile @@ -136,4 +136,4 @@ ENTRYPOINT ["/bin/bash", "/mindoc/start.sh"] # https://docs.docker.com/engine/reference/commandline/run/#options # set MINDOC=//d/mindoc # windows # export MINDOC=/home/ubuntu/mindoc-docker # linux -# docker run --rm -it -p 8181:8181 -v "%MINDOC%":"/mindoc-sync-host" --name mindoc -e MINDOC_ENABLE_EXPORT=true -d gsw945/mindoc:2.1 +# docker run -d --name=mindoc --restart=always -v /www/mindoc/uploads:/mindoc/uploads -v /www/mindoc/database:/mindoc/database -v /www/mindoc/conf:/mindoc/conf -e MINDOC_DB_ADAPTER=sqlite3 -e MINDOC_DB_DATABASE=./database/mindoc.db -e MINDOC_CACHE=true -e MINDOC_CACHE_PROVIDER=file -p 8181:8181 mindoc-org/mindoc:v2.1 diff --git a/static/js/editor.js b/static/js/editor.js index 7668dfe4..81b7ff4e 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -447,6 +447,14 @@ function initHighlighting() { } $(function () { + locales = { + 'zh-CN': { + attachments: ' 个附件', + }, + 'en': { + attachments: ' attachments', + } + } window.vueApp = new Vue({ el: "#attachList", data: { @@ -484,7 +492,7 @@ $(function () { }, watch: { lists: function ($lists) { - $("#attachInfo").text(" " + $lists.length + " 个附件") + $("#attachInfo").text(" " + $lists.length + locales[lang].attachments) } } }); diff --git a/static/js/html-editor.js b/static/js/html-editor.js index 94be65ea..867ee864 100644 --- a/static/js/html-editor.js +++ b/static/js/html-editor.js @@ -46,6 +46,12 @@ $(function () { console.warn('You could only upload images.'); } }; + editor.config.lang = window.lang; + editor.i18next = window.i18next; + editor.config.languages['en']['wangEditor']['menus']['title']['保存'] = 'save'; + editor.config.languages['en']['wangEditor']['menus']['title']['发布'] = 'publish'; + editor.config.languages['en']['wangEditor']['menus']['title']['附件'] = 'attachment'; + editor.config.languages['en']['wangEditor']['menus']['title']['history'] = 'history'; /* editor.config.menus.splice(0,0,"|"); editor.config.menus.splice(0,0,"history"); @@ -80,6 +86,57 @@ $(function () { }; */ + window.editormdLocales = { + 'zh-CN': { + placeholder: '本编辑器支持 Markdown 编辑,左边编写,右边预览。', + contentUnsaved: '编辑内容未保存,需要保存吗?', + noDocNeedPublish: '没有需要发布的文档', + loadDocFailed: '文档加载失败', + fetchDocFailed: '获取当前文档信息失败', + cannotAddToEmptyNode: '空节点不能添加内容', + overrideModified: '文档已被其他人修改确定覆盖已存在的文档吗?', + confirm: '确定', + cancel: '取消', + contentsNameEmpty: '目录名称不能为空', + addDoc: '添加文档', + edit: '编辑', + delete: '删除', + loadFailed: '加载失败请重试', + tplNameEmpty: '模板名称不能为空', + tplContentEmpty: '模板内容不能为空', + saveSucc: '保存成功', + serverExcept: '服务器异常', + paramName: '参数名称', + paramType: '参数类型', + example: '示例值', + remark: '备注', + }, + 'en': { + placeholder: 'This editor supports Markdown editing, writing on the left and previewing on the right.', + contentUnsaved: 'The edited content is not saved, need to save it?', + noDocNeedPublish: 'No Document need to be publish', + loadDocFailed: 'Load Document failed', + fetchDocFailed: 'Fetch Document info failed', + cannotAddToEmptyNode: 'Cannot add content to empty node', + overrideModified: 'The document has been modified by someone else, are you sure to overwrite the document?', + confirm: 'Confirm', + cancel: 'Cancel', + contentsNameEmpty: 'Document Name cannot be empty', + addDoc: 'Add Document', + edit: 'Edit', + delete: 'Delete', + loadFailed: 'Failed to load, please try again', + tplNameEmpty: 'Template name cannot be empty', + tplContentEmpty: 'Template content cannot be empty', + saveSucc: 'Save success', + serverExcept: 'Server Exception', + paramName: 'Parameter', + paramType: 'Type', + example: 'Example', + remark: 'Remark', + } + }; + window.editor.config.onchange = function (newHtml) { var saveMenu = window.editor.menus.menuList.find((item) => item.key == 'save'); // 判断内容是否改变 @@ -150,8 +207,8 @@ $(function () { } var version = ""; - if(!node){ - layer.msg("获取当前文档信息失败"); + if (!node) { + layer.msg(editormdLocales[lang].fetchDocFailed); return; } var doc_id = parseInt(node.id); @@ -191,9 +248,9 @@ $(function () { callback(); } }else if(res.errcode === 6005){ - var confirmIndex = layer.confirm('文档已被其他人修改确定覆盖已存在的文档吗?', { - btn: ['确定','取消'] //按钮 - }, function(){ + var confirmIndex = layer.confirm(editormdLocales[lang].overrideModified, { + btn: [editormdLocales[lang].confirm, editormdLocales[lang].cancel] // 按钮 + }, function () { layer.close(confirmIndex); saveDocument(true,callback); }); @@ -205,6 +262,7 @@ $(function () { } + /** * 添加顶级文档 */ @@ -265,7 +323,7 @@ $(function () { "separator_before": false, "separator_after": true, "_disabled": false, - "label": "添加文档", + "label": window.editormdLocales[window.lang].addDoc,//"添加文档", "icon": "fa fa-plus", "action": function (data) { @@ -279,7 +337,7 @@ $(function () { "separator_before": false, "separator_after": true, "_disabled": false, - "label": "编辑", + "label": window.editormdLocales[window.lang].edit, "icon": "fa fa-edit", "action": function (data) { var inst = $.jstree.reference(data.reference); @@ -291,7 +349,7 @@ $(function () { "separator_before": false, "separator_after": true, "_disabled": false, - "label": "删除", + "label": window.editormdLocales[window.lang].delete, "icon": "fa fa-trash-o", "action": function (data) { var inst = $.jstree.reference(data.reference); @@ -305,7 +363,7 @@ $(function () { window.treeCatalog = $(this).jstree(); }).on('select_node.jstree', function (node, selected, event) { if(window.editor.menus.menuList.find((item) => item.key == 'save').$elem.hasClass('selected')) { - if(confirm("编辑内容未保存,需要保存吗?")){ + if (confirm(window.editormdLocales[window.lang].contentUnsaved)) { saveDocument(false,function () { loadDocument(selected); }); @@ -321,25 +379,33 @@ $(function () { window.releaseBook = function () { if(Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0){ if(window.editor.menus.menuList.find((item) => item.key == 'save').$elem.hasClass('selected')) { - if(confirm("编辑内容未保存,需要保存吗?")) { + if(confirm(editormdLocales[lang].contentUnsaved)) { saveDocument(); } } + locales = { + 'zh-CN': { + publishToQueue: '发布任务已推送到任务队列,稍后将在后台执行。', + }, + 'en': { + publishToQueue: 'The publish task has been pushed to the queue
and will be executed soon.', + } + } $.ajax({ - url : window.releaseURL, - data :{"identify" : window.book.identify }, - type : "post", - dataType : "json", - success : function (res) { - if(res.errcode === 0){ - layer.msg("发布任务已推送到任务队列,稍后将在后台执行。"); - }else{ + url: window.releaseURL, + data: {"identify": window.book.identify}, + type: "post", + dataType: "json", + success: function (res) { + if (res.errcode === 0) { + layer.msg(locales[lang].publishToQueue); + } else { layer.msg(res.message); } } }); }else{ - layer.msg("没有需要发布的文档") + layer.msg(editormdLocales[lang].noDocNeedPublish) } }; diff --git a/static/js/quill.js b/static/js/quill.js index c90854bd..4a4523aa 100644 --- a/static/js/quill.js +++ b/static/js/quill.js @@ -1,4 +1,54 @@ $(function () { + window.editormdLocales = { + 'zh-CN': { + placeholder: '本编辑器支持 Markdown 编辑,左边编写,右边预览。', + contentUnsaved: '编辑内容未保存,需要保存吗?', + noDocNeedPublish: '没有需要发布的文档', + loadDocFailed: '文档加载失败', + fetchDocFailed: '获取当前文档信息失败', + cannotAddToEmptyNode: '空节点不能添加内容', + overrideModified: '文档已被其他人修改确定覆盖已存在的文档吗?', + confirm: '确定', + cancel: '取消', + contentsNameEmpty: '目录名称不能为空', + addDoc: '添加文档', + edit: '编辑', + delete: '删除', + loadFailed: '加载失败请重试', + tplNameEmpty: '模板名称不能为空', + tplContentEmpty: '模板内容不能为空', + saveSucc: '保存成功', + serverExcept: '服务器异常', + paramName: '参数名称', + paramType: '参数类型', + example: '示例值', + remark: '备注', + }, + 'en': { + placeholder: 'This editor supports Markdown editing, writing on the left and previewing on the right.', + contentUnsaved: 'The edited content is not saved, need to save it?', + noDocNeedPublish: 'No Document need to be publish', + loadDocFailed: 'Load Document failed', + fetchDocFailed: 'Fetch Document info failed', + cannotAddToEmptyNode: 'Cannot add content to empty node', + overrideModified: 'The document has been modified by someone else, are you sure to overwrite the document?', + confirm: 'Confirm', + cancel: 'Cancel', + contentsNameEmpty: 'Document Name cannot be empty', + addDoc: 'Add Document', + edit: 'Edit', + delete: 'Delete', + loadFailed: 'Failed to load, please try again', + tplNameEmpty: 'Template name cannot be empty', + tplContentEmpty: 'Template content cannot be empty', + saveSucc: 'Save success', + serverExcept: 'Server Exception', + paramName: 'Parameter', + paramType: 'Type', + example: 'Example', + remark: 'Remark', + } + }; window.addDocumentModalFormHtml = $(this).find("form").html(); window.menu_save = $("#markdown-save"); window.uploader = null; @@ -286,7 +336,7 @@ $(function () { "separator_before": false, "separator_after": true, "_disabled": false, - "label": "添加文档", + "label": window.editormdLocales[window.lang].addDoc,//"添加文档", "icon": "fa fa-plus", "action": function (data) { @@ -300,7 +350,7 @@ $(function () { "separator_before": false, "separator_after": true, "_disabled": false, - "label": "编辑", + "label": window.editormdLocales[window.lang].edit, "icon": "fa fa-edit", "action": function (data) { var inst = $.jstree.reference(data.reference); @@ -312,7 +362,7 @@ $(function () { "separator_before": false, "separator_after": true, "_disabled": false, - "label": "删除", + "label": window.editormdLocales[window.lang].delete, "icon": "fa fa-trash-o", "action": function (data) { var inst = $.jstree.reference(data.reference); @@ -329,7 +379,7 @@ $(function () { }).on('select_node.jstree', function (node, selected, event) { if(window.menu_save.hasClass('change')) { - if(confirm("编辑内容未保存,需要保存吗?")){ + if (confirm(window.editormdLocales[window.lang].contentUnsaved)) { saveDocument(false,function () { loadDocument(selected); }); @@ -344,6 +394,7 @@ $(function () { window.editor.root.innerHTML =''; }); + window.saveDocument = saveDocument; window.releaseBook = function () { diff --git a/views/document/html_edit_template.tpl b/views/document/html_edit_template.tpl index 2f041dd8..828a043b 100644 --- a/views/document/html_edit_template.tpl +++ b/views/document/html_edit_template.tpl @@ -5,7 +5,7 @@ - 编辑文档 - Powered by MinDoc + {{i18n .Lang "doc.edit_doc"}} - Powered by MinDoc