@things-factory/i18n-base 7.0.66 → 7.0.67

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.
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translationsRouter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
6
+ const typeorm_1 = require("typeorm");
7
+ const shell_1 = require("@things-factory/shell");
8
+ const terminology_1 = require("../service/terminology/terminology");
9
+ const env_1 = require("@things-factory/env");
10
+ const path = require('path');
11
+ const cacheFS = require('fs');
12
+ var fs = require('fs');
13
+ const disableCustomTerminologyFeature = env_1.config.get('i18n/disableCustomTerminologyFeature');
14
+ if (!disableCustomTerminologyFeature) {
15
+ process.on('client-rebuilt', (app, compilerFileSystem) => {
16
+ /* change filesystem whenever webpacking assets done. only for development mode. */
17
+ fs = compilerFileSystem;
18
+ const cacheFileFolder = path.join('cache', 'translations');
19
+ if (cacheFS.existsSync(cacheFileFolder)) {
20
+ cacheFS.rmSync(cacheFileFolder, { recursive: true });
21
+ }
22
+ });
23
+ }
24
+ exports.translationsRouter = new koa_router_1.default();
25
+ exports.translationsRouter.get('/translations/:filename', async (context, next) => {
26
+ const { subdomain, filename } = context.params;
27
+ const { domain } = context.state;
28
+ const locale = (filename || 'en.json').split('.')[0];
29
+ // context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년
30
+ // context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정
31
+ if (disableCustomTerminologyFeature) {
32
+ var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)));
33
+ context.type = 'application/json';
34
+ context.body = file;
35
+ return;
36
+ }
37
+ const cacheFileFolder = path.join('cache', 'translations', subdomain);
38
+ const cacheFilePath = path.join(cacheFileFolder, filename);
39
+ if (cacheFS.existsSync(cacheFilePath)) {
40
+ var file = cacheFS.readFileSync(cacheFilePath);
41
+ }
42
+ else {
43
+ var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)));
44
+ try {
45
+ const terminologies = await (0, shell_1.getRepository)(terminology_1.Terminology).find({
46
+ where: { domain: { id: domain.id }, locale: (0, typeorm_1.ILike)(locale + '%') }
47
+ });
48
+ const json = JSON.parse(file);
49
+ terminologies.forEach(term => {
50
+ const { name, category, display } = term;
51
+ json[`${category}.${name}`] = display;
52
+ });
53
+ try {
54
+ if (!cacheFS.existsSync(cacheFileFolder)) {
55
+ cacheFS.mkdirSync(cacheFileFolder, { recursive: true });
56
+ }
57
+ cacheFS.writeFileSync(cacheFilePath, JSON.stringify(json));
58
+ }
59
+ catch (err) {
60
+ console.error(err);
61
+ }
62
+ context.type = 'application/json';
63
+ context.body = json;
64
+ return;
65
+ }
66
+ catch (err) {
67
+ console.error(err);
68
+ }
69
+ }
70
+ context.type = 'application/json';
71
+ context.body = file;
72
+ });
73
+ //# sourceMappingURL=translations-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations-router.js","sourceRoot":"","sources":["../../server/routers/translations-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,qCAA+B;AAE/B,iDAAqD;AACrD,oEAAgE;AAChE,6CAA4C;AAE5C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAC7B,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEtB,MAAM,+BAA+B,GAAG,YAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAA;AAE1F,IAAI,CAAC,+BAA+B,EAAE,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,gBAAuB,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;QAC9D,mFAAmF;QACnF,EAAE,GAAG,kBAAkB,CAAA;QAEvB,MAAM,eAAe,GAAG,IAA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C;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;IACjC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;AACrB,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport { ILike } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\nimport { Terminology } from '../service/terminology/terminology'\nimport { config } from '@things-factory/env'\n\nconst path = require('path')\nconst cacheFS = require('fs')\nvar fs = require('fs')\n\nconst disableCustomTerminologyFeature = config.get('i18n/disableCustomTerminologyFeature')\n\nif (!disableCustomTerminologyFeature) {\n process.on('client-rebuilt' as any, (app, compilerFileSystem) => {\n /* change filesystem whenever webpacking assets done. only for development mode. */\n fs = compilerFileSystem\n\n const cacheFileFolder = path.join('cache', 'translations')\n\n if (cacheFS.existsSync(cacheFileFolder)) {\n cacheFS.rmSync(cacheFileFolder, { recursive: true })\n }\n })\n}\n\nexport const translationsRouter = new Router()\n\ntranslationsRouter.get('/translations/:filename', async (context, next) => {\n const { subdomain, filename } = context.params\n const { domain } = context.state\n\n const locale = (filename || 'en.json').split('.')[0]\n\n // context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년\n // context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정\n\n if (disableCustomTerminologyFeature) {\n var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)))\n\n context.type = 'application/json'\n context.body = file\n return\n }\n\n const cacheFileFolder = path.join('cache', 'translations', subdomain)\n const cacheFilePath = path.join(cacheFileFolder, filename)\n\n if (cacheFS.existsSync(cacheFilePath)) {\n var file = cacheFS.readFileSync(cacheFilePath)\n } else {\n var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)))\n\n try {\n const terminologies = await getRepository(Terminology).find({\n where: { domain: { id: domain.id }, locale: ILike(locale + '%') }\n })\n\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 try {\n if (!cacheFS.existsSync(cacheFileFolder)) {\n cacheFS.mkdirSync(cacheFileFolder, { recursive: true })\n }\n\n cacheFS.writeFileSync(cacheFilePath, JSON.stringify(json))\n } catch (err) {\n console.error(err)\n }\n\n context.type = 'application/json'\n context.body = json\n\n return\n } catch (err) {\n console.error(err)\n }\n }\n\n context.type = 'application/json'\n context.body = file\n})\n"]}
@@ -2,22 +2,10 @@
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
5
  const env_1 = require("@things-factory/env");
