not-locale 0.0.16 → 0.0.20
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/.nyc_output/2a1b074f-0174-4a72-b52a-b4d152a1738b.json +1 -0
- package/.nyc_output/898162e7-334a-49a5-a474-011ccd8f196e.json +1 -0
- package/.nyc_output/ac32ae4c-fb5f-435c-a4f0-acca848abb5d.json +1 -0
- package/.nyc_output/processinfo/2a1b074f-0174-4a72-b52a-b4d152a1738b.json +1 -0
- package/.nyc_output/processinfo/898162e7-334a-49a5-a474-011ccd8f196e.json +1 -0
- package/.nyc_output/processinfo/ac32ae4c-fb5f-435c-a4f0-acca848abb5d.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/index.js +3 -1
- package/package.json +5 -4
- package/src/common/lib.js +97 -71
- package/src/controllers/common/nsLocale.js +63 -44
- package/src/routes/locale.js +2 -8
- package/src/routes/locale.manifest.js +2 -2
- package/src/routes/locale.ws.js +4 -4
- package/test/index.js +25 -7
- package/test/locales/en.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"/home/cypher/proj/not-lib/not-locale/index.js":{"path":"/home/cypher/proj/not-lib/not-locale/index.js","statementMap":{"0":{"start":{"line":10,"column":4},"end":{"line":10,"column":34}},"1":{"start":{"line":12,"column":0},"end":{"line":20,"column":2}}},"fnMap":{},"branchMap":{},"s":{"0":1,"1":1},"f":{},"b":{},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"a938b7754dc99ed6454876c19f1a63d93dd2a549","contentHash":"22c1682fdb71284685be8a57e0a08f5213a2e8e6592e9317f7b4fb9df56e466f"},"/home/cypher/proj/not-lib/not-locale/src/common/lib.js":{"path":"/home/cypher/proj/not-lib/not-locale/src/common/lib.js","statementMap":{"0":{"start":{"line":7,"column":7},"end":{"line":7,"column":47}},"1":{"start":{"line":8,"column":6},"end":{"line":8,"column":19}},"2":{"start":{"line":9,"column":11},"end":{"line":9,"column":30}},"3":{"start":{"line":10,"column":8},"end":{"line":10,"column":23}},"4":{"start":{"line":12,"column":12},"end":{"line":12,"column":14}},"5":{"start":{"line":13,"column":8},"end":{"line":16,"column":2}},"6":{"start":{"line":24,"column":2},"end":{"line":28,"column":3}},"7":{"start":{"line":25,"column":3},"end":{"line":25,"column":30}},"8":{"start":{"line":27,"column":3},"end":{"line":27,"column":40}},"9":{"start":{"line":29,"column":2},"end":{"line":33,"column":3}},"10":{"start":{"line":30,"column":3},"end":{"line":30,"column":31}},"11":{"start":{"line":32,"column":3},"end":{"line":32,"column":36}},"12":{"start":{"line":34,"column":2},"end":{"line":34,"column":9}},"13":{"start":{"line":43,"column":0},"end":{"line":53,"column":2}},"14":{"start":{"line":44,"column":1},"end":{"line":51,"column":2}},"15":{"start":{"line":45,"column":2},"end":{"line":47,"column":3}},"16":{"start":{"line":46,"column":3},"end":{"line":46,"column":34}},"17":{"start":{"line":48,"column":2},"end":{"line":50,"column":3}},"18":{"start":{"line":49,"column":3},"end":{"line":49,"column":32}},"19":{"start":{"line":52,"column":1},"end":{"line":52,"column":15}},"20":{"start":{"line":61,"column":0},"end":{"line":75,"column":2}},"21":{"start":{"line":62,"column":1},"end":{"line":69,"column":2}},"22":{"start":{"line":63,"column":12},"end":{"line":63,"column":14}},"23":{"start":{"line":64,"column":15},"end":{"line":64,"column":32}},"24":{"start":{"line":65,"column":2},"end":{"line":67,"column":5}},"25":{"start":{"line":66,"column":3},"end":{"line":66,"column":39}},"26":{"start":{"line":68,"column":2},"end":{"line":68,"column":13}},"27":{"start":{"line":70,"column":1},"end":{"line":74,"column":2}},"28":{"start":{"line":71,"column":2},"end":{"line":71,"column":53}},"29":{"start":{"line":73,"column":2},"end":{"line":73,"column":42}},"30":{"start":{"line":82,"column":0},"end":{"line":107,"column":2}},"31":{"start":{"line":83,"column":1},"end":{"line":106,"column":4}},"32":{"start":{"line":84,"column":2},"end":{"line":105,"column":5}},"33":{"start":{"line":85,"column":3},"end":{"line":104,"column":4}},"34":{"start":{"line":86,"column":4},"end":{"line":86,"column":16}},"35":{"start":{"line":88,"column":4},"end":{"line":102,"column":5}},"36":{"start":{"line":88,"column":16},"end":{"line":88,"column":17}},"37":{"start":{"line":89,"column":20},"end":{"line":89,"column":54}},"38":{"start":{"line":90,"column":14},"end":{"line":90,"column":36}},"39":{"start":{"line":91,"column":5},"end":{"line":101,"column":6}},"40":{"start":{"line":92,"column":6},"end":{"line":98,"column":7}},"41":{"start":{"line":93,"column":18},"end":{"line":93,"column":35}},"42":{"start":{"line":94,"column":23},"end":{"line":94,"column":42}},"43":{"start":{"line":95,"column":7},"end":{"line":95,"column":50}},"44":{"start":{"line":97,"column":7},"end":{"line":97,"column":20}},"45":{"start":{"line":100,"column":6},"end":{"line":100,"column":15}},"46":{"start":{"line":103,"column":4},"end":{"line":103,"column":14}},"47":{"start":{"line":116,"column":1},"end":{"line":127,"column":2}},"48":{"start":{"line":117,"column":13},"end":{"line":117,"column":34}},"49":{"start":{"line":118,"column":12},"end":{"line":118,"column":14}},"50":{"start":{"line":119,"column":2},"end":{"line":123,"column":3}},"51":{"start":{"line":120,"column":3},"end":{"line":120,"column":46}},"52":{"start":{"line":122,"column":3},"end":{"line":122,"column":17}},"53":{"start":{"line":124,"column":2},"end":{"line":124,"column":16}},"54":{"start":{"line":126,"column":2},"end":{"line":126,"column":15}},"55":{"start":{"line":130,"column":0},"end":{"line":130,"column":17}},"56":{"start":{"line":136,"column":0},"end":{"line":136,"column":43}},"57":{"start":{"line":136,"column":28},"end":{"line":136,"column":41}},"58":{"start":{"line":142,"column":0},"end":{"line":142,"column":56}},"59":{"start":{"line":142,"column":23},"end":{"line":142,"column":54}},"60":{"start":{"line":145,"column":0},"end":{"line":151,"column":2}},"61":{"start":{"line":146,"column":1},"end":{"line":150,"column":2}},"62":{"start":{"line":147,"column":2},"end":{"line":147,"column":23}},"63":{"start":{"line":149,"column":2},"end":{"line":149,"column":12}},"64":{"start":{"line":154,"column":0},"end":{"line":156,"column":2}},"65":{"start":{"line":155,"column":1},"end":{"line":155,"column":27}},"66":{"start":{"line":160,"column":1},"end":{"line":160,"column":51}},"67":{"start":{"line":160,"column":20},"end":{"line":160,"column":50}},"68":{"start":{"line":163,"column":0},"end":{"line":163,"column":36}},"69":{"start":{"line":165,"column":0},"end":{"line":173,"column":2}},"70":{"start":{"line":166,"column":1},"end":{"line":172,"column":2}},"71":{"start":{"line":167,"column":2},"end":{"line":171,"column":4}}},"fnMap":{"0":{"name":"detect","decl":{"start":{"line":22,"column":10},"end":{"line":22,"column":16}},"loc":{"start":{"line":22,"column":34},"end":{"line":35,"column":2}},"line":22},"1":{"name":"(anonymous_1)","decl":{"start":{"line":43,"column":24},"end":{"line":43,"column":25}},"loc":{"start":{"line":43,"column":35},"end":{"line":53,"column":1}},"line":43},"2":{"name":"(anonymous_2)","decl":{"start":{"line":61,"column":19},"end":{"line":61,"column":20}},"loc":{"start":{"line":61,"column":48},"end":{"line":75,"column":1}},"line":61},"3":{"name":"(anonymous_3)","decl":{"start":{"line":65,"column":15},"end":{"line":65,"column":16}},"loc":{"start":{"line":65,"column":24},"end":{"line":67,"column":3}},"line":65},"4":{"name":"(anonymous_4)","decl":{"start":{"line":82,"column":18},"end":{"line":82,"column":19}},"loc":{"start":{"line":82,"column":48},"end":{"line":107,"column":1}},"line":82},"5":{"name":"(anonymous_5)","decl":{"start":{"line":83,"column":20},"end":{"line":83,"column":21}},"loc":{"start":{"line":83,"column":39},"end":{"line":106,"column":2}},"line":83},"6":{"name":"(anonymous_6)","decl":{"start":{"line":84,"column":28},"end":{"line":84,"column":29}},"loc":{"start":{"line":84,"column":44},"end":{"line":105,"column":3}},"line":84},"7":{"name":"say","decl":{"start":{"line":115,"column":9},"end":{"line":115,"column":12}},"loc":{"start":{"line":115,"column":56},"end":{"line":128,"column":1}},"line":115},"8":{"name":"(anonymous_8)","decl":{"start":{"line":136,"column":21},"end":{"line":136,"column":22}},"loc":{"start":{"line":136,"column":27},"end":{"line":136,"column":42}},"line":136},"9":{"name":"(anonymous_9)","decl":{"start":{"line":142,"column":15},"end":{"line":142,"column":16}},"loc":{"start":{"line":142,"column":21},"end":{"line":142,"column":55}},"line":142},"10":{"name":"(anonymous_10)","decl":{"start":{"line":145,"column":14},"end":{"line":145,"column":15}},"loc":{"start":{"line":145,"column":24},"end":{"line":151,"column":1}},"line":145},"11":{"name":"(anonymous_11)","decl":{"start":{"line":154,"column":20},"end":{"line":154,"column":21}},"loc":{"start":{"line":154,"column":24},"end":{"line":156,"column":1}},"line":154},"12":{"name":"modulePhrase","decl":{"start":{"line":159,"column":9},"end":{"line":159,"column":21}},"loc":{"start":{"line":159,"column":38},"end":{"line":161,"column":1}},"line":159},"13":{"name":"(anonymous_13)","decl":{"start":{"line":160,"column":8},"end":{"line":160,"column":9}},"loc":{"start":{"line":160,"column":20},"end":{"line":160,"column":50}},"line":160},"14":{"name":"(anonymous_14)","decl":{"start":{"line":165,"column":23},"end":{"line":165,"column":24}},"loc":{"start":{"line":165,"column":44},"end":{"line":173,"column":1}},"line":165},"15":{"name":"(anonymous_15)","decl":{"start":{"line":166,"column":8},"end":{"line":166,"column":9}},"loc":{"start":{"line":166,"column":56},"end":{"line":172,"column":2}},"line":166}},"branchMap":{"0":{"loc":{"start":{"line":24,"column":2},"end":{"line":28,"column":3}},"type":"if","locations":[{"start":{"line":24,"column":2},"end":{"line":28,"column":3}},{"start":{"line":24,"column":2},"end":{"line":28,"column":3}}],"line":24},"1":{"loc":{"start":{"line":29,"column":2},"end":{"line":33,"column":3}},"type":"if","locations":[{"start":{"line":29,"column":2},"end":{"line":33,"column":3}},{"start":{"line":29,"column":2},"end":{"line":33,"column":3}}],"line":29},"2":{"loc":{"start":{"line":44,"column":1},"end":{"line":51,"column":2}},"type":"if","locations":[{"start":{"line":44,"column":1},"end":{"line":51,"column":2}},{"start":{"line":44,"column":1},"end":{"line":51,"column":2}}],"line":44},"3":{"loc":{"start":{"line":45,"column":2},"end":{"line":47,"column":3}},"type":"if","locations":[{"start":{"line":45,"column":2},"end":{"line":47,"column":3}},{"start":{"line":45,"column":2},"end":{"line":47,"column":3}}],"line":45},"4":{"loc":{"start":{"line":45,"column":6},"end":{"line":45,"column":51}},"type":"binary-expr","locations":[{"start":{"line":45,"column":6},"end":{"line":45,"column":21}},{"start":{"line":45,"column":25},"end":{"line":45,"column":51}}],"line":45},"5":{"loc":{"start":{"line":48,"column":2},"end":{"line":50,"column":3}},"type":"if","locations":[{"start":{"line":48,"column":2},"end":{"line":50,"column":3}},{"start":{"line":48,"column":2},"end":{"line":50,"column":3}}],"line":48},"6":{"loc":{"start":{"line":48,"column":6},"end":{"line":48,"column":60}},"type":"binary-expr","locations":[{"start":{"line":48,"column":6},"end":{"line":48,"column":20}},{"start":{"line":48,"column":24},"end":{"line":48,"column":60}}],"line":48},"7":{"loc":{"start":{"line":61,"column":34},"end":{"line":61,"column":45}},"type":"default-arg","locations":[{"start":{"line":61,"column":43},"end":{"line":61,"column":45}}],"line":61},"8":{"loc":{"start":{"line":62,"column":1},"end":{"line":69,"column":2}},"type":"if","locations":[{"start":{"line":62,"column":1},"end":{"line":69,"column":2}},{"start":{"line":62,"column":1},"end":{"line":69,"column":2}}],"line":62},"9":{"loc":{"start":{"line":70,"column":1},"end":{"line":74,"column":2}},"type":"if","locations":[{"start":{"line":70,"column":1},"end":{"line":74,"column":2}},{"start":{"line":70,"column":1},"end":{"line":74,"column":2}}],"line":70},"10":{"loc":{"start":{"line":82,"column":34},"end":{"line":82,"column":45}},"type":"default-arg","locations":[{"start":{"line":82,"column":43},"end":{"line":82,"column":45}}],"line":82},"11":{"loc":{"start":{"line":85,"column":3},"end":{"line":104,"column":4}},"type":"if","locations":[{"start":{"line":85,"column":3},"end":{"line":104,"column":4}},{"start":{"line":85,"column":3},"end":{"line":104,"column":4}}],"line":85},"12":{"loc":{"start":{"line":91,"column":5},"end":{"line":101,"column":6}},"type":"if","locations":[{"start":{"line":91,"column":5},"end":{"line":101,"column":6}},{"start":{"line":91,"column":5},"end":{"line":101,"column":6}}],"line":91},"13":{"loc":{"start":{"line":115,"column":21},"end":{"line":115,"column":32}},"type":"default-arg","locations":[{"start":{"line":115,"column":30},"end":{"line":115,"column":32}}],"line":115},"14":{"loc":{"start":{"line":115,"column":34},"end":{"line":115,"column":55}},"type":"default-arg","locations":[{"start":{"line":115,"column":43},"end":{"line":115,"column":55}}],"line":115},"15":{"loc":{"start":{"line":119,"column":2},"end":{"line":123,"column":3}},"type":"if","locations":[{"start":{"line":119,"column":2},"end":{"line":123,"column":3}},{"start":{"line":119,"column":2},"end":{"line":123,"column":3}}],"line":119},"16":{"loc":{"start":{"line":146,"column":1},"end":{"line":150,"column":2}},"type":"if","locations":[{"start":{"line":146,"column":1},"end":{"line":150,"column":2}},{"start":{"line":146,"column":1},"end":{"line":150,"column":2}}],"line":146},"17":{"loc":{"start":{"line":159,"column":22},"end":{"line":159,"column":37}},"type":"default-arg","locations":[{"start":{"line":159,"column":35},"end":{"line":159,"column":37}}],"line":159},"18":{"loc":{"start":{"line":165,"column":24},"end":{"line":165,"column":39}},"type":"default-arg","locations":[{"start":{"line":165,"column":37},"end":{"line":165,"column":39}}],"line":165},"19":{"loc":{"start":{"line":166,"column":17},"end":{"line":166,"column":28}},"type":"default-arg","locations":[{"start":{"line":166,"column":26},"end":{"line":166,"column":28}}],"line":166},"20":{"loc":{"start":{"line":166,"column":30},"end":{"line":166,"column":51}},"type":"default-arg","locations":[{"start":{"line":166,"column":39},"end":{"line":166,"column":51}}],"line":166}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":3,"7":1,"8":2,"9":3,"10":2,"11":1,"12":3,"13":1,"14":5,"15":3,"16":1,"17":3,"18":1,"19":5,"20":1,"21":4,"22":0,"23":0,"24":0,"25":0,"26":0,"27":4,"28":1,"29":3,"30":1,"31":3,"32":3,"33":3,"34":1,"35":2,"36":2,"37":4,"38":4,"39":4,"40":3,"41":3,"42":2,"43":2,"44":1,"45":1,"46":2,"47":8,"48":8,"49":7,"50":7,"51":6,"52":1,"53":1,"54":2,"55":1,"56":1,"57":4,"58":1,"59":3,"60":1,"61":0,"62":0,"63":0,"64":1,"65":0,"66":1,"67":1,"68":1,"69":1,"70":1,"71":1},"f":{"0":3,"1":5,"2":4,"3":0,"4":3,"5":3,"6":3,"7":8,"8":4,"9":3,"10":0,"11":0,"12":1,"13":1,"14":1,"15":1},"b":{"0":[1,2],"1":[2,1],"2":[3,2],"3":[1,2],"4":[3,1],"5":[1,2],"6":[3,1],"7":[2],"8":[0,4],"9":[1,3],"10":[3],"11":[1,2],"12":[3,1],"13":[4],"14":[3],"15":[6,1],"16":[0,0],"17":[0],"18":[0],"19":[1],"20":[1]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"6d7e3f0e9a52618562ded9da1771c08e8087b293","contentHash":"509355475609984f70c664919bcf7b545f5b94e1b6484630019ae597319720a2"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"898162e7-334a-49a5-a474-011ccd8f196e","pid":901929,"argv":["/usr/local/bin/node","/home/cypher/proj/not-lib/not-locale/node_modules/.bin/mocha","--reporter","spec"],"execArgv":[],"cwd":"/home/cypher/proj/not-lib/not-locale","time":1634507330748,"ppid":901928,"coverageFilename":"/home/cypher/proj/not-lib/not-locale/.nyc_output/2a1b074f-0174-4a72-b52a-b4d152a1738b.json","externalId":"","uuid":"2a1b074f-0174-4a72-b52a-b4d152a1738b","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":901915,"argv":["/usr/local/bin/node","/usr/local/bin/npm","run","test"],"execArgv":[],"cwd":"/home/cypher/proj/not-lib/not-locale","time":1634507330515,"ppid":901904,"coverageFilename":"/home/cypher/proj/not-lib/not-locale/.nyc_output/898162e7-334a-49a5-a474-011ccd8f196e.json","externalId":"","uuid":"898162e7-334a-49a5-a474-011ccd8f196e","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"2a1b074f-0174-4a72-b52a-b4d152a1738b","pid":901936,"argv":["/usr/local/bin/node","/home/cypher/proj/not-lib/not-locale/node_modules/mocha/bin/_mocha","--reporter","spec"],"execArgv":[],"cwd":"/home/cypher/proj/not-lib/not-locale","time":1634507330834,"ppid":901929,"coverageFilename":"/home/cypher/proj/not-lib/not-locale/.nyc_output/ac32ae4c-fb5f-435c-a4f0-acca848abb5d.json","externalId":"","uuid":"ac32ae4c-fb5f-435c-a4f0-acca848abb5d","files":["/home/cypher/proj/not-lib/not-locale/index.js","/home/cypher/proj/not-lib/not-locale/src/common/lib.js"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"processes":{"2a1b074f-0174-4a72-b52a-b4d152a1738b":{"parent":"898162e7-334a-49a5-a474-011ccd8f196e","children":["ac32ae4c-fb5f-435c-a4f0-acca848abb5d"]},"898162e7-334a-49a5-a474-011ccd8f196e":{"parent":null,"children":["2a1b074f-0174-4a72-b52a-b4d152a1738b"]},"ac32ae4c-fb5f-435c-a4f0-acca848abb5d":{"parent":"2a1b074f-0174-4a72-b52a-b4d152a1738b","children":[]}},"files":{"/home/cypher/proj/not-lib/not-locale/index.js":["ac32ae4c-fb5f-435c-a4f0-acca848abb5d"],"/home/cypher/proj/not-lib/not-locale/src/common/lib.js":["ac32ae4c-fb5f-435c-a4f0-acca848abb5d"]},"externalIds":{}}
|
package/index.js
CHANGED
|
@@ -3,6 +3,8 @@ const {
|
|
|
3
3
|
fromJSON,
|
|
4
4
|
fromDir,
|
|
5
5
|
say,
|
|
6
|
+
sayForModule,
|
|
7
|
+
modulePhrase,
|
|
6
8
|
vocabulary,
|
|
7
9
|
OPTS
|
|
8
10
|
} = require('./src/common/lib.js');
|
|
@@ -14,5 +16,5 @@ module.exports = {
|
|
|
14
16
|
logics: __dirname + '/src/logics',
|
|
15
17
|
routes: __dirname + '/src/routes',
|
|
16
18
|
},
|
|
17
|
-
getMiddleware, fromJSON, fromDir, say, vocabulary, OPTS
|
|
19
|
+
getMiddleware, fromJSON, fromDir, say, sayForModule, modulePhrase, vocabulary, OPTS
|
|
18
20
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "not-locale",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "not-* family module for localization in not- environment",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,14 +24,15 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/interrupter/not-locale#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
27
|
+
"not-log": "^0.0.20",
|
|
28
|
+
"not-path": "^1.0.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"chai": "*",
|
|
31
32
|
"chai-as-promised": "*",
|
|
32
|
-
"eslint": "^
|
|
33
|
+
"eslint": "^8.3.0",
|
|
33
34
|
"ink-docstrap": "^1.3.2",
|
|
34
|
-
"jsdoc": "^3.6.
|
|
35
|
+
"jsdoc": "^3.6.7",
|
|
35
36
|
"mocha": "*",
|
|
36
37
|
"nyc": "*"
|
|
37
38
|
}
|
package/src/common/lib.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module not-locale/lib
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const loadJsonFile = require('load-json-file'),
|
|
6
|
+
const //loadJsonFile = require('load-json-file'),
|
|
7
7
|
Log = require('not-log')(module, 'not-locale'),
|
|
8
8
|
fs = require('fs'),
|
|
9
9
|
notPath = require('not-path'),
|
|
@@ -15,37 +15,37 @@ var store = {},
|
|
|
15
15
|
getter: null
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Express middleware, to determine in which locale should we process response
|
|
20
|
+
*/
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
next();
|
|
22
|
+
function detect(req, res, next) {
|
|
23
|
+
let reqLang;
|
|
24
|
+
if (OPTS.getter) {
|
|
25
|
+
reqLang = OPTS.getter(req);
|
|
26
|
+
} else {
|
|
27
|
+
reqLang = req.get('Accept-Language');
|
|
28
|
+
}
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(store, reqLang)) {
|
|
30
|
+
res.locals.locale = reqLang;
|
|
31
|
+
} else {
|
|
32
|
+
res.locals.locale = OPTS.default;
|
|
35
33
|
}
|
|
34
|
+
next();
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Express middleware initializer, to determine in which locale should we process response
|
|
39
|
+
* @param {object} options - object with `deafult` {string}, `getter` {function} redefined
|
|
40
|
+
* @return {function} function wich will accept three params (req, res, next) and run as express middleware
|
|
41
|
+
*/
|
|
42
42
|
|
|
43
|
-
exports.getMiddleware = (options)=>{
|
|
44
|
-
if (options){
|
|
45
|
-
if (options.default && options.default.length > 1){
|
|
43
|
+
exports.getMiddleware = (options) => {
|
|
44
|
+
if (options) {
|
|
45
|
+
if (options.default && options.default.length > 1) {
|
|
46
46
|
OPTS.default = options.default;
|
|
47
47
|
}
|
|
48
|
-
if (options.getter && typeof options.getter === 'function'){
|
|
48
|
+
if (options.getter && typeof options.getter === 'function') {
|
|
49
49
|
OPTS.getter = options.getter;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -54,12 +54,12 @@ exports.getMiddleware = (options)=>{
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
exports.fromJSON = (locale, json, prefix = '')=>{
|
|
62
|
-
if(prefix){
|
|
57
|
+
* Add locale by json object
|
|
58
|
+
* @param {string} locale - name of locale
|
|
59
|
+
* @param {json} json - json object
|
|
60
|
+
*/
|
|
61
|
+
exports.fromJSON = (locale, json, prefix = '') => {
|
|
62
|
+
if (prefix) {
|
|
63
63
|
let tmp = {};
|
|
64
64
|
const keys = Object.keys(json);
|
|
65
65
|
keys.forEach((key) => {
|
|
@@ -67,36 +67,36 @@ exports.fromJSON = (locale, json, prefix = '')=>{
|
|
|
67
67
|
});
|
|
68
68
|
json = tmp;
|
|
69
69
|
}
|
|
70
|
-
if (typeof store[locale] !== 'undefined'){
|
|
70
|
+
if (typeof store[locale] !== 'undefined') {
|
|
71
71
|
store[locale] = Object.assign(store[locale], json);
|
|
72
|
-
}else{
|
|
72
|
+
} else {
|
|
73
73
|
store[locale] = Object.assign({}, json);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
exports.fromDir = (pathToLocales, prefix = '')=>{
|
|
83
|
-
return new Promise((resolve, reject)=>{
|
|
78
|
+
* Load locales from directory, with json files, names as [locale_name].json
|
|
79
|
+
* @param {number} pathToLocales - absolute path to directory
|
|
80
|
+
* @return {Promise}
|
|
81
|
+
*/
|
|
82
|
+
exports.fromDir = (pathToLocales, prefix = '') => {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
84
|
fs.readdir(pathToLocales, (err, items) => {
|
|
85
|
-
if (err){
|
|
85
|
+
if (err) {
|
|
86
86
|
reject(err);
|
|
87
|
-
}else{
|
|
88
|
-
for(let i = 0; i < items.length; i++) {
|
|
87
|
+
} else {
|
|
88
|
+
for (let i = 0; i < items.length; i++) {
|
|
89
89
|
let filename = path.join(pathToLocales, items[i]),
|
|
90
90
|
stats = fs.lstatSync(filename);
|
|
91
|
-
if (stats.isFile()){
|
|
92
|
-
try{
|
|
93
|
-
let file =
|
|
91
|
+
if (stats.isFile()) {
|
|
92
|
+
try {
|
|
93
|
+
let file = require(filename),
|
|
94
94
|
[localeName] = items[i].split('.');
|
|
95
95
|
exports.fromJSON(localeName, file, prefix);
|
|
96
|
-
}catch(e){
|
|
96
|
+
} catch (e) {
|
|
97
97
|
Log.error(e);
|
|
98
98
|
}
|
|
99
|
-
}else{
|
|
99
|
+
} else {
|
|
100
100
|
continue;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -107,48 +107,74 @@ exports.fromDir = (pathToLocales, prefix = '')=>{
|
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
try{
|
|
110
|
+
* Returns localized variant of code phrase
|
|
111
|
+
* @param {string} phrase - code phrase
|
|
112
|
+
* @param {array|object} params - array or hash with params for template parser
|
|
113
|
+
* @return {string} localized variant
|
|
114
|
+
*/
|
|
115
|
+
function say(phrase, params = {}, locale = OPTS.default) {
|
|
116
|
+
try {
|
|
117
117
|
let tmpl = store[locale][phrase],
|
|
118
118
|
result = '';
|
|
119
|
-
if (
|
|
119
|
+
if (typeof tmpl === 'undefined') {
|
|
120
|
+
return phrase;
|
|
121
|
+
}
|
|
122
|
+
if (params) {
|
|
120
123
|
return notPath.parseSubs(tmpl, params, {});
|
|
121
|
-
}else{
|
|
124
|
+
} else {
|
|
122
125
|
result = tmpl;
|
|
123
126
|
}
|
|
124
127
|
return result;
|
|
125
|
-
}catch(e){
|
|
128
|
+
} catch (e) {
|
|
126
129
|
Log.error(e);
|
|
127
130
|
}
|
|
128
|
-
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
exports.say = say;
|
|
129
134
|
|
|
130
135
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
exports.vocabulary = () => {
|
|
136
|
+
* Getter for stores of all locales
|
|
137
|
+
* @return {objects} all locales
|
|
138
|
+
*/
|
|
139
|
+
exports.vocabulary = () => {
|
|
140
|
+
return store;
|
|
141
|
+
};
|
|
135
142
|
|
|
136
143
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
exports.OPTS = () => {
|
|
144
|
+
* Getter for OPTS variable
|
|
145
|
+
* @return {object} copy of OPTS object
|
|
146
|
+
*/
|
|
147
|
+
exports.OPTS = () => {
|
|
148
|
+
return Object.assign({}, OPTS);
|
|
149
|
+
};
|
|
141
150
|
|
|
142
151
|
|
|
143
|
-
exports.get = (locale)=>{
|
|
144
|
-
if(Object.prototype.hasOwnProperty.call(store, locale)){
|
|
152
|
+
exports.get = (locale) => {
|
|
153
|
+
if (Object.prototype.hasOwnProperty.call(store, locale)) {
|
|
145
154
|
return store[locale];
|
|
146
|
-
}else{
|
|
155
|
+
} else {
|
|
147
156
|
return {};
|
|
148
157
|
}
|
|
149
158
|
};
|
|
150
159
|
|
|
151
160
|
|
|
152
|
-
exports.available = ()=>{
|
|
161
|
+
exports.available = () => {
|
|
153
162
|
return Object.keys(store);
|
|
154
163
|
};
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
function modulePhrase(moduleName = '') {
|
|
167
|
+
return (phrase) => [moduleName, phrase].join(':');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
exports.modulePhrase = modulePhrase;
|
|
171
|
+
|
|
172
|
+
exports.sayForModule = (moduleName = '') => {
|
|
173
|
+
return (phrase, params = {}, locale = OPTS.default) => {
|
|
174
|
+
return say(
|
|
175
|
+
[moduleName, phrase].join(':'),
|
|
176
|
+
params,
|
|
177
|
+
locale
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
};
|
|
@@ -1,62 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* detects current locale, loads dictionary from server
|
|
3
|
-
*
|
|
4
|
-
**/
|
|
2
|
+
* detects current locale, loads dictionary from server
|
|
3
|
+
*
|
|
4
|
+
**/
|
|
5
5
|
|
|
6
6
|
const SECTION_ID = 'locale';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
notCommon,
|
|
10
|
+
notLocale,
|
|
11
|
+
TopMenu
|
|
12
|
+
} from 'not-bulma';
|
|
9
13
|
|
|
10
|
-
class nsLocale{
|
|
11
|
-
constructor(app){
|
|
14
|
+
class nsLocale {
|
|
15
|
+
constructor(app) {
|
|
12
16
|
this.app = app;
|
|
13
17
|
this.locales = [];
|
|
14
|
-
this.
|
|
15
|
-
|
|
18
|
+
this.failures = 0;
|
|
19
|
+
this.app.on('wsClient:main:connected', this.update.bind(this));
|
|
20
|
+
notLocale.on('change', () => {
|
|
16
21
|
this.app.emit('locale');
|
|
17
22
|
});
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
interface(data){
|
|
26
|
+
* Creates network interface for this service
|
|
27
|
+
*/
|
|
28
|
+
interface(data) {
|
|
24
29
|
return this.app.getInterface('locale')(data);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
async update(){
|
|
32
|
-
try{
|
|
33
|
+
* Retrieves dictionary for current locale
|
|
34
|
+
* sets dictionary in notLocale object
|
|
35
|
+
*/
|
|
36
|
+
async update() {
|
|
37
|
+
try {
|
|
33
38
|
await this.updateAvailable();
|
|
34
|
-
let res = await this.interface({
|
|
35
|
-
|
|
39
|
+
let res = await this.interface({
|
|
40
|
+
locale: this.getCurrentLocale()
|
|
41
|
+
}).$get({});
|
|
42
|
+
if (res.status === 'ok' && res.result) {
|
|
36
43
|
notLocale.set(res.result);
|
|
44
|
+
} else {
|
|
45
|
+
this.scheduleUpdate();
|
|
37
46
|
}
|
|
38
|
-
}catch(e){
|
|
47
|
+
} catch (e) {
|
|
39
48
|
notCommon.error(e);
|
|
49
|
+
this.scheduleUpdate();
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
scheduleUpdate() {
|
|
54
|
+
this.failures++;
|
|
55
|
+
if (this.failures < 100) {
|
|
56
|
+
setTimeout(this.update.bind(this), 1000 * this.failures);
|
|
57
|
+
} else {
|
|
58
|
+
notCommon.error('Too many failures of locale loading');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async updateAvailable() {
|
|
63
|
+
try {
|
|
45
64
|
let res = await this.interface({}).$available({});
|
|
46
|
-
if(res.status === 'ok' && res.result){
|
|
65
|
+
if (res.status === 'ok' && res.result) {
|
|
47
66
|
this.setAvailable(res.result);
|
|
48
67
|
}
|
|
49
|
-
}catch(e){
|
|
68
|
+
} catch (e) {
|
|
50
69
|
notCommon.error(e);
|
|
51
70
|
}
|
|
52
71
|
}
|
|
53
72
|
|
|
54
|
-
updateUI(list){
|
|
73
|
+
updateUI(list) {
|
|
55
74
|
let menuItems = this.createMenuItems(list);
|
|
56
75
|
TopMenu.updateSectionItems(SECTION_ID, () => {
|
|
57
76
|
return menuItems;
|
|
58
77
|
});
|
|
59
|
-
setTimeout(()=>{
|
|
78
|
+
setTimeout(() => {
|
|
60
79
|
this.app.emit(`tag-${SECTION_ID}:update`, {
|
|
61
80
|
title: this.getCurrentLocale()
|
|
62
81
|
});
|
|
@@ -78,18 +97,18 @@ class nsLocale{
|
|
|
78
97
|
};
|
|
79
98
|
}
|
|
80
99
|
|
|
81
|
-
changeLocale(locale){
|
|
100
|
+
changeLocale(locale) {
|
|
82
101
|
this.saveLocaleToStore(locale);
|
|
83
102
|
this.update();
|
|
84
103
|
}
|
|
85
104
|
|
|
86
105
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
getCurrentLocale(){
|
|
106
|
+
* @returns {string} code of current locale
|
|
107
|
+
**/
|
|
108
|
+
getCurrentLocale() {
|
|
90
109
|
let stored = this.restoreLocaleFromStore();
|
|
91
|
-
if (stored){
|
|
92
|
-
if(this.locales.includes(stored)){
|
|
110
|
+
if (stored) {
|
|
111
|
+
if (this.locales.includes(stored)) {
|
|
93
112
|
return stored;
|
|
94
113
|
}
|
|
95
114
|
}
|
|
@@ -97,22 +116,22 @@ class nsLocale{
|
|
|
97
116
|
}
|
|
98
117
|
|
|
99
118
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
getAvailable(){
|
|
119
|
+
* @returns {Promise<Array>} of locales objects {code, title}
|
|
120
|
+
**/
|
|
121
|
+
getAvailable() {
|
|
103
122
|
return this.interface().$available({});
|
|
104
123
|
}
|
|
105
124
|
|
|
106
125
|
|
|
107
|
-
setAvailable(list){
|
|
126
|
+
setAvailable(list) {
|
|
108
127
|
this.locales = list;
|
|
109
128
|
this.updateUI(list);
|
|
110
129
|
}
|
|
111
130
|
|
|
112
|
-
restoreLocaleFromStore(){
|
|
131
|
+
restoreLocaleFromStore() {
|
|
113
132
|
if (window.localStorage) {
|
|
114
|
-
|
|
115
|
-
|
|
133
|
+
try {
|
|
134
|
+
return window.localStorage.getItem('locale');
|
|
116
135
|
} catch (e) {
|
|
117
136
|
this.app.error(e);
|
|
118
137
|
return false;
|
|
@@ -121,10 +140,10 @@ class nsLocale{
|
|
|
121
140
|
return false;
|
|
122
141
|
}
|
|
123
142
|
|
|
124
|
-
saveLocaleToStore(locale){
|
|
143
|
+
saveLocaleToStore(locale) {
|
|
125
144
|
if (window.localStorage) {
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
try {
|
|
146
|
+
return window.localStorage.setItem('locale', locale);
|
|
128
147
|
} catch (e) {
|
|
129
148
|
this.app.error(e);
|
|
130
149
|
return false;
|
|
@@ -133,12 +152,12 @@ class nsLocale{
|
|
|
133
152
|
return false;
|
|
134
153
|
}
|
|
135
154
|
|
|
136
|
-
selectBest(){
|
|
137
|
-
if(navigator.languages){
|
|
155
|
+
selectBest() {
|
|
156
|
+
if (navigator.languages) {
|
|
138
157
|
let locale = navigator.languages.find((itm) => {
|
|
139
158
|
return this.locales.includes(itm);
|
|
140
159
|
});
|
|
141
|
-
if(locale){
|
|
160
|
+
if (locale) {
|
|
142
161
|
return locale;
|
|
143
162
|
}
|
|
144
163
|
}
|
package/src/routes/locale.js
CHANGED
|
@@ -6,10 +6,7 @@ async function get(req, res){
|
|
|
6
6
|
try{
|
|
7
7
|
let locale = req.params.locale;
|
|
8
8
|
let result = await notNode.Application.getLogic('Locale').get({locale});
|
|
9
|
-
res.status(200).json(
|
|
10
|
-
status: 'ok',
|
|
11
|
-
result
|
|
12
|
-
});
|
|
9
|
+
res.status(200).json(result);
|
|
13
10
|
}catch(err){
|
|
14
11
|
Log.error(err);
|
|
15
12
|
notNode.Application.report(
|
|
@@ -31,10 +28,7 @@ async function get(req, res){
|
|
|
31
28
|
async function available(req, res){
|
|
32
29
|
try{
|
|
33
30
|
let result = await notNode.Application.getLogic('Locale').available();
|
|
34
|
-
res.status(200).json(
|
|
35
|
-
status: 'ok',
|
|
36
|
-
result
|
|
37
|
-
});
|
|
31
|
+
res.status(200).json(result);
|
|
38
32
|
}catch(err){
|
|
39
33
|
Log.error(err);
|
|
40
34
|
notNode.Application.report(
|
package/src/routes/locale.ws.js
CHANGED
package/test/index.js
CHANGED
|
@@ -48,7 +48,7 @@ describe("fromDir", function() {
|
|
|
48
48
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
it("try to load
|
|
51
|
+
it("try to load faulty json files", function() {
|
|
52
52
|
locale.fromDir(path.join(__dirname, 'faulty.locales'))
|
|
53
53
|
.then(()=>{
|
|
54
54
|
expect().fail();
|
|
@@ -71,7 +71,7 @@ describe("say", function() {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("phrase not exists `like`", function() {
|
|
74
|
-
expect(locale.say('
|
|
74
|
+
expect(locale.say('like_me')).to.be.equal('like_me');
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
it("locale not exists, should throw", function() {
|
|
@@ -91,6 +91,24 @@ describe("say", function() {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
+
|
|
95
|
+
describe("say for module", function() {
|
|
96
|
+
it("say login in default(en) locale for not-user module", function() {
|
|
97
|
+
let say = locale.sayForModule('not-user');
|
|
98
|
+
expect(typeof say).to.be.equal('function');
|
|
99
|
+
expect(say('login')).to.be.equal('login for module version');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("modulePhrase", function() {
|
|
104
|
+
it("prefixes phrase with module name", function() {
|
|
105
|
+
let say = locale.modulePhrase('not-user');
|
|
106
|
+
expect(typeof say).to.be.equal('function');
|
|
107
|
+
expect(say('login')).to.be.equal('not-user:login');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
|
|
94
112
|
describe("middleware", function() {
|
|
95
113
|
it("pass in express request mockup with Accept-Language: ga ", function() {
|
|
96
114
|
locale.vocabulary()['ga'] = {
|
|
@@ -102,18 +120,18 @@ describe("middleware", function() {
|
|
|
102
120
|
return 'ga';
|
|
103
121
|
}
|
|
104
122
|
},resMock = {locals:{}};
|
|
105
|
-
locale.
|
|
123
|
+
locale.getMiddleware()(reqMock, resMock, ()=>{
|
|
106
124
|
expect(resMock.locals.locale).to.be.equal('ga');
|
|
107
125
|
});
|
|
108
126
|
});
|
|
109
127
|
|
|
110
128
|
it("init middleware with option default: ru", function() {
|
|
111
|
-
locale.
|
|
129
|
+
locale.getMiddleware({default: 'ru'});
|
|
112
130
|
expect(locale.OPTS().default).to.be.equal('ru');
|
|
113
131
|
});
|
|
114
132
|
|
|
115
133
|
it("init middleware with empty options", function() {
|
|
116
|
-
locale.
|
|
134
|
+
locale.getMiddleware({});
|
|
117
135
|
expect(locale.OPTS().default).to.be.equal('ru');
|
|
118
136
|
});
|
|
119
137
|
|
|
@@ -123,13 +141,13 @@ describe("middleware", function() {
|
|
|
123
141
|
return 'it';
|
|
124
142
|
}
|
|
125
143
|
},resMock = {locals:{}};
|
|
126
|
-
locale.
|
|
144
|
+
locale.getMiddleware()(reqMock, resMock, ()=>{
|
|
127
145
|
expect(resMock.locals.locale).to.be.equal(locale.OPTS().default);
|
|
128
146
|
});
|
|
129
147
|
});
|
|
130
148
|
|
|
131
149
|
it("init middleware with custom getter", function() {
|
|
132
|
-
let middleware = locale.
|
|
150
|
+
let middleware = locale.getMiddleware({
|
|
133
151
|
getter:(req)=>{
|
|
134
152
|
return req.user.lang;
|
|
135
153
|
}}),resMock = {locals:{}};
|
package/test/locales/en.json
CHANGED