Skip to content

Commit

Permalink
增加 wangEditor v4 的 国际化语言支持,support eng (#923)
Browse files Browse the repository at this point in the history
* [il8] 增加html 编辑器的英文模式

* [template] add window.lang

* [wangeditor v4] 更新多语音

* [i18n] update eng langure

* [i18n] update eng langure

* update releaseBook langure

---------

Co-authored-by: admin <[email protected]>
  • Loading branch information
ydf and admin authored Jan 5, 2024
1 parent 663eb28 commit e64bee1
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.o
*.a
*.so

.DS_Store
# Folders
_obj
_test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion static/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ function initHighlighting() {
}

$(function () {
locales = {
'zh-CN': {
attachments: ' 个附件',
},
'en': {
attachments: ' attachments',
}
}
window.vueApp = new Vue({
el: "#attachList",
data: {
Expand Down Expand Up @@ -484,7 +492,7 @@ $(function () {
},
watch: {
lists: function ($lists) {
$("#attachInfo").text(" " + $lists.length + " 个附件")
$("#attachInfo").text(" " + $lists.length + locales[lang].attachments)
}
}
});
Expand Down
104 changes: 85 additions & 19 deletions static/js/html-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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');
// 判断内容是否改变
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand All @@ -205,6 +262,7 @@ $(function () {
}



/**
* 添加顶级文档
*/
Expand Down Expand Up @@ -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) {

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
});
Expand All @@ -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</br> 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)
}
};

Expand Down
59 changes: 55 additions & 4 deletions static/js/quill.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
});
Expand All @@ -344,6 +394,7 @@ $(function () {
window.editor.root.innerHTML ='';
});


window.saveDocument = saveDocument;

window.releaseBook = function () {
Expand Down
Loading

0 comments on commit e64bee1

Please sign in to comment.