From e1893956e56a942d3dae565679e8c8f245365de4 Mon Sep 17 00:00:00 2001 From: fromwheretowhere Date: Wed, 27 Feb 2019 22:27:26 -0800 Subject: [PATCH] =?UTF-8?q?#16=20=E5=9C=A8=E5=91=BD=E5=90=8D=E4=B8=AD?= =?UTF-8?q?=E6=9C=89=E5=A4=9A=E8=AF=8D=E6=97=B6=E4=BD=BF=E7=94=A8=E4=BA=BA?= =?UTF-8?q?=E5=B7=A5=E7=BF=BB=E8=AF=91=E9=87=8A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "src/\346\237\245\350\257\215.ts" | 2 +- ...32\344\271\211\350\257\215\345\205\270.ts" | 3 +- "test/\346\237\245\350\257\215.test.ts" | 41 ++++++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git "a/src/\346\237\245\350\257\215.ts" "b/src/\346\237\245\350\257\215.ts" index 7e0f986..c8030b2 100644 --- "a/src/\346\237\245\350\257\215.ts" +++ "b/src/\346\237\245\350\257\215.ts" @@ -53,7 +53,7 @@ export function 取释义(选中文本: string): 模型.字段释义 { if (所有词条.length > 1) { let 首选释义 = 释义处理.选取释义(所有词条, 所有词); for (let 序号 = 0; 序号 < 所有词.length; 序号++) { - 释义 = 释义.replace(所有词[序号], 首选释义[序号]) + 释义 = 释义.replace(所有词[序号], 自定义词典.常用命名[所有词条[序号].词] || 首选释义[序号]) } } else if (所有词条.length == 1) { // TODO: 简化词条 (以适应状态栏宽度) diff --git "a/src/\347\277\273\350\257\221/\350\207\252\345\256\232\344\271\211\350\257\215\345\205\270.ts" "b/src/\347\277\273\350\257\221/\350\207\252\345\256\232\344\271\211\350\257\215\345\205\270.ts" index f63e84b..ac7d439 100644 --- "a/src/\347\277\273\350\257\221/\350\207\252\345\256\232\344\271\211\350\257\215\345\205\270.ts" +++ "b/src/\347\277\273\350\257\221/\350\207\252\345\256\232\344\271\211\350\257\215\345\205\270.ts" @@ -1,4 +1,4 @@ -const 常用命名 = { +export const 常用命名 = { 'text': "文本", "get": "获取", "util": "功用", @@ -33,7 +33,6 @@ const 常用命名 = { }; export const 不翻译 = { - "is": false, "to": false, "of": false, "bean": false diff --git "a/test/\346\237\245\350\257\215.test.ts" "b/test/\346\237\245\350\257\215.test.ts" index 5c55233..73c82f6 100644 --- "a/test/\346\237\245\350\257\215.test.ts" +++ "b/test/\346\237\245\350\257\215.test.ts" @@ -62,6 +62,34 @@ suite("查词测试", () => { 查词.取释义("seconds") ); + assert.deepEqual( + { + "原字段": "eventListener", + "释义": "事件监听器", + "各词": [ + { + "词": "event", "释义": "n. 事件, 结果, 事情的进程, 竞赛项目\\n[计] 事件", + "词形": [ + { + "变化": "events", + "类型": "名词复数形式" + } + ] + }, + { + "词": "listener", "释义": "n. 收听者, 听众", + "词形": [ + { + "变化": "listeners", + "类型": "名词复数形式" + } + ] + } + ] + }, + 查词.取释义("eventListener") + ); + 检查释义("execPath", "执行路径"); 检查释义("string_decoder", "字符串_译码器"); @@ -70,13 +98,16 @@ suite("查词测试", () => { 检查释义("account_number_0", "帐户_数字_0"); 检查释义("account_number0", "帐户_数字0"); - 检查释义("getSeconds", "取得指令秒"); + // 对于仅有一个单词且有其他字符的命名, 忽略其他字符, 按照单词查询释义 + // 检查释义("account0", "帐户0"); + + 检查释义("getSeconds", "获取秒"); 检查释义("useColors", "使用颜色"); 检查释义("fsPath", "fs路径"); // 取现在分词原型 - 检查释义("gettingStarted", "取得指令出发"); + 检查释义("gettingStarted", "获取出发"); // 词性搭配 // 形容词+名词 @@ -85,6 +116,12 @@ suite("查词测试", () => { // 检查释义("deepEqual", "深入地等于") // 同时有以上两种组合 检查释义("firstSteps", "第一的步骤"); + + // 忽略常见单词 + 检查释义("is_decoder", "为_译码器"); + + // 获取常用命名 + 检查释义("eventListener", "事件监听器"); }); function 检查释义(原词语, 释义) {