8
6
  const disableCustomTerminologyFeature = env_1.config.get('i18n/disableCustomTerminologyFeature');
9
- const terminology_1 = require("./service/terminology/terminology");
10
- const path = require('path');
11
- const cacheFS = require('fs');
12
- var fs = require('fs');
13
- process.on('client-rebuilt', (app, compilerFileSystem) => {
14
- /* change filesystem whenever webpacking assets done. only for development mode. */
15
- fs = compilerFileSystem;
16
- const cacheFileFolder = path.join('cache', 'translations');
17
- if (cacheFS.existsSync(cacheFileFolder)) {
18
- cacheFS.rmSync(cacheFileFolder, { recursive: true });
19
- }
20
- });
7
+ const isPathBaseDomain = !env_1.config.get('subdomain') && !env_1.config.get('useVirtualHostBasedDomain');
8
+ const translations_router_1 = require("./routers/translations-router");
21
9
  process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
22
10
  globalPublicRouter.get('/translations/translate/:lng/:key', async (context, next) => {
23
11
  const { lng, key } = context.params;
@@ -31,53 +19,11 @@ process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) =>
31
19
  });
32
20
  });
33
21
  process.on('bootstrap-module-domain-public-route', (app, domainPublicRouter) => {
34
- domainPublicRouter.get('/domain/:subdomain/translations/:filename', async (context, next) => {
35
- const { subdomain, filename } = context.params;
36
- const { domain } = context.state;
37
- const locale = (filename || 'en.json').split('.')[0];
38
- // context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년
39
- // context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정
40
- if (disableCustomTerminologyFeature) {
41
- var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)));
42
- context.type = 'application/json';
43
- context.body = file;
44
- return;
45
- }
46
- const cacheFileFolder = path.join('cache', 'translations', subdomain);
47
- const cacheFilePath = path.join(cacheFileFolder, filename);
48
- if (cacheFS.existsSync(cacheFilePath)) {
49
- var file = cacheFS.readFileSync(cacheFilePath);
50
- }
51
- else {
52
- var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)));
53
- try {
54
- const terminologies = await (0, shell_1.getRepository)(terminology_1.Terminology).find({
55
- where: { domain: { id: domain.id }, locale: (0, typeorm_1.ILike)(locale + '%') }
56
- });
57
- const json = JSON.parse(file);
58
- terminologies.forEach(term => {
59
- const { name, category, display } = term;
60
- json[`${category}.${name}`] = display;
61
- });
62
- try {
63
- if (!cacheFS.existsSync(cacheFileFolder)) {
64
- cacheFS.mkdirSync(cacheFileFolder, { recursive: true });
65
- }
66
- cacheFS.writeFileSync(cacheFilePath, JSON.stringify(json));
67
- }
68
- catch (err) {
69
- console.error(err);
70
- }
71
- context.type = 'application/json';
72
- context.body = json;
73
- return;
74
- }
75
- catch (err) {
76
- console.error(err);
77
- }
78
- }
79
- context.type = 'application/json';
80
- context.body = file;
81
- });
22
+ if (isPathBaseDomain) {
23
+ domainPublicRouter.use('/domain/:subdomain', translations_router_1.translationsRouter.routes(), translations_router_1.translationsRouter.allowedMethods());
24
+ }
25
+ else if (!disableCustomTerminologyFeature) {
26
+ domainPublicRouter.use('', translations_router_1.translationsRouter.routes(), translations_router_1.translationsRouter.allowedMethods());
27
+ }
82
28
  });
