@nocobase/server 0.16.0-alpha.3 → 0.16.0-alpha.4

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.
@@ -2,7 +2,7 @@
2
2
  /// <reference types="koa-bodyparser" />
3
3
  import { ACL } from '@nocobase/acl';
4
4
  import { AuthManager, AuthManagerOptions } from '@nocobase/auth';
5
- import { CacheManagerOptions, Cache, CacheManager } from '@nocobase/cache';
5
+ import { Cache, CacheManager, CacheManagerOptions } from '@nocobase/cache';
6
6
  import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
7
7
  import { AppLoggerOptions, Logger } from '@nocobase/logger';
8
8
  import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
@@ -13,11 +13,11 @@ import { i18n, InitOptions } from 'i18next';
13
13
  import Koa, { DefaultContext as KoaDefaultContext, DefaultState as KoaDefaultState } from 'koa';
14
14
  import { AppCommand } from './app-command';
15
15
  import { AppSupervisor } from './app-supervisor';
16
+ import { CronJobManager } from './cron/cron-job-manager';
16
17
  import { ApplicationVersion } from './helpers/application-version';
17
18
  import { Locale } from './locale';
18
19
  import { Plugin } from './plugin';
19
20
  import { InstallOptions, PluginManager } from './plugin-manager';
20
- import { CronJobManager } from './cron/cron-job-manager';
21
21
  export type PluginType = string | typeof Plugin;
22
22
  export type PluginConfiguration = PluginType | [PluginType, any];
