Skip to content

Commit fde6417

Browse files
committed
fix: no formality for certain languages
"EN" (English), "EN-GB" (British English), "EN-US" (American English), "ES" (Spanish), "JA" (Japanese) and "ZH" (Chinese) are unsupported.
1 parent d6db8f8 commit fde6417

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
2. 下载插件 [releases](https://github.com/geekdada/bob-plugin-deepl-translate/releases)
1313
3. [安装插件](https://ripperhe.gitee.io/bob/#/general/quickstart/plugin?id=%e5%ae%89%e8%a3%85%e6%8f%92%e4%bb%b6)
1414

15+
## 配置
16+
17+
- `formality` 正式程度: 设置翻译后的文本是倾向于正式语言还是非正式语言。此功能目前适用于所有目标语言,除了英语、英式英语、美式英语、西班牙语、汉语和日语。
18+
1519
## Sub DeepL
1620

1721
每个月最少 2.5 美元即可使用 DeepL API,详情请见 [sub-deepl.royli.dev](https://sub-deepl.royli.dev?utm_source=github&utm_medium=readme)

src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function translate(
2929
throw err
3030
}
3131

32+
const formality = isFormalitySupported(targetLanguage)
33+
? $option.formality
34+
: 'default'
3235
const response = await api.request<{
3336
translations: ReadonlyArray<{
3437
detected_source_language: string
@@ -42,7 +45,7 @@ export function translate(
4245
target_lang: targetLanguage,
4346
split_sentences: '1',
4447
preserve_formatting: '0',
45-
formality: $option.formality,
48+
formality,
4649
},
4750
})
4851

@@ -95,3 +98,9 @@ export function translate(
9598
})
9699
})
97100
}
101+
102+
function isFormalitySupported(lang: string): boolean {
103+
const unsupported = ['EN', 'EN-GB', 'EN-US', 'ES', 'JA', 'ZH']
104+
105+
return !unsupported.includes(lang.toUpperCase())
106+
}

0 commit comments

Comments
 (0)