diff options
author | 2021-09-14 11:03:28 +0200 | |
---|---|---|
committer | 2021-09-14 11:03:28 +0200 | |
commit | 087113d8a1214ba4c7df03bfe66747d8d944280c (patch) | |
tree | 4d853a03057138dfa845cd6a7d91ccf63565a1a6 /src/electron/ipc-api/cld.ts | |
parent | chore: codebase improvements (#1930) (diff) | |
download | ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.tar.gz ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.tar.zst ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.zip |
chore: convert JS to TS (#1934)
Diffstat (limited to 'src/electron/ipc-api/cld.ts')
-rw-r--r-- | src/electron/ipc-api/cld.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/electron/ipc-api/cld.ts b/src/electron/ipc-api/cld.ts new file mode 100644 index 000000000..b907f3730 --- /dev/null +++ b/src/electron/ipc-api/cld.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import { ipcMain } from 'electron'; | ||
2 | import cld from 'cld'; | ||
3 | |||
4 | const debug = require('debug')('Ferdi:ipcApi:cld'); | ||
5 | |||
6 | export default async () => { | ||
7 | ipcMain.handle('detect-language', async (_event, { sample }) => { | ||
8 | try { | ||
9 | const result = await cld.detect(sample); | ||
10 | debug('Checking language', 'probability', result.languages); | ||
11 | if (result.reliable) { | ||
12 | debug( | ||
13 | 'Language detected reliably, setting spellchecker language to', | ||
14 | result.languages[0].code, | ||
15 | ); | ||
16 | |||
17 | return result.languages[0].code; | ||
18 | } | ||
19 | } catch (e) { | ||
20 | console.error(e); | ||
21 | } | ||
22 | }); | ||
23 | }; | ||