Skip to content

Commit

Permalink
fix: 将特殊字符串分隔作为可配置项, 默认关闭 issues #21
Browse files Browse the repository at this point in the history
  • Loading branch information
roojay520 committed Apr 9, 2023
1 parent 0ee9c61 commit 13fea9f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged

npm run type-check
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
}
},
"lint-staged": {
"**/*.ts": [
"npm run type-check"
],
"**/*.{js, ts, json}": [
"npm run prettier:fix",
"npm run eslint:fix"
Expand Down
17 changes: 17 additions & 0 deletions src/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@
"title": "代理域名",
"desc": "如果你的网络环境需要代理才能访问 Google Translate, 可以在此填写代理域名, 格式形如: google-translate.proxy.com",
"defaultValue": ""
},
{
"identifier": "stringFmt",
"type": "menu",
"title": "字符串分隔",
"defaultValue": "disable",
"desc": "拆分驼峰/中划线/下划线格式的长字符串, 例如: fooBarBaz-intoString → foo Bar Baz - into String",
"menuValues": [
{
"title": "开启",
"value": "enable"
},
{
"title": "关闭",
"value": "disable"
}
]
}
]
}
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ function supportLanguages(): Bob.supportLanguages {
// https://ripperhe.gitee.io/bob/#/plugin/quickstart/translate
function translate(query: Bob.TranslateQuery, completion: Bob.Completion) {
const { text = '', detectFrom, detectTo } = query;
const str = formatString(text);

// https://github.com/roojay520/bobplugin-google-translate/issues/21
// 是否开启字符串分隔处理, 默认关闭(现在 Google Translate API 已经能很好的拆分)
const stringFmt = Bob.api.getOption('stringFmt') === 'enable';
const str = stringFmt ? formatString(text) : text;

const from = standardToNoStandard(detectFrom);
const to = standardToNoStandard(detectTo);
const params = { from, to, cache: Bob.api.getOption('cache') };
Expand Down

0 comments on commit 13fea9f

Please sign in to comment.