Added mult language show error and notice

This commit is contained in:
chris
2022-05-25 14:40:51 +08:00
parent 511a3e2289
commit 7aae1b23e9
2 changed files with 28 additions and 9 deletions

19
Message.ts Normal file
View File

@@ -0,0 +1,19 @@
export const NoticeMsg: {[key: string]:any} = {
"en": {
"notion-logo": "Share to notion",
"sync-success": "Sync to notion success: \n",
"sync-fail": "Sync to notion fail: \n",
"open-notion": "Please open the file that needs to be synchronized",
},
"zh": {
"notion-logo": "分享到Notion",
"sync-success": "同步到Notion成功:\n",
"sync-fail": "同步到Notion失败: \n",
"open-file": "请打开需要同步的文件"
},
}
export const NoticeMConfig = (lang:any) :any => {
return NoticeMsg[lang]
}

18
main.ts
View File

@@ -1,8 +1,5 @@
import { timingSafeEqual } from "crypto";
import { import {
App, App,
EditableFileView,
requestUrl,
Editor, Editor,
MarkdownView, MarkdownView,
Modal, Modal,
@@ -16,6 +13,8 @@ import { join } from "path";
import * as fs from "fs"; import * as fs from "fs";
import {addIcons} from 'icon'; import {addIcons} from 'icon';
import { Upload2Notion } from "Upload2Notion"; import { Upload2Notion } from "Upload2Notion";
import {NoticeMConfig} from "Message";
// Remember to rename these classes and interfaces! // Remember to rename these classes and interfaces!
@@ -24,6 +23,7 @@ interface MyPluginSettings {
databaseID: string; databaseID: string;
bannerUrl: string; bannerUrl: string;
proxy: string; proxy: string;
langConfig: any;
} }
const DEFAULT_SETTINGS: MyPluginSettings = { const DEFAULT_SETTINGS: MyPluginSettings = {
@@ -31,21 +31,21 @@ const DEFAULT_SETTINGS: MyPluginSettings = {
databaseID: "", databaseID: "",
bannerUrl: "", bannerUrl: "",
proxy: "", proxy: "",
langConfig: NoticeMConfig( window.localStorage.getItem('language') || 'en')
}; };
export default class MyPlugin extends Plugin { export default class MyPlugin extends Plugin {
settings: MyPluginSettings; settings: MyPluginSettings;
async onload() { async onload() {
await this.loadSettings(); await this.loadSettings();
addIcons(); addIcons();
// This creates an icon in the left ribbon. // This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon( const ribbonIconEl = this.addRibbonIcon(
"notion-logo", "notion-logo",
"Share to notion", "Share to notion",
async (evt: MouseEvent) => { async (evt: MouseEvent) => {
// Called when the user clicks the icon. // Called when the user clicks the icon.
console.log(this,window.localStorage.getItem('language'))
this.upload(); this.upload();
@@ -90,9 +90,9 @@ export default class MyPlugin extends Plugin {
const res = await upload.syncMarkdownToNotion(basename,fileData, fullPath) const res = await upload.syncMarkdownToNotion(basename,fileData, fullPath)
console.log(res) console.log(res)
if(res.status === 200){ if(res.status === 200){
new Notice(`${basename} 同步成功`) new Notice(`${this.settings.langConfig["sync-success"]}${basename}`)
}else { }else {
new Notice(`${basename} 同步失败`) new Notice(`${this.settings.langConfig["sync-fail"]}${basename}`)
} }
} }
} }
@@ -112,7 +112,7 @@ export default class MyPlugin extends Plugin {
fullPath, fullPath,
}; };
} else { } else {
new Notice("请打开需要同步的文件"); new Notice(this.settings.langConfig["open-file"]);
return; return;
} }
} }