@l10nmonster/helpers-lqaboss 3.0.0-alpha.13 → 3.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -0
- package/lqabossRoutes.js +28 -0
- package/package.json +1 -1
package/index.js
CHANGED
package/lqabossRoutes.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { logInfo, logVerbose } from '@l10nmonster/core';
|
|
2
|
+
|
|
3
|
+
export function createLQABossRoutes(mm) {
|
|
4
|
+
return [
|
|
5
|
+
['post', '/lookup', async (req, res) => {
|
|
6
|
+
logInfo`LQABossRoute:/lookup`;
|
|
7
|
+
try {
|
|
8
|
+
const { sourceLang, targetLang, segments } = req.body;
|
|
9
|
+
const tm = mm.tmm.getTM(sourceLang, targetLang);
|
|
10
|
+
const guids = new Set(segments.map(segment => segment.g));
|
|
11
|
+
let tus = [];
|
|
12
|
+
if (guids.size > 0) {
|
|
13
|
+
tus = await tm.queryByGuids(Array.from(guids));
|
|
14
|
+
}
|
|
15
|
+
const guidMap = new Map(tus.map(tu => [ tu.guid, tu ]));
|
|
16
|
+
const results = segments.map(segment => guidMap.get(segment.g) ?? {});
|
|
17
|
+
logVerbose`Matched ${tus.length} segments out of ${guids.size}`;
|
|
18
|
+
res.json({ results });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
logInfo`Error in LQABossRoute:/lookup: ${error.message}`;
|
|
21
|
+
res.status(500).json({
|
|
22
|
+
error: 'Failed to lookup translation memory',
|
|
23
|
+
message: error.message
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}]
|
|
27
|
+
]
|
|
28
|
+
}
|