index.js
1.3 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const MODULE_NAME = 'TRANSLATE-RC';
const fs = require('fs');
const path = require('path');
const logger = require('../logger');
const dictDefault = require('./rcs');
const dictCustomFilename = path.join(process.cwd(), 'rc-local.json');
const dictCustomFileExists = fs.existsSync(dictCustomFilename);
// eslint-disable-next-line import/no-dynamic-require
const dictCustom = dictCustomFileExists ? require(dictCustomFilename) : null;
if (dictCustomFileExists) {
logger.verbose(`${MODULE_NAME} 14F61E23: Custom RC dictionary found`, {
fileName: dictCustomFilename,
content: dictCustom,
});
}
module.exports = (xid, rcFromPartner) => {
if (!rcFromPartner) {
logger.verbose(`${MODULE_NAME} 030CFC8F: Unknown rcFromPartner`, { xid });
return '68';
}
logger.verbose(`${MODULE_NAME} 9EDC60A9: Translating RC from partner`, { xid, rcFromPartner });
if (dictCustom) {
logger.verbose(`${MODULE_NAME} 3A495EC2: Using rc-local.json`, { xid });
return dictCustom[rcFromPartner] || '40';
}
if (dictDefault[rcFromPartner]) {
logger.verbose(`${MODULE_NAME} D1B588D9: Found on default dict`, { xid });
return dictDefault[rcFromPartner];
}
logger.verbose(`${MODULE_NAME} 61A6ADCE: Using default rc (40)`, { xid });
return '40';
};