@nocobase/plugin-localization 1.2.8-alpha → 1.2.9-alpha

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.
@@ -11,14 +11,14 @@ module.exports = {
11
11
  "@ant-design/icons": "5.2.6",
12
12
  "@formily/core": "2.3.0",
13
13
  "@formily/react": "2.3.0",
14
- "@nocobase/client": "1.2.8-alpha",
14
+ "@nocobase/client": "1.2.9-alpha",
15
15
  "ahooks": "3.7.8",
16
16
  "antd": "5.12.8",
17
17
  "react": "18.2.0",
18
- "@nocobase/database": "1.2.8-alpha",
19
- "@nocobase/plugin-ui-schema-storage": "1.2.8-alpha",
20
- "@nocobase/server": "1.2.8-alpha",
21
- "@nocobase/cache": "1.2.8-alpha",
18
+ "@nocobase/database": "1.2.9-alpha",
19
+ "@nocobase/plugin-ui-schema-storage": "1.2.9-alpha",
20
+ "@nocobase/server": "1.2.9-alpha",
21
+ "@nocobase/cache": "1.2.9-alpha",
22
22
  "react-i18next": "11.18.6",
23
- "@nocobase/actions": "1.2.8-alpha"
23
+ "@nocobase/actions": "1.2.9-alpha"
24
24
  };
@@ -1 +1 @@
1
- {"name":"deepmerge","description":"A library for deep (recursive) merging of Javascript objects","keywords":["merge","deep","extend","copy","clone","recursive"],"version":"4.3.1","homepage":"https://github.com/TehShrike/deepmerge","repository":{"type":"git","url":"git://github.com/TehShrike/deepmerge.git"},"main":"dist/cjs.js","engines":{"node":">=0.10.0"},"scripts":{"build":"rollup -c","test":"npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript","test:typescript":"tsc --noEmit test/typescript.ts && ts-node test/typescript.ts","size":"npm run build && uglifyjs --compress --mangle -- ./dist/umd.js | gzip -c | wc -c"},"devDependencies":{"@types/node":"^8.10.54","is-mergeable-object":"1.1.0","is-plain-object":"^5.0.0","jsmd":"^1.0.2","rollup":"^1.23.1","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","tape":"^4.11.0","ts-node":"7.0.1","typescript":"=2.2.2","uglify-js":"^3.6.1"},"license":"MIT","_lastModified":"2024-06-25T07:52:22.113Z"}
1
+ {"name":"deepmerge","description":"A library for deep (recursive) merging of Javascript objects","keywords":["merge","deep","extend","copy","clone","recursive"],"version":"4.3.1","homepage":"https://github.com/TehShrike/deepmerge","repository":{"type":"git","url":"git://github.com/TehShrike/deepmerge.git"},"main":"dist/cjs.js","engines":{"node":">=0.10.0"},"scripts":{"build":"rollup -c","test":"npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript","test:typescript":"tsc --noEmit test/typescript.ts && ts-node test/typescript.ts","size":"npm run build && uglifyjs --compress --mangle -- ./dist/umd.js | gzip -c | wc -c"},"devDependencies":{"@types/node":"^8.10.54","is-mergeable-object":"1.1.0","is-plain-object":"^5.0.0","jsmd":"^1.0.2","rollup":"^1.23.1","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","tape":"^4.11.0","ts-node":"7.0.1","typescript":"=2.2.2","uglify-js":"^3.6.1"},"license":"MIT","_lastModified":"2024-06-27T03:13:06.289Z"}
@@ -223,8 +223,7 @@ const sync = async (ctx, next) => {
223
223
  await next();
224
224
  };
225
225
  const publish = async (ctx, next) => {
226
- const resources = await getResourcesInstance(ctx);
227
- ctx.body = await resources.resetCache(ctx.get("X-Locale") || "en-US");
226
+ ctx.app.localeManager.reload();
228
227
  await next();
229
228
  };
230
229
  var localization_default = { publish, sync };
@@ -41,7 +41,6 @@ __export(plugin_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(plugin_exports);
43
43
  var import_server = require("@nocobase/server");
44
- var import_deepmerge = __toESM(require("deepmerge"));
45
44
  var import_path = require("path");
46
45
  var import_localization = __toESM(require("./actions/localization"));
47
46
  var import_localizationTexts = __toESM(require("./actions/localizationTexts"));
@@ -132,28 +131,8 @@ class PluginLocalizationServer extends import_server.Plugin {
132
131
  });
133
132
  this.resources = new import_resources.default(this.db, cache);
134
133
  this.registerUISchemahook();
135
- this.app.resourceManager.use(async (ctx, next) => {
136
- await next();
137
- const { resourceName, actionName } = ctx.action.params;
138
- if (resourceName === "app" && actionName === "getLang") {
139
- const custom = await this.resources.getResources(ctx.body.lang || "en-US");
140
- const appLang = ctx.body;
141
- const resources = { ...appLang.resources };
142
- Object.keys(custom).forEach((key) => {
143
- const module2 = key.replace("resources.", "");
144
- const resource = appLang.resources[module2];
145
- const customResource = custom[key];
146
- resources[module2] = resource ? (0, import_deepmerge.default)(resource, customResource) : customResource;
147
- const pkgName = `${import_server.OFFICIAL_PLUGIN_PREFIX}${module2}`;
148
- if (appLang.resources[pkgName]) {
149
- resources[pkgName] = { ...resources[module2] };
150
- }
151
- });
152
- ctx.body = {
153
- ...appLang,
154
- resources
155
- };
156
- }
134
+ this.app.localeManager.registerResourceStorer("plugin-localization", {
135
+ getResources: (lang) => this.resources.getResources(lang)
157
136
  });
158
137
  }
159
138
  async install(options) {
@@ -37,6 +37,9 @@ class Resources {
37
37
  this.db = db;
38
38
  }
39
39
  async getTexts(transaction) {
40
+ if (!await this.db.collectionExistsInDb("localizationTexts")) {
41
+ return [];
42
+ }
40
43
  return await this.cache.wrap(`texts`, async () => {
41
44
  return await this.db.getRepository("localizationTexts").find({
42
45
  fields: ["id", "module", "text"],
@@ -46,6 +49,9 @@ class Resources {
46
49
  });
47
50
  }
48
51
  async getTranslations(locale) {
52
+ if (!await this.db.collectionExistsInDb("localizationTranslations")) {
53
+ return [];
54
+ }
49
55
  return await this.cache.wrap(`translations:${locale}`, async () => {
50
56
  return await this.db.getRepository("localizationTranslations").find({
51
57
  fields: ["textId", "translation"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-localization",
3
- "version": "1.2.8-alpha",
3
+ "version": "1.2.9-alpha",
4
4
  "main": "dist/server/index.js",
5
5
  "homepage": "https://docs.nocobase.com/handbook/localization-management",
6
6
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/localization-management",
@@ -24,5 +24,5 @@
24
24
  "displayName.zh-CN": "本地化",
25
25
  "description": "Allows to manage localization resources of the application.",
26
26
  "description.zh-CN": "支持管理应用程序的本地化资源。",
27
- "gitHead": "23132ae9e60c152ea61b77a6371a41c684d4041a"
27
+ "gitHead": "b80e4678e8098d60755195ec63f865122aba021a"
28
28
  }