waibu 1.0.7 → 1.0.9

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.
@@ -1,6 +1,11 @@
1
- function getPluginPrefix (base) {
1
+ function getPluginPrefix (base, webApp = 'waibuMpa') {
2
2
  const { get, trim } = this.app.bajo.lib._
3
- const prefix = get(this, `app.${base}.config.waibu.prefix`, this.app[base].alias)
3
+ let prefix = get(this, `app.${base}.config.waibu.prefix`, this.app[base].alias)
4
+ if (base === 'main') {
5
+ const cfg = this.app[webApp].config
6
+ if (cfg.mountMainAsRoot) prefix = ''
7
+ }
8
+
4
9
  return trim(prefix, '/')
5
10
  }
6
11
 
@@ -20,7 +20,7 @@ function routePath (name = '', { query = {}, base = 'waibuMpa', params = {}, gue
20
20
  return p[0] === ':' && params[p.slice(1)] ? params[p.slice(1)] : p
21
21
  }).join('/')
22
22
  let url = info.path
23
- const langDetector = get(cfg, 'i18n.detectors', [])
23
+ const langDetector = get(cfg, 'intl.detectors', [])
24
24
  if (info.ns) url = trimEnd(langDetector.includes('path') ? `/${params.lang ?? ''}${this.routeDir(info.ns)}${info.path}` : `${this.routeDir(info.ns)}${info.path}`, '/')
25
25
  info.qs = defaultsDeep({}, query, info.qs)
26
26
  if (!isEmpty(info.qs)) url += '?' + this.qs.stringify(info.qs)
package/bajo/start.js CHANGED
@@ -22,8 +22,8 @@ async function start () {
22
22
 
23
23
  const instance = fastify(cfg.factory)
24
24
  instance.decorateRequest('lang', null)
25
- instance.decorateRequest('i18n', null)
26
25
  instance.decorateRequest('t', () => {})
26
+ instance.decorateRequest('format', () => {})
27
27
  instance.decorateRequest('langDetector', null)
28
28
  instance.decorateRequest('site', null)
29
29
  instance.decorateRequest('ns', null)
package/lib/app.js CHANGED
@@ -9,7 +9,7 @@ export async function collect (glob = 'boot.js', baseNs) {
9
9
  await eachPlugins(async function ({ config, file, ns, alias }) {
10
10
  const mod = await importModule(file, { asHandler: true })
11
11
  mod.prefix = get(config, 'waibu.prefix', alias)
12
- if (get(config, 'i18n.detectors', []).includes('path')) mod.prefix = `/:lang${mod.prefix}`
12
+ if (get(config, 'intl.detectors', []).includes('path')) mod.prefix = `/:lang${mod.prefix}`
13
13
  mod.ns = ns
14
14
  mod.alias = alias
15
15
  mods.push(mod)
@@ -1,7 +1,7 @@
1
1
  function detect (detector = [], req, reply) {
2
2
  const { get, map, trim, orderBy } = this.app.bajo.lib._
3
- const supported = get(this, 'app.bajoI18N.config.supportedLngs', [this.app.bajo.config.lang])
4
- const defLang = get(this, 'app.bajoI18N.config.lang', this.app.bajo.config.lang)
3
+ const supported = get(this, 'app.bajo.config.intl.supported', [this.app.bajo.config.lang])
4
+ const defLang = get(this, 'app.bajo.config.intl.fallback', this.app.bajo.config.lang)
5
5
  let lang = null
6
6
  // by route path
7
7
  if (detector.includes('path')) {
@@ -48,24 +48,16 @@ function detect (detector = [], req, reply) {
48
48
  req.lang = lang ?? defLang
49
49
  }
50
50
 
51
- async function attachI18N (detector = [], req, reply) {
52
- if (!this.app.bajoI18N) return
53
- const { importModule } = this.app.bajo
51
+ async function attachIntl (detector = [], req, reply) {
54
52
  const { get } = this.app.bajo.lib._
55
- const translate = await importModule('bajo:/boot/lib/translate.js')
56
53
  detect.call(this, detector, req, reply)
57
54
  const defNs = get(req, 'routeOptions.config.ns', this.name)
58
- const opts = { defaultNS: defNs }
59
- if (req.lang) opts.lng = req.lang
60
- req.i18n = this.app.bajoI18N.instance.cloneInstance(opts)
61
- req.t = (...args) => {
62
- // console.log(args)
63
- // const defNs = get(req, 'routeOptions.config.ns', this.name)
64
- return translate.call(this.app[defNs], req.i18n, ...args)
55
+ req.t = (text, ...args) => {
56
+ return this.app[defNs].print.write(text, req.lang, ...args)
65
57
  }
66
58
  req.format = (value, type = 'auto', opts) => {
67
- return this.app.bajoI18N.format(value, type, req.lang, opts)
59
+ return this.app.bajo.format(value, type, req.lang, opts)
68
60
  }
69
61
  }
70
62
 
71
- export default attachI18N
63
+ export default attachIntl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
File without changes