refactor and update i18n, to be continue

pull/680/head
shiqstone 2021-04-15 11:21:50 +08:00
parent 6eb26fcb23
commit cbe47213d7
6 changed files with 68 additions and 12 deletions

View File

@ -5,7 +5,7 @@
/**
*
*/
function openLastSelectedNode() {
function openLastSelectedNode() {
//如果文档树或编辑器没有准备好则不加载文档
if (window.treeCatalog == null || window.editor == null) {
return false;
@ -81,7 +81,14 @@ function jstree_save(node, parent) {
var index = layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
locales = {
'zh-CN': {
saveSortSucc: '',
},
'en': {
saveSortSucc: 'Save sort success',
}
}
$.ajax({
url: window.sortURL,
type: "post",
@ -89,7 +96,7 @@ function jstree_save(node, parent) {
success: function (res) {
layer.close(index);
if (res.errcode === 0) {
layer.msg("保存排序成功");
layer.msg(locales[lang].saveSortSucc);
} else {
layer.msg(res.message);
}
@ -138,8 +145,27 @@ function getSiblingSort(node) {
* @param $node
*/
function openDeleteDocumentDialog($node) {
var index = layer.confirm('', {
btn: ['', ''] //按钮
locales = {
'zh-CN': {
saveSortSucc: '',
confirmDeleteDoc: '',
confirm: '',
cancel: '',
deleteFailed: '',
confirmLeave: ''
},
'en': {
saveSortSucc: 'Save sort success',
confirmDeleteDoc: 'Are you sure you want to delete this document?',
confirm: 'Confirm',
cancel: 'Cancel',
deleteFailed: 'Delete Failed',
confirmLeave: 'The content you entered has not been saved. Are you sure you want to leave this page?'
}
}
langs = locales[lang];
var index = layer.confirm(langs.confirmDeleteDoc, {
btn: [langs.confirm, langs.cancel] //按钮
}, function () {
$.post(window.deleteURL, {"identify": window.book.identify, "doc_id": $node.id}).done(function (res) {
@ -154,11 +180,11 @@ function openDeleteDocumentDialog($node) {
// console.log(window.documentCategory)
setLastSelectNode();
} else {
layer.msg("删除失败", {icon: 2})
layer.msg(lang.deleteFailed, {icon: 2})
}
}).fail(function () {
layer.close(index);
layer.msg("删除失败", {icon: 2})
layer.msg(lang.deleteFailed, {icon: 2})
});
});
@ -228,6 +254,14 @@ function pushVueLists($lists) {
*
*/
function releaseBook() {
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},
@ -235,7 +269,7 @@ function releaseBook() {
dataType: "json",
success: function (res) {
if (res.errcode === 0) {
layer.msg("发布任务已推送到任务队列,稍后将在后台执行。");
layer.msg(locales[lang].publishToQueue);
} else {
layer.msg(res.message);
}
@ -298,9 +332,17 @@ function showSuccess($msg, $id) {
}
window.documentHistory = function () {
locales = {
'zh-CN': {
hisVer: '',
},
'en': {
hisVer: 'Historic version',
}
}
layer.open({
type: 2,
title: '',
title: locales[lang].hisVer,
shadeClose: true,
shade: 0.8,
area: ['700px', '80%'],
@ -320,6 +362,16 @@ window.documentHistory = function () {
};
function uploadImage($id, $callback) {
locales = {
'zh-CN': {
unsupportType: '',
uploadFailed: ''
},
'en': {
unsupportType: 'Unsupport image type',
uploadFailed: 'Upload image failed'
}
}
/** 粘贴上传图片 **/
document.getElementById($id).addEventListener('paste', function (e) {
if (e.clipboardData && e.clipboardData.items) {
@ -345,7 +397,7 @@ function uploadImage($id, $callback) {
fileName += ".gif";
break;
default :
layer.msg("不支持的图片格式");
layer.msg(locales[lang].unsupportType);
return;
}
var form = new FormData();
@ -367,7 +419,7 @@ function uploadImage($id, $callback) {
error: function () {
layer.close(layerIndex);
$callback('error');
layer.msg("图片上传失败");
layer.msg(locales[lang].uploadFailed);
},
success: function (data) {
layer.close(layerIndex);

View File

@ -220,6 +220,7 @@
<script src="{{cdnjs "/static/js/blog.js" "version"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
lang = {{i18n $.Lang "common.js_lang"}};
window.vueApp.lists = {{.AttachList}};
$("#attachInfo").on("click",function () {
$("#uploadAttachModal").modal("show");

View File

@ -146,7 +146,7 @@
</div>
<div class="m-copyright">
<p>
本文档使用 <a href="https://www.iminho.me" target="_blank">MinDoc</a> 发布
{{i18n .Lang "doc.doc_publish_by"}} <a href="https://www.iminho.me" target="_blank">MinDoc</a> {{i18n .Lang "doc.doc_publish"}}
</p>
</div>
</div>

View File

@ -200,6 +200,7 @@
<script src="{{cdnjs "/static/js/html-editor.js"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
lang = {{i18n $.Lang "common.js_lang"}};
$("#attachInfo").on("click",function () {
$("#uploadAttachModal").modal("show");
});

View File

@ -442,6 +442,7 @@
<script src="{{cdnjs "/static/js/markdown.js" "version"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
lang = {{i18n $.Lang "common.js_lang"}};
$("#attachInfo").on("click",function () {
$("#uploadAttachModal").modal("show");
});

View File

@ -386,6 +386,7 @@
<script src="{{cdnjs "/static/js/quill.js"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
lang = {{i18n $.Lang "common.js_lang"}};
hljs.configure({ // optionally configure hljs
languages: ['javascript', 'ruby', 'python']
});