nv-remote-translate
v1.0.1
Published
nv-remote-translate ============ - cli tool - create a translate json file server - support dynamic-modify-config through unix\_sock OR http
Downloads
1
Readme
nv-remote-translate
- cli tool
- create a translate json file server
- support dynamic-modify-config through unix_sock OR http
install
- npm install nv-remote-translate
usage
# npm install nv-remote-translate -g
nv_rtrans_srv -H
Usage: nv_rtrans_srv [options]
Options:
-p, --port server port or unix_sock, default ./___usock___
-d, --workdir work dir, default ./
-H, --help usage
HTTP
init
# mkdir trans-srv
# cd trans-srv/
# nv_rtrans_srv -p 18888
//...wait install node_modules
trans-srv# ls -l | egrep -v "node_modules|package"
total 16
-rw-r--r-- 1 root root 297 Feb 15 03:25 srv.js
-rw-r--r-- 1 root root 225 Feb 15 03:25 translate.json
trans-srv#
trans-srv# cat srv.js
const S = require("nv-remote-translate-srv");
const path = require("path");
module.exports = async ()=> {
await S(18888,path.join("/mnt/sdb/JS/BUSINESS-LIB_/nv-remote-translate/TEST/trans-srv",'translate.json'),"/mnt/sdb/JS/BUSINESS-LIB_/nv-remote-translate/TEST/trans-srv");
return(S)
}
trans-srv#
edit tbl
# vim translate.json
/*
{
"cnl": [
"c0",
"c1",
"c2"
],
"tbl": [
[
"A",
"B",
"C"
],
[
"a",
"b",
"c"
]
]
}
*/
start srv
> const S = await require("./srv")()
listen on: 18888
> S.CFG //this is a getter, for dynamic-change-from-remote
>
get config from remote
# nv_rtrans_cli -S -p 18888
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ] ]
}
change config from remote when server running
- CFG is keywords
add
nv_rtrans_client -m "CFG.add(['cA','cB','cC'])" -p 18888
before:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ] ]
}
------------
after:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
check it on server AFTER change from client
> S.CFG
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
>
check the cfg file AFTER change from client
cat translate.json
{
"cnl": [
"c0",
"c1",
"c2"
],
"tbl": [
[
"A",
"B",
"C"
],
[
"a",
"b",
"c"
],
[
"cA",
"cB",
"cC"
]
]
}
delete
nv_rtrans_client -m "CFG.del('cA')" -p 18888
others
//see readme of https://www.npmjs.com/package/nv-facutil-simple-translate
nv_rtrans_client -m "console.log(Object.getOwnPropertyNames(CFG))" -p 18888
before:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
------------
[
'#cnl', '#tbl',
'col_c0', 'col_c1',
'col_c2', 'dict_c0_to_c1',
'map_c0_to_c1', 'dict_c1_to_c0',
'map_c1_to_c0', 'dict_c0_to_c2',
'map_c0_to_c2', 'dict_c2_to_c0',
'map_c2_to_c0', 'dict_c1_to_c2',
'map_c1_to_c2', 'dict_c2_to_c1',
'map_c2_to_c1'
]
after:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
# nv_rtrans_client -m "console.log(CFG.constructor.prototype)" -p 18888
before:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
------------
{
add: [Function (anonymous)],
del: [Function (anonymous)],
dump: [Function (anonymous)],
get: [Function (anonymous)],
get_all: [Function (anonymous)],
slct: [Function (anonymous)]
}
after:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
# nv_rtrans_client -m "console.log(CFG.dict_c1_to_c0)" -p 18888
before:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
------------
{ B: 'A', b: 'a', cB: 'cA' }
after:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
# nv_rtrans_client -m "console.log(CFG.dict_c0_to_c1)" -p 18888
before:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
------------
{ A: 'B', a: 'b', cA: 'cB' }
after:
_T {
'#cnl': [ 'c0', 'c1', 'c2' ],
'#tbl': [ [ 'A', 'B', 'C' ], [ 'a', 'b', 'c' ], [ 'cA', 'cB', 'cC' ] ]
}
UNIX_SOCK
- for security
server
# vim ./srv
//change the port to undefined
const S = require("nv-remote-translate-srv");
const path = require("path");
module.exports = async ()=> {
await S(
undefined, //===>
path.join("/mnt/sdb/JS/BUSINESS-LIB_/nv-remote-translate/TEST/trans-srv",'translate.json'),
"/mnt/sdb/JS/BUSINESS-LIB_/nv-remote-translate/TEST/trans-srv"
);
return(S)
}
> const S = await require("./srv")()
listen on: /mnt/sdb/JS/BUSINESS-LIB_/nv-remote-translate/TEST/trans-srv/___usock___
client
//JUST without -p if in dir-of-translate.json , others same as http
nv_rtrans_client -S -p /mnt/sdb/JS/BUSINESS-LIB_/nv-remote-translate/TEST/trans-srv/___usock___
nv_rtrans_client -S
nv_rcfg_client -m "..."
LICENSE
- ISC