Commit 52669b2e408727e968a486c5f237af91de1a054d

Authored by Adhidarma Hadiwinoto
1 parent 00fd3da335
Exists in master

rc-local.json is exclusive

Showing 1 changed file with 5 additions and 5 deletions Inline Diff

lib/translate-rc/index.js
1 const MODULE_NAME = 'TRANSLATE-RC'; 1 const MODULE_NAME = 'TRANSLATE-RC';
2 2
3 const fs = require('fs'); 3 const fs = require('fs');
4 const path = require('path'); 4 const path = require('path');
5 5
6 const logger = require('../logger'); 6 const logger = require('../logger');
7 7
8 const dictDefault = require('./rcs'); 8 const dictDefault = require('./rcs');
9 9
10 const dictCustomFilename = path.join(process.cwd(), 'rc-local.json'); 10 const dictCustomFilename = path.join(process.cwd(), 'rc-local.json');
11 const dictCustomFileExists = fs.existsSync(dictCustomFilename); 11 const dictCustomFileExists = fs.existsSync(dictCustomFilename);
12 12
13 // eslint-disable-next-line import/no-dynamic-require 13 // eslint-disable-next-line import/no-dynamic-require
14 const dictCustom = dictCustomFileExists ? require(dictCustomFilename) : {}; 14 const dictCustom = dictCustomFileExists ? require(dictCustomFilename) : null;
15 15
16 if (dictCustomFileExists) { 16 if (dictCustomFileExists) {
17 logger.verbose(`${MODULE_NAME} 14F61E23: Custom RC dictionary found`, { 17 logger.verbose(`${MODULE_NAME} 14F61E23: Custom RC dictionary found`, {
18 fileName: dictCustomFilename, 18 fileName: dictCustomFilename,
19 content: dictCustom, 19 content: dictCustom,
20 }); 20 });
21 } 21 }
22 22
23 module.exports = (xid, rcFromPartner) => { 23 module.exports = (xid, rcFromPartner) => {
24 if (!rcFromPartner) { 24 if (!rcFromPartner) {
25 logger.verbose(`${MODULE_NAME} 030CFC8F: Unknown rcFromPartner`, { xid }); 25 logger.verbose(`${MODULE_NAME} 030CFC8F: Unknown rcFromPartner`, { xid });
26 return null; 26 return '68';
27 } 27 }
28 28
29 logger.verbose(`${MODULE_NAME} 9EDC60A9: Translating RC from partner`, { xid, rcFromPartner }); 29 logger.verbose(`${MODULE_NAME} 9EDC60A9: Translating RC from partner`, { xid, rcFromPartner });
30 30
31 if (dictCustom[rcFromPartner]) { 31 if (dictCustom) {
32 logger.verbose(`${MODULE_NAME} 0F4ED40E: Found on custom dict`, { xid }); 32 logger.verbose(`${MODULE_NAME} 3A495EC2: Using rc-local.json`, { xid });
33 return dictCustom[rcFromPartner]; 33 return dictCustom[rcFromPartner] || '40';
34 } 34 }
35 35
36 if (dictDefault[rcFromPartner]) { 36 if (dictDefault[rcFromPartner]) {
37 logger.verbose(`${MODULE_NAME} D1B588D9: Found on default dict`, { xid }); 37 logger.verbose(`${MODULE_NAME} D1B588D9: Found on default dict`, { xid });
38 return dictDefault[rcFromPartner]; 38 return dictDefault[rcFromPartner];
39 } 39 }
40 40
41 logger.verbose(`${MODULE_NAME} 61A6ADCE: Using default rc (40)`, { xid }); 41 logger.verbose(`${MODULE_NAME} 61A6ADCE: Using default rc (40)`, { xid });
42 return '40'; 42 return '40';
43 }; 43 };
44 44