From 571749f4c7859ef7e5741468a49e7b63fe25ca33 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Tue, 29 Oct 2024 23:22:42 +0800 Subject: [PATCH] save --- .vscode/settings.json | 5 +++- l10n/README.md | 39 ++++++++++++++++++++++++++ l10n/bundle.l10n.en.json | 46 ++++++++++++++++--------------- l10n/bundle.l10n.zh-cn.json | 46 ++++++++++++++++--------------- l10n/bundle.l10n.zh-tw.json | 46 ++++++++++++++++--------------- src/extension.ts | 14 +++++----- src/function/dide-viewer/api.ts | 21 +++++++------- src/function/dide-viewer/index.ts | 4 +-- src/function/lsp-client/index.ts | 8 +++--- src/function/tool.ts | 2 +- src/hdlParser/core.ts | 2 +- src/monitor/event.ts | 5 ++-- 12 files changed, 144 insertions(+), 94 deletions(-) create mode 100644 l10n/README.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 30bf8c2..811da37 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,8 @@ "out": true // set this to false to include "out" folder in search results }, // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off" + "typescript.tsc.autoDetect": "off", + "i18n-haru.root": "l10n", + "i18n-haru.main": "zh-cn", + "i18n-haru.line-hint-max-length": 20 } \ No newline at end of file diff --git a/l10n/README.md b/l10n/README.md new file mode 100644 index 0000000..aba9860 --- /dev/null +++ b/l10n/README.md @@ -0,0 +1,39 @@ +命名规则: + +```html +.. +``` + +比如 `info.monitor.update-pl` + +- info: 通知等级 +- monitor: 功能模块,此处是监视器 +- name: 对于模块功能的描述,可以是更加复杂的层级关系,比如 name.subname.subsubname + +上述的一个描述代表了一个如此的功能描述: + +该功能描述了 monitor 这个功能模块的一个名叫 update-pl 的功能,该功能在进行输出时,输出等级为 info. + +有的时候一个功能下可能希望更加细粒度的描述,比如说上面的 update-pl,这个功能的描述文本可以作为最终的主体文本(text),也可以作为最终描述该功能组件的标题(title),也可以是该功能的一个按钮(button)。总之,有的时候我们还希望指定该功能描述的一个实体/组件。所以下面的格式也是符合要求的: + +```html +... +``` + +比如以下的三组描述: + +```json +{ + "info.vcd-view.load.button": "加载", + "info.vcd-view.load.title": "加载", + "info.vcd-view.load.text": "正在加载 ..." +} +``` + +它们都代表了 `vcd-view` 这个功能模块的名为 `load` 的功能的中文翻译,但是这三个文本分别描述了实施这个 load 功能的功能组件: + +- `info.vcd-view.load.button` 描述了 button 位置上需要渲染的文本 +- `info.vcd-view.load.title` 描述了 title 位置上需要渲染的文本 +- `info.vcd-view.load.text` 描述了 text 位置上需要渲染的文本 + +关于如何进行规定 `` 位置上的值,应该由产品经理来规定。 \ No newline at end of file diff --git a/l10n/bundle.l10n.en.json b/l10n/bundle.l10n.en.json index 378cec3..7226ffe 100644 --- a/l10n/bundle.l10n.en.json +++ b/l10n/bundle.l10n.en.json @@ -1,25 +1,27 @@ { - "hello": "hello in English", - "welcome.title": "Thanks for using Digital-IDE ❤️. Your star will be our best motivation! 😊", - "welcome.star": "Star", - "welcome.refuse": "Refuse", - "progress.register-command": "Register Command", - "progress.active-lsp-server": "Activate LSP Server", - "progress.initialization": "Initialization", - "progress.build-module-tree": "Build Module Tree", - "progress.download-digital-lsp": "Download Digital LSP", - "progress.choose-best-download-source": "Choose Best Download Source", - "progress.extract-digital-lsp": "Extract Digital LSP", - "error.download-digital-lsp": "Fail to download digital lsp server, check your network and reload vscode. You can also visit following site and download manually: https://github.com/Digital-EDA/Digital-IDE/releases/tag/", - "error.save-file": "保存文件失败", + "info.test.hello": "hello in English", + "info.welcome.title": "Thanks for using Digital-IDE ❤️. Your star will be our best motivation! 😊", + "info.welcome.star": "Star", + "info.welcome.refuse": "Refuse", + "info.progress.register-command": "Register Command", + "info.progress.active-lsp-server": "Activate LSP Server", + "info.progress.initialization": "Initialization", + "info.progress.build-module-tree": "Build Module Tree", + "info.progress.download-digital-lsp": "Download Digital LSP", + "info.progress.choose-best-download-source": "Choose Best Download Source", + "info.progress.extract-digital-lsp": "Extract Digital LSP", + "error.lsp.download-digital-lsp": "Fail to download digital lsp server, check your network and reload vscode. You can also visit following site and download manually: https://github.com/Digital-EDA/Digital-IDE/releases/tag/", + "error.filelist.save-file": "保存文件失败", "warning.ppy-already-exist": "property.json 已经存在了!", - "save": "保存", - "save-as-view": "另存为视图文件", - "vcd-view-file": "vcd 视图文件", - "all-file": "所有文件", - "load": "加载", - "load-view-file": "加载视图文件", - "bad-view-file": "视图文件已损坏", - "error.unexist-direct-vcd-file": "视图文件指向的 vcd 文件不存在", - "click.join-qq-group": "Click the link to join the QQ group" + "info.monitor.update-hdlparam": "更新 HdlParam", + "info.monitor.update-pl": "更新 PL", + "info.vcd-viewer.save": "保存", + "info.vcd-viewer.save-as-view": "另存为视图文件", + "info.vcd-viewer.vcd-view-file": "vcd 视图文件", + "info.vcd-viewer.all-file": "所有文件", + "info.vcd-viewer.load.button": "加载", + "info.vcd-viewer.load.title": "加载视图文件", + "error.vcd-viewer.bad-view-file": "视图文件已损坏", + "error.vcd-viewer.unexist-direct-vcd-file": "视图文件指向的 vcd 文件不存在", + "info.welcome.join-qq-group": "Click the link to join the QQ group" } \ No newline at end of file diff --git a/l10n/bundle.l10n.zh-cn.json b/l10n/bundle.l10n.zh-cn.json index 57f1feb..71c4f1c 100644 --- a/l10n/bundle.l10n.zh-cn.json +++ b/l10n/bundle.l10n.zh-cn.json @@ -1,25 +1,27 @@ { - "hello": "你好", - "welcome.title": "感谢使用 Digital-IDE ❤️。您的支持将是我们最大的动力!😊", - "welcome.star": "支持", - "welcome.refuse": "拒绝", - "progress.register-command": "Digital IDE 注册命令", - "progress.active-lsp-server": "Digital IDE 激活语言服务器", - "progress.initialization": "Digital IDE 初始化", - "progress.build-module-tree": "构建模块树", - "progress.download-digital-lsp": "下载 Digital IDE 语言服务器", - "progress.choose-best-download-source": "选择最佳下载源", - "progress.extract-digital-lsp": "解压 Digital LSP 语言服务器", - "error.download-digital-lsp": "无法下载 Digital LSP 语言服务器,检查你的网络后重启 vscode,或者请手动去下方地址下载 https://github.com/Digital-EDA/Digital-IDE/releases/tag/", - "error.save-file": "保存文件失败", + "info.test.hello": "你好", + "info.welcome.title": "感谢使用 Digital-IDE ❤️。您的支持将是我们最大的动力!😊", + "info.welcome.star": "支持", + "info.welcome.refuse": "拒绝", + "info.progress.register-command": "Digital IDE 注册命令", + "info.progress.active-lsp-server": "Digital IDE 激活语言服务器", + "info.progress.initialization": "Digital IDE 初始化", + "info.progress.build-module-tree": "构建模块树", + "info.progress.download-digital-lsp": "下载 Digital IDE 语言服务器", + "info.progress.choose-best-download-source": "选择最佳下载源", + "info.progress.extract-digital-lsp": "解压 Digital LSP 语言服务器", + "error.lsp.download-digital-lsp": "无法下载 Digital LSP 语言服务器,检查你的网络后重启 vscode,或者请手动去下方地址下载 https://github.com/Digital-EDA/Digital-IDE/releases/tag/", + "error.filelist.save-file": "保存文件失败", "warning.ppy.already-exist": "property.json 已经存在了!", - "save": "保存", - "save-as-view": "另存为视图文件", - "vcd-view-file": "vcd 视图文件", - "all-file": "所有文件", - "load": "加载", - "load-view-file": "加载视图文件", - "bad-view-file": "视图文件已损坏", - "error.unexist-direct-vcd-file": "视图文件指向的 vcd 文件不存在", - "click.join-qq-group": "点击链接加入QQ群一起讨论" + "info.monitor.update-hdlparam": "更新 HdlParam", + "info.monitor.update-pl": "更新 PL", + "info.vcd-viewer.save": "保存", + "info.vcd-viewer.save-as-view": "另存为视图文件", + "info.vcd-viewer.vcd-view-file": "vcd 视图文件", + "info.vcd-viewer.all-file": "所有文件", + "info.vcd-viewer.load.button": "加载", + "info.vcd-viewer.load.title": "加载视图文件", + "error.vcd-viewer.bad-view-file": "视图文件已损坏", + "error.vcd-viewer.unexist-direct-vcd-file": "视图文件指向的 vcd 文件不存在", + "info.welcome.join-qq-group": "点击链接加入QQ群一起讨论" } \ No newline at end of file diff --git a/l10n/bundle.l10n.zh-tw.json b/l10n/bundle.l10n.zh-tw.json index 2b4367e..6ce1b31 100644 --- a/l10n/bundle.l10n.zh-tw.json +++ b/l10n/bundle.l10n.zh-tw.json @@ -1,25 +1,27 @@ { - "hello": "你好", - "welcome.title": "感謝使用 Digital-IDE ❤️。您的支持將是我們最大的動力!😊", - "welcome.star": "支持", - "welcome.refuse": "拒絕", - "progress.register-command": "(Digital IDE) 註冊命令", - "progress.active-lsp-server": "Activate LSP Server", - "progress.initialization": "(Digital IDE) 初始化", - "progress.build-module-tree": "構建模塊樹", - "progress.download-digital-lsp": "Download Digital LSP", - "progress.choose-best-download-source": "Choose Best Download Source", - "progress.extract-digital-lsp": "Extract Digital LSP", - "error.download-digital-lsp": "Fail to download digital lsp server, check your network and reload vscode", - "error.save-file": "保存文件失败", + "info.test.hello": "你好", + "info.welcome.title": "感謝使用 Digital-IDE ❤️。您的支持將是我們最大的動力!😊", + "info.welcome.star": "支持", + "info.welcome.refuse": "拒絕", + "info.progress.register-command": "(Digital IDE) 註冊命令", + "info.progress.active-lsp-server": "Activate LSP Server", + "info.progress.initialization": "(Digital IDE) 初始化", + "info.progress.build-module-tree": "構建模塊樹", + "info.progress.download-digital-lsp": "Download Digital LSP", + "info.progress.choose-best-download-source": "Choose Best Download Source", + "info.progress.extract-digital-lsp": "Extract Digital LSP", + "error.lsp.download-digital-lsp": "Fail to download digital lsp server, check your network and reload vscode", + "error.filelist.save-file": "保存文件失败", "warning.ppy-already-exist": "property.json 已经存在了!", - "save": "保存", - "save-as-view": "另存为视图文件", - "vcd-view-file": "vcd 视图文件", - "all-file": "所有文件", - "load": "加载", - "load-view-file": "加载视图文件", - "bad-view-file": "视图文件已损坏", - "error.unexist-direct-vcd-file": "视图文件指向的 vcd 文件不存在", - "click.join-qq-group": "点击链接加入QQ群一起讨论" + "info.monitor.update-hdlparam": "更新 HdlParam", + "info.monitor.update-pl": "更新 PL", + "info.vcd-viewer.save": "保存", + "info.vcd-viewer.save-as-view": "另存为视图文件", + "info.vcd-viewer.vcd-view-file": "vcd 视图文件", + "info.vcd-viewer.all-file": "所有文件", + "info.vcd-viewer.load.button": "加载", + "info.vcd-viewer.load.title": "加载视图文件", + "error.vcd-viewer.bad-view-file": "视图文件已损坏", + "error.vcd-viewer.unexist-direct-vcd-file": "视图文件指向的 vcd 文件不存在", + "info.welcome.join-qq-group": "点击链接加入QQ群一起讨论" } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index d156e0e..fbe08a0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -33,13 +33,13 @@ function getVersion(context: vscode.ExtensionContext): string { async function launch(context: vscode.ExtensionContext) { const { t } = vscode.l10n; - console.log(t('welcome.title')); - console.log(t('click.join-qq-group') + ' https://qm.qq.com/q/1M655h3GsA'); + console.log(t('info.welcome.title')); + console.log(t('info.welcome.join-qq-group') + ' https://qm.qq.com/q/1M655h3GsA'); const versionString = getVersion(context); await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, - title: t('progress.register-command') + title: t('info.progress.register-command') }, async () => { await registerCommand(context, versionString); }); @@ -49,7 +49,7 @@ async function launch(context: vscode.ExtensionContext) { await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, - title: t('progress.initialization') + title: t('info.progress.initialization') }, async (progress: vscode.Progress, token: vscode.CancellationToken) => { // 初始化解析 await manager.prjManage.initialise(context, progress); @@ -77,9 +77,9 @@ async function launch(context: vscode.ExtensionContext) { // don't show in next time welcomeSetting.update('show', false, vscode.ConfigurationTarget.Global); const res = await vscode.window.showInformationMessage( - t('welcome.title'), - { title: t('welcome.star'), value: true }, - { title: t('welcome.refuse'), value: false }, + t('info.welcome.title'), + { title: t('info.welcome.star'), value: true }, + { title: t('info.welcome.refuse'), value: false }, ); if (res?.value) { vscode.env.openExternal(vscode.Uri.parse('https://github.com/Digital-EDA/Digital-IDE')); diff --git a/src/function/dide-viewer/api.ts b/src/function/dide-viewer/api.ts index 8f3e44c..3273464 100644 --- a/src/function/dide-viewer/api.ts +++ b/src/function/dide-viewer/api.ts @@ -78,7 +78,8 @@ function getFilename(file: string) { export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.WebviewPanel) { const { t } = vscode.l10n; - + + try { // 先保存原来的文件 payload 一定是 all let { originVcdFile, originVcdViewFile, payload } = data; @@ -95,13 +96,13 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi // 询问新的路径 const defaultFilename = getFilename(payload.originVcdFile); const vcdFilters: Record = {}; - vcdFilters[t('vcd-view-file')] = ['view']; - vcdFilters[t('all-file')] = ['*']; - + vcdFilters[t('info.vcd-viewer.vcd-view-file')] = ['view']; + vcdFilters[t('info.vcd-viewer.all-file')] = ['*']; + const saveUri = await vscode.window.showSaveDialog({ - title: t('save-as-view'), + title: t('info.vcd-viewer.save-as-view'), defaultUri: vscode.Uri.file(path.join(rootPath, defaultFilename)), - saveLabel: t('save'), + saveLabel: t('info.vcd-viewer.save'), filters: vcdFilters }); @@ -144,13 +145,13 @@ export async function loadView(data: any, uri: vscode.Uri, panel: vscode.Webview const defaultFolder = path.dirname(vcdPath); const vcdFilters: Record = {}; - vcdFilters[t('vcd-view-file')] = ['view']; - vcdFilters[t('all-file')] = ['*']; + vcdFilters[t('info.vcd-viewer.vcd-view-file')] = ['view']; + vcdFilters[t('info.vcd-viewer.all-file')] = ['*']; const viewUri = await vscode.window.showOpenDialog({ - title: t('load-view-file'), + title: t('info.vcd-viewer.load.title'), defaultUri: vscode.Uri.file(defaultFolder), - openLabel: t('load'), + openLabel: t('info.vcd-viewer.load.button'), canSelectFiles: true, canSelectMany: false, canSelectFolders: false, diff --git a/src/function/dide-viewer/index.ts b/src/function/dide-viewer/index.ts index be2ec95..6cb0f91 100644 --- a/src/function/dide-viewer/index.ts +++ b/src/function/dide-viewer/index.ts @@ -221,14 +221,14 @@ function getViewLaunchFiles(context: vscode.ExtensionContext, uri: vscode.Uri, p if (recoverJson.originVcdFile) { const vcdPath = recoverJson.originVcdFile; if (!fs.existsSync(vcdPath)) { - return new Error(t('error.unexist-direct-vcd-file') + ':' + vcdPath); + return new Error(t('error.vcd-viewer.unexist-direct-vcd-file') + ':' + vcdPath); } const vcd = panel.webview.asWebviewUri(vscode.Uri.file(recoverJson.originVcdFile)).toString(); const view = panel.webview.asWebviewUri(uri).toString(); return { vcd, view, worker, root }; } else { - return new Error(t('bad-view-file') + ':' + entryPath); + return new Error(t('error.vcd-viewer.bad-view-file') + ':' + entryPath); } } return new Error('unsupported languages'); diff --git a/src/function/lsp-client/index.ts b/src/function/lsp-client/index.ts index 61e0ed6..597e1f3 100644 --- a/src/function/lsp-client/index.ts +++ b/src/function/lsp-client/index.ts @@ -101,7 +101,7 @@ export async function downloadLsp(context: vscode.ExtensionContext, version: str const downloadLink = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: t('progress.choose-best-download-source') + title: t('info.progress.choose-best-download-source') }, async (progress: vscode.Progress, token: vscode.CancellationToken) => { let timeout = 3000; let reportInterval = 500; @@ -119,7 +119,7 @@ export async function downloadLsp(context: vscode.ExtensionContext, version: str const tarGzFilePath = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: t('progress.download-digital-lsp') + title: t('info.progress.download-digital-lsp') }, async (progress: vscode.Progress, token: vscode.CancellationToken) => { progress.report({ increment: 0 }); const response = await axios.get(downloadLink, { responseType: 'stream' }); @@ -128,13 +128,13 @@ export async function downloadLsp(context: vscode.ExtensionContext, version: str await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: t('progress.extract-digital-lsp') + title: t('info.progress.extract-digital-lsp') }, async (progress: vscode.Progress, token: vscode.CancellationToken) => { if (fs.existsSync(tarGzFilePath)) { console.log('check finish, begin to extract'); await extractTarGz(tarGzFilePath, versionFolderPath); } else { - vscode.window.showErrorMessage(t('error.download-digital-lsp') + version); + vscode.window.showErrorMessage(t('error.lsp.download-digital-lsp') + version); } }); diff --git a/src/function/tool.ts b/src/function/tool.ts index 2cd0293..b37c572 100644 --- a/src/function/tool.ts +++ b/src/function/tool.ts @@ -98,7 +98,7 @@ async function askUserToSaveFilelist(filelist: string[]) { fs.writeFileSync(filePath, fileContent); } catch (error) { - vscode.window.showErrorMessage(t('error.save-file') + ': ' + error); + vscode.window.showErrorMessage(t('error.filelist.save-file') + ': ' + error); } } diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts index cc19733..5bb6651 100644 --- a/src/hdlParser/core.ts +++ b/src/hdlParser/core.ts @@ -252,7 +252,7 @@ class HdlParam { const pools: { id: number, promise: Promise, path: string }[] = []; - const reportTitle = t('progress.build-module-tree'); + const reportTitle = t('info.progress.build-module-tree'); progress?.report({ message: reportTitle + ` ${1}/${fileNum}`, increment: 0 }); diff --git a/src/monitor/event.ts b/src/monitor/event.ts index cd6ccde..822f787 100644 --- a/src/monitor/event.ts +++ b/src/monitor/event.ts @@ -281,15 +281,16 @@ class PpyAction extends BaseAction { public async refreshHdlMonitor(m: HdlMonitor, originalHdlFiles: AbsPath[]) { m.remakeHdlMonitor(); + const { t } = vscode.l10n; const newFiles = await prjManage.getPrjHardwareFiles(); const { addFiles, delFiles } = this.diffNewOld(newFiles, originalHdlFiles); const options: vscode.ProgressOptions = { location: vscode.ProgressLocation.Notification }; - options.title = 'update HdlParam'; + options.title = t('info.monitor.update-hdlparam'); await vscode.window.withProgress(options, async () => await this.updateHdlParam(addFiles, delFiles)); if (opeParam.prjInfo.toolChain === ToolChainType.Xilinx) { - options.title = 'update PL'; + options.title = t('info.monitor.update-pl'); await vscode.window.withProgress(options, async () => await this.updatePL(addFiles, delFiles)); } }