blob: a6332e22d799e46b70466424bff82b445cef8120 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import { ipcMain } from 'electron';
// @ts-ignore
import cld from 'cld';
const debug = require('../../preload-safe-debug')('Ferdium:ipcApi:cld');
export default async () => {
ipcMain.handle('detect-language', async (_event, { sample }) => {
if (!cld) {
return null;
}
try {
const result = await cld.detect(sample);
debug('Checking language', 'probability', result.languages);
if (result.reliable) {
debug(
'Language detected reliably, setting spellchecker language to',
result.languages[0].code,
);
return result.languages[0].code;
}
} catch (error) {
console.error(error);
return null;
}
});
};
|