From 7aae1b23e96444f9ee25ea2a25b04944c376d12e Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 25 May 2022 14:40:51 +0800 Subject: [PATCH] Added mult language show error and notice --- Message.ts | 19 +++++++++++++++++++ main.ts | 18 +++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 Message.ts diff --git a/Message.ts b/Message.ts new file mode 100644 index 0000000..1154f2c --- /dev/null +++ b/Message.ts @@ -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] +} \ No newline at end of file diff --git a/main.ts b/main.ts index d04dc79..255638d 100644 --- a/main.ts +++ b/main.ts @@ -1,8 +1,5 @@ -import { timingSafeEqual } from "crypto"; import { App, - EditableFileView, - requestUrl, Editor, MarkdownView, Modal, @@ -16,6 +13,8 @@ import { join } from "path"; import * as fs from "fs"; import {addIcons} from 'icon'; import { Upload2Notion } from "Upload2Notion"; +import {NoticeMConfig} from "Message"; + // Remember to rename these classes and interfaces! @@ -24,6 +23,7 @@ interface MyPluginSettings { databaseID: string; bannerUrl: string; proxy: string; + langConfig: any; } const DEFAULT_SETTINGS: MyPluginSettings = { @@ -31,21 +31,21 @@ const DEFAULT_SETTINGS: MyPluginSettings = { databaseID: "", bannerUrl: "", proxy: "", + langConfig: NoticeMConfig( window.localStorage.getItem('language') || 'en') }; export default class MyPlugin extends Plugin { settings: MyPluginSettings; - async onload() { await this.loadSettings(); - addIcons(); + addIcons(); // This creates an icon in the left ribbon. const ribbonIconEl = this.addRibbonIcon( "notion-logo", "Share to notion", async (evt: MouseEvent) => { // Called when the user clicks the icon. - console.log(this,window.localStorage.getItem('language')) + this.upload(); @@ -90,9 +90,9 @@ export default class MyPlugin extends Plugin { const res = await upload.syncMarkdownToNotion(basename,fileData, fullPath) console.log(res) if(res.status === 200){ - new Notice(`${basename} 同步成功`) + new Notice(`${this.settings.langConfig["sync-success"]}${basename}`) }else { - new Notice(`${basename} 同步失败`) + new Notice(`${this.settings.langConfig["sync-fail"]}${basename}`) } } } @@ -112,7 +112,7 @@ export default class MyPlugin extends Plugin { fullPath, }; } else { - new Notice("请打开需要同步的文件"); + new Notice(this.settings.langConfig["open-file"]); return; } }