23
23
  export interface ResourcerOptions {
@@ -118,6 +118,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
118
118
  get authManager(): AuthManager;
119
119
  protected _locales: Locale;
120
120
  get locales(): Locale;
121
+ get localeManager(): Locale;
121
122
  protected _version: ApplicationVersion;
122
123
  get version(): ApplicationVersion;
123
124
  get log(): Logger;
@@ -44,14 +44,14 @@ var import_lodash = __toESM(require("lodash"));
44
44
  var import_acl2 = require("./acl");
45
45
  var import_app_command = require("./app-command");
46
46
  var import_app_supervisor = require("./app-supervisor");
47
+ var import_cache2 = require("./cache");
47
48
  var import_commands = require("./commands");
49
+ var import_cron_job_manager = require("./cron/cron-job-manager");
48
50
  var import_application_not_install = require("./errors/application-not-install");
49
51
  var import_helper = require("./helper");
50
52
  var import_application_version = require("./helpers/application-version");
51
53
  var import_locale = require("./locale");
52
54
  var import_plugin_manager = require("./plugin-manager");
53
- var import_cron_job_manager = require("./cron/cron-job-manager");
54
- var import_cache2 = require("./cache");
55
55
  const packageJson = require("../package.json");
56
56
  const _Application = class _Application extends import_koa.default {
57
57
  constructor(options) {
@@ -134,6 +134,9 @@ const _Application = class _Application extends import_koa.default {
134
134
  get locales() {
135
135
  return this._locales;
136
136
  }
137
+ get localeManager() {
138
+ return this._locales;
139
+ }
137
140
  _version;
138
141
  get version() {
139
142
  return this._version;
@@ -5,6 +5,7 @@ export declare class Locale {
5
5
  cache: Cache;
6
6
  defaultLang: string;
7
7
  localeFn: Map<any, any>;
8
+ resourceCached: Map<any, any>;
8
9
  constructor(app: Application);
9
10
  load(): Promise<void>;
10
11
  setLocaleFn(name: string, fn: (lang: string) => Promise<any>): void;
@@ -12,6 +13,7 @@ export declare class Locale {
12
13
  resources: any;
13
14
  }>;
14
15
  wrapCache(key: string, fn: () => any): Promise<any>;
16
+ loadResourcesByLang(lang: string): Promise<void>;
15
17
  getCacheResources(lang: string): Promise<any>;
16
18
  getResources(lang: string): {};
17
19
  }
@@ -28,6 +28,7 @@ const _Locale = class _Locale {
28
28
  cache;
29
29
  defaultLang = "en-US";
30
30
  localeFn = /* @__PURE__ */ new Map();
31
+ resourceCached = /* @__PURE__ */ new Map();
31
32
  constructor(app) {
32
33
  this.app = app;
33
34
  this.app.on("afterLoad", async () => {
@@ -66,7 +67,16 @@ const _Locale = class _Locale {
66
67
  isCacheable: (val) => !import_utils.lodash.isEmpty(val)
67
68
  });
68
69
  }
70
+ async loadResourcesByLang(lang) {
71
+ if (!this.cache) {
72
+ return;
73
+ }
74
+ if (!this.resourceCached.has(lang)) {
75
+ await this.getCacheResources(lang);
76
+ }
77
+ }
69
78
  async getCacheResources(lang) {
79
+ this.resourceCached.set(lang, true);
70
80
  return await this.wrapCache(`resources:${lang}`, () => this.getResources(lang));
71
81
  }
72
82
  getResources(lang) {
@@ -90,6 +100,9 @@ const _Locale = class _Locale {
90
100
  } catch (err) {
91
101
  }
92
102
  }
103
+ Object.keys(resources).forEach((name) => {
104
+ this.app.i18n.addResources(lang, name, resources[name]);
105
+ });
93
106
  return resources;
94
107
  }
95
108
  };
@@ -32,6 +32,7 @@ async function i18n(ctx, next) {
32
32
  const lng = ctx.getCurrentLocale();
33
33
  if (lng !== "*" && lng) {
34
34
  i18n2.changeLanguage(lng);
35
+ await ctx.app.localeManager.loadResourcesByLang(lng);
35
36
  }
36
37
  await next();
37
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.16.0-alpha.3",
3
+ "version": "0.16.0-alpha.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,16 +10,16 @@
10
10
  "@koa/cors": "^3.1.0",
11
11
  "@koa/multer": "^3.0.2",
12
12
  "@koa/router": "^9.4.0",
13
- "@nocobase/acl": "0.16.0-alpha.3",
14
- "@nocobase/actions": "0.16.0-alpha.3",
15
- "@nocobase/auth": "0.16.0-alpha.3",
16
- "@nocobase/cache": "0.16.0-alpha.3",
17
- "@nocobase/database": "0.16.0-alpha.3",
18
- "@nocobase/evaluators": "0.16.0-alpha.3",
19
- "@nocobase/logger": "0.16.0-alpha.3",
20
- "@nocobase/resourcer": "0.16.0-alpha.3",
21
- "@nocobase/sdk": "0.16.0-alpha.3",
22
- "@nocobase/utils": "0.16.0-alpha.3",
13
+ "@nocobase/acl": "0.16.0-alpha.4",
14
+ "@nocobase/actions": "0.16.0-alpha.4",
15
+ "@nocobase/auth": "0.16.0-alpha.4",
16
+ "@nocobase/cache": "0.16.0-alpha.4",
17
+ "@nocobase/database": "0.16.0-alpha.4",
18
+ "@nocobase/evaluators": "0.16.0-alpha.4",
19
+ "@nocobase/logger": "0.16.0-alpha.4",
20
+ "@nocobase/resourcer": "0.16.0-alpha.4",
21
+ "@nocobase/sdk": "0.16.0-alpha.4",
22
+ "@nocobase/utils": "0.16.0-alpha.4",
23
23
  "@types/decompress": "4.2.4",
24
24
  "@types/ini": "^1.3.31",
25
25
  "@types/koa-send": "^4.1.3",
@@ -52,5 +52,5 @@
52
52
  "@types/serve-handler": "^6.1.1",
53
53
  "@types/ws": "^8.5.5"
54
54
  },
55
- "gitHead": "198052634f520e19410275eac726d6d9e6949265"
55
+ "gitHead": "98d65186a22281e59209d11a6756712a62667c07"
56
56
  }