Skip to content

Commit

Permalink
#16 在命名中有多词时使用人工翻译释义
Browse files Browse the repository at this point in the history
testacount1 committed Feb 28, 2019
1 parent b311a43 commit e189395
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/查词.ts
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ export function 取释义(选中文本: string): 模型.字段释义 {
if (所有词条.length > 1) {
let 首选释义 = 释义处理.选取释义(所有词条, 所有词);
for (let 序号 = 0; 序号 < 所有词.length; 序号++) {
释义 = 释义.replace(所有词[序号], 首选释义[序号])
释义 = 释义.replace(所有词[序号], 自定义词典.常用命名[所有词条[序号].] || 首选释义[序号])
}
} else if (所有词条.length == 1) {
// TODO: 简化词条 (以适应状态栏宽度)
3 changes: 1 addition & 2 deletions src/翻译/自定义词典.ts
Original file line number Diff line number Diff line change
@@ -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
41 changes: 39 additions & 2 deletions test/查词.test.ts
Original file line number Diff line number Diff line change
@@ -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 检查释义(原词语, 释义) {

0 comments on commit e189395

Please sign in to comment.