@things-factory/i18n-base 7.0.1-alpha.1 → 7.0.1-alpha.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/i18n-base",
3
- "version": "7.0.1-alpha.1",
3
+ "version": "7.0.1-alpha.13",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@operato/i18n": "^2.0.0-alpha.0",
28
- "@things-factory/shell": "^7.0.1-alpha.1"
28
+ "@things-factory/shell": "^7.0.1-alpha.13"
29
29
  },
30
- "gitHead": "6cc9a9da9059f32f8c2968c57831c1d353a2ec97"
30
+ "gitHead": "58eaf3ce7403c0722fe948041bad0185e57fdc81"
31
31
  }
package/server/routes.ts CHANGED
@@ -1,4 +1,16 @@
1
1
  import i18next from 'i18next'
2
+ import { ILike } from 'typeorm'
3
+
4
+ import { Domain, getRepository } from '@things-factory/shell'
5
+ import { Terminology } from './service/terminology/terminology'
6
+
7
+ const path = require('path')
8
+ var fs = require('fs')
9
+
10
+ process.on('client-rebuilt' as any, (app, compilerFileSystem) => {
11
+ /* change filesystem whenever webpacking assets done. only for development mode. */
12
+ fs = compilerFileSystem
13
+ })
2
14
 
3
15
  process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
4
16
  globalPublicRouter.get('/translations/translate/:lng/:key', async (context, next) => {
@@ -9,10 +21,45 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
9
21
  })
10
22
 
11
23
  globalPublicRouter.get('/translations/translate/:key', async (context, next) => {
12
- const { lng } = context.state
13
24
  const { key } = context.params
14
25
  const translated = context.t(key)
15
26
 
16
27
  context.body = translated
17
28
  })
18
29
  })
30
+
31
+ process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
32
+ domainPublicRouter.get('/domain/:domain/translations/:filename', async (context, next) => {
33
+ const { filename } = context.params
34
+ const { domain } = context.state
35
+
36
+ // context.set('Cache-Control', 'public, max-age=31536000') // 캐시 기간 설정 : 1년
37
+ // context.set('Expires', new Date(Date.now() + 31536000000).toUTCString()) // 캐시 만료일 설정
38
+
39
+ const locale = (filename || 'en.json').split('.')[0]
40
+ const file = fs.readFileSync(path.resolve(path.join('dist-app', 'translations', filename)))
41
+
42
+ const terminologies = await getRepository(Terminology).find({
43
+ where: { domain: { id: domain.id }, locale: ILike(locale + '%') }
44
+ })
45
+
46
+ try {
47
+ const json = JSON.parse(file)
48
+
49
+ terminologies.forEach(term => {
50
+ const { name, category, display } = term
51
+ json[`${category}.${name}`] = display
52
+ })
53
+
54
+ context.type = 'application/json'
55
+ context.body = json
56
+
57
+ return
58
+ } catch (err) {
59
+ console.error(err)
60
+ }
61
+
62
+ context.type = 'application/json'
63
+ context.body = file
64
+ })
65
+ })