83
29
  //# sourceMappingURL=routes.js.map
@@ -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AAG,kBAAkB,CAAA;gBACjC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;gBAEnB,OAAM;YACR,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACpB,CAAC;QACH,CAAC;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 { getRepository } from '@things-factory/shell'\nimport { config } from '@things-factory/env'\n\nconst disableCustomTerminologyFeature = config.get('i18n/disableCustomTerminologyFeature')\n\nimport { Terminology } from './service/terminology/terminology'\n\nconst path = require('path')\nconst cacheFS = require('fs')\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 const cacheFileFolder = path.join('cache', 'translations')\n\n if (cacheFS.existsSync(cacheFileFolder)) {\n cacheFS.rmSync(cacheFileFolder, { recursive: true })\n }\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/:subdomain/translations/:filename', async (context, next) => {\n const { subdomain, filename } = context.params\n const { domain } = context.state\n\n const locale = (filename || 'en.json').split('.')[0]\n\n // context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년\n // context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정\n\n if (disableCustomTerminologyFeature) {\n var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)))\n\n context.type = 'application/json'\n context.body = file\n return\n }\n\n const cacheFileFolder = path.join('cache', 'translations', subdomain)\n const cacheFilePath = path.join(cacheFileFolder, filename)\n\n if (cacheFS.existsSync(cacheFilePath)) {\n var file = cacheFS.readFileSync(cacheFilePath)\n } else {\n var file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)))\n\n try {\n const terminologies = await getRepository(Terminology).find({\n where: { domain: { id: domain.id }, locale: ILike(locale + '%') }\n })\n\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 try {\n if (!cacheFS.existsSync(cacheFileFolder)) {\n cacheFS.mkdirSync(cacheFileFolder, { recursive: true })\n }\n\n cacheFS.writeFileSync(cacheFilePath, JSON.stringify(json))\n } catch (err) {\n console.error(err)\n }\n\n context.type = 'application/json'\n context.body = json\n\n return\n } catch (err) {\n console.error(err)\n }\n }\n\n context.type = 'application/json'\n context.body = file\n })\n})\n"]}
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;;AAAA,8DAA6B;AAC7B,6CAA4C;AAE5C,MAAM,+BAA+B,GAAG,YAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAA;AAC1F,MAAM,gBAAgB,GAAG,CAAC,YAAM,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,YAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;AAE7F,uEAAkE;AAElE,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF,kBAAkB,CAAC,GAAG,CAAC,mCAAmC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAClF,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAA;QACnC,MAAM,UAAU,GAAG,iBAAO,CAAC,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAA;QAEvE,OAAO,CAAC,IAAI,GAAG,UAAU,CAAA;IAC3B,CAAC,CAAC,CAAA;IAEF,kBAAkB,CAAC,GAAG,CAAC,8BAA8B,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7E,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAA;QAC9B,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAEjC,OAAO,CAAC,IAAI,GAAG,UAAU,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF,IAAI,gBAAgB,EAAE,CAAC;QACrB,kBAAkB,CAAC,GAAG,CAAC,oBAAoB,EAAE,wCAAkB,CAAC,MAAM,EAAE,EAAE,wCAAkB,CAAC,cAAc,EAAE,CAAC,CAAA;IAChH,CAAC;SAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;QAC5C,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAAE,wCAAkB,CAAC,MAAM,EAAE,EAAE,wCAAkB,CAAC,cAAc,EAAE,CAAC,CAAA;IAC9F,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["import i18next from 'i18next'\nimport { config } from '@things-factory/env'\n\nconst disableCustomTerminologyFeature = config.get('i18n/disableCustomTerminologyFeature')\nconst isPathBaseDomain = !config.get('subdomain') && !config.get('useVirtualHostBasedDomain')\n\nimport { translationsRouter } from './routers/translations-router'\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 if (isPathBaseDomain) {\n domainPublicRouter.use('/domain/:subdomain', translationsRouter.routes(), translationsRouter.allowedMethods())\n } else if (!disableCustomTerminologyFeature) {\n domainPublicRouter.use('', translationsRouter.routes(), translationsRouter.allowedMethods())\n }\n})\n"]}