@things-factory/i18n-base 7.0.1-alpha.4 → 7.0.1-alpha.43
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/dist-server/routes.js
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const i18next_1 = tslib_1.__importDefault(require("i18next"));
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const terminology_1 = require("./service/terminology/terminology");
|
|
8
|
+
const path = require('path');
|
|
9
|
+
var fs = require('fs');
|
|
10
|
+
process.on('client-rebuilt', (app, compilerFileSystem) => {
|
|
11
|
+
/* change filesystem whenever webpacking assets done. only for development mode. */
|
|
12
|
+
fs = compilerFileSystem;
|
|
13
|
+
});
|
|
5
14
|
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
|
|
6
15
|
globalPublicRouter.get('/translations/translate/:lng/:key', async (context, next) => {
|
|
7
16
|
const { lng, key } = context.params;
|
|
@@ -9,10 +18,37 @@ process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) =>
|
|
|
9
18
|
context.body = translated;
|
|
10
19
|
});
|
|
11
20
|
globalPublicRouter.get('/translations/translate/:key', async (context, next) => {
|
|
12
|
-
const { lng } = context.state;
|
|
13
21
|
const { key } = context.params;
|
|
14
22
|
const translated = context.t(key);
|
|
15
23
|
context.body = translated;
|
|
16
24
|
});
|
|
17
25
|
});
|
|
26
|
+
process.on('bootstrap-module-domain-public-route', (app, domainPublicRouter) => {
|
|
27
|
+
domainPublicRouter.get('/domain/:domain/translations/:filename', async (context, next) => {
|
|
28
|
+
const { filename } = context.params;
|
|
29
|
+
const { domain } = context.state;
|
|
30
|
+
// context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년
|
|
31
|
+
// context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정
|
|
32
|
+
const locale = (filename || 'en.json').split('.')[0];
|
|
33
|
+
const file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)));
|
|
34
|
+
const terminologies = await (0, shell_1.getRepository)(terminology_1.Terminology).find({
|
|
35
|
+
where: { domain: { id: domain.id }, locale: (0, typeorm_1.ILike)(locale + '%') }
|
|
36
|
+
});
|
|
37
|
+
try {
|
|
38
|
+
const json = JSON.parse(file);
|
|
39
|
+
terminologies.forEach(term => {
|
|
40
|
+
const { name, category, display } = term;
|
|
41
|
+
json[`${category}.${name}`] = display;
|
|
42
|
+
});
|
|
43
|
+
context.type = 'application/json';
|
|
44
|
+
context.body = json;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.error(err);
|
|
49
|
+
}
|
|
50
|
+
context.type = 'application/json';
|
|
51
|
+
context.body = file;
|
|
52
|
+
});
|
|
53
|
+
});
|
|
18
54
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;;AAAA,8DAA6B;
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;;AAAA,8DAA6B;AAC7B,qCAA+B;AAE/B,iDAA6D;AAC7D,mEAA+D;AAE/D,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEtB,OAAO,CAAC,EAAE,CAAC,gBAAuB,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IAC9D,mFAAmF;IACnF,EAAE,GAAG,kBAAkB,CAAA;AACzB,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,E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AC,CAAA;QAE3F,MAAM,aAAa,GAAG,MAAM,IAAA,qBAAa,EAAC,yBAAW,CAAC,CAAC,IAAI,CAAC;YAC1D,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAA,eAAK,EAAC,MAAM,GAAG,GAAG,CAAC,EAAE;SAClE,CAAC,CAAA;QAEF,IAAI;YACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAE7B,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBAC3B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;gBACxC,IAAI,CAAC,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC,GAAG,OAAO,CAAA;YACvC,CAAC,CAAC,CAAA;YAEF,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;YACjC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;YAEnB,OAAM;SACP;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SACnB;QAED,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;QACjC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;IACrB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import i18next from 'i18next'\nimport { ILike } from 'typeorm'\n\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { Terminology } from './service/terminology/terminology'\n\nconst path = require('path')\nvar fs = require('fs')\n\nprocess.on('client-rebuilt' as any, (app, compilerFileSystem) => {\n /* change filesystem whenever webpacking assets done. only for development mode. */\n fs = compilerFileSystem\n})\n\nprocess.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {\n globalPublicRouter.get('/translations/translate/:lng/:key', async (context, next) => {\n const { lng, key } = context.params\n const translated = i18next.getFixedT(lng, 'translations' /* ns */)(key)\n\n context.body = translated\n })\n\n globalPublicRouter.get('/translations/translate/:key', async (context, next) => {\n const { key } = context.params\n const translated = context.t(key)\n\n context.body = translated\n })\n})\n\nprocess.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {\n domainPublicRouter.get('/domain/:domain/translations/:filename', async (context, next) => {\n const { filename } = context.params\n const { domain } = context.state\n\n // context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년\n // context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정\n\n const locale = (filename || 'en.json').split('.')[0]\n const file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)))\n\n const terminologies = await getRepository(Terminology).find({\n where: { domain: { id: domain.id }, locale: ILike(locale + '%') }\n })\n\n try {\n const json = JSON.parse(file)\n\n terminologies.forEach(term => {\n const { name, category, display } = term\n json[`${category}.${name}`] = display\n })\n\n context.type = 'application/json'\n context.body = json\n\n return\n } catch (err) {\n console.error(err)\n }\n\n context.type = 'application/json'\n context.body = file\n })\n})\n"]}
|