@midwayjs/i18n 3.19.0 → 4.0.0-alpha.1

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.
@@ -22,11 +22,12 @@ let I18nConfiguration = class I18nConfiguration {
22
22
  });
23
23
  }
24
24
  };
25
+ exports.I18nConfiguration = I18nConfiguration;
25
26
  __decorate([
26
27
  (0, core_1.Inject)(),
27
28
  __metadata("design:type", core_1.MidwayApplicationManager)
28
29
  ], I18nConfiguration.prototype, "applicationManager", void 0);
29
- I18nConfiguration = __decorate([
30
+ exports.I18nConfiguration = I18nConfiguration = __decorate([
30
31
  (0, core_1.Configuration)({
31
32
  namespace: 'i18n',
32
33
  importConfigs: [
@@ -36,5 +37,4 @@ I18nConfiguration = __decorate([
36
37
  ],
37
38
  })
38
39
  ], I18nConfiguration);
39
- exports.I18nConfiguration = I18nConfiguration;
40
40
  //# sourceMappingURL=configuration.js.map
@@ -59,10 +59,9 @@ let MidwayI18nServiceSingleton = class MidwayI18nServiceSingleton {
59
59
  * @param options
60
60
  */
61
61
  translate(message, options = {}) {
62
- var _a, _b, _c;
63
- const useLocale = (0, utils_1.formatLocale)((_a = options.locale) !== null && _a !== void 0 ? _a : this.defaultLocale);
64
- const args = (_b = options.args) !== null && _b !== void 0 ? _b : [];
65
- const group = (_c = options.group) !== null && _c !== void 0 ? _c : 'default';
62
+ const useLocale = (0, utils_1.formatLocale)(options.locale ?? this.defaultLocale);
63
+ const args = options.args ?? [];
64
+ const group = options.group ?? 'default';
66
65
  let msg = this.getLocaleMappingText(useLocale, message, group, args);
67
66
  if (!msg && useLocale !== this.defaultLocale) {
68
67
  if (this.fallbackMatch.length) {
@@ -167,6 +166,7 @@ let MidwayI18nServiceSingleton = class MidwayI18nServiceSingleton {
167
166
  }
168
167
  }
169
168
  };
169
+ exports.MidwayI18nServiceSingleton = MidwayI18nServiceSingleton;
170
170
  __decorate([
171
171
  (0, core_1.Config)('i18n'),
172
172
  __metadata("design:type", Object)
@@ -177,11 +177,10 @@ __decorate([
177
177
  __metadata("design:paramtypes", []),
178
178
  __metadata("design:returntype", Promise)
179
179
  ], MidwayI18nServiceSingleton.prototype, "init", null);
180
- MidwayI18nServiceSingleton = __decorate([
180
+ exports.MidwayI18nServiceSingleton = MidwayI18nServiceSingleton = __decorate([
181
181
  (0, core_1.Provide)(),
182
182
  (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
183
183
  ], MidwayI18nServiceSingleton);
184
- exports.MidwayI18nServiceSingleton = MidwayI18nServiceSingleton;
185
184
  let MidwayI18nService = class MidwayI18nService {
186
185
  translate(message, options = {}) {
187
186
  if (!options.locale) {
@@ -215,12 +214,11 @@ let MidwayI18nService = class MidwayI18nService {
215
214
  * save current context lang to flag, middleware will be set it to cookie
216
215
  */
217
216
  saveRequestLocale(locale) {
218
- var _a, _b;
219
217
  if (locale) {
220
- (_a = this.ctx) === null || _a === void 0 ? void 0 : _a.setAttr(interface_1.I18N_ATTR_KEY, (0, utils_1.formatLocale)(locale));
218
+ this.ctx?.setAttr(interface_1.I18N_ATTR_KEY, (0, utils_1.formatLocale)(locale));
221
219
  }
222
220
  else {
223
- (_b = this.ctx) === null || _b === void 0 ? void 0 : _b.setAttr(interface_1.I18N_ATTR_KEY, (0, utils_1.formatLocale)(this.getDefaultLocale()));
221
+ this.ctx?.setAttr(interface_1.I18N_ATTR_KEY, (0, utils_1.formatLocale)(this.getDefaultLocale()));
224
222
  }
225
223
  }
226
224
  /**
@@ -239,6 +237,7 @@ let MidwayI18nService = class MidwayI18nService {
239
237
  return this.i18nServiceSingleton.hasAvailableLocale(locale);
240
238
  }
241
239
  };
240
+ exports.MidwayI18nService = MidwayI18nService;
242
241
  __decorate([
243
242
  (0, core_1.Inject)(),
244
243
  __metadata("design:type", MidwayI18nServiceSingleton)
@@ -247,10 +246,9 @@ __decorate([
247
246
  (0, core_1.Inject)(),
248
247
  __metadata("design:type", Object)
249
248
  ], MidwayI18nService.prototype, "ctx", void 0);
250
- MidwayI18nService = __decorate([
249
+ exports.MidwayI18nService = MidwayI18nService = __decorate([
251
250
  (0, core_1.Provide)()
252
251
  ], MidwayI18nService);
253
- exports.MidwayI18nService = MidwayI18nService;
254
252
  function formatText(message, args) {
255
253
  if (Array.isArray(args)) {
256
254
  return (0, utils_1.formatWithArray)(message, args);
@@ -34,6 +34,7 @@ let I18nFilter = class I18nFilter {
34
34
  return value;
35
35
  }
36
36
  };
37
+ exports.I18nFilter = I18nFilter;
37
38
  __decorate([
38
39
  (0, core_1.Config)('i18n.resolver'),
39
40
  __metadata("design:type", Object)
@@ -42,13 +43,12 @@ __decorate([
42
43
  (0, core_1.Config)('i18n'),
43
44
  __metadata("design:type", Object)
44
45
  ], I18nFilter.prototype, "i18nConfig", void 0);
45
- I18nFilter = __decorate([
46
+ exports.I18nFilter = I18nFilter = __decorate([
46
47
  (0, core_1.Match)()
47
48
  ], I18nFilter);
48
- exports.I18nFilter = I18nFilter;
49
49
  let I18nMiddleware = class I18nMiddleware {
50
50
  resolve(app) {
51
- if (app.getFrameworkType() === core_1.MidwayFrameworkType.WEB_EXPRESS) {
51
+ if ('express' === app.getNamespace()) {
52
52
  // add a filter for i18n cookie
53
53
  app.useFilter(I18nFilter);
54
54
  return async (req, res, next) => {
@@ -172,6 +172,7 @@ let I18nMiddleware = class I18nMiddleware {
172
172
  return 'i18n';
173
173
  }
174
174
  };
175
+ exports.I18nMiddleware = I18nMiddleware;
175
176
  __decorate([
176
177
  (0, core_1.Config)('i18n.resolver'),
177
178
  __metadata("design:type", Object)
@@ -180,8 +181,7 @@ __decorate([
180
181
  (0, core_1.Config)('i18n'),
181
182
  __metadata("design:type", Object)
182
183
  ], I18nMiddleware.prototype, "i18nConfig", void 0);
183
- I18nMiddleware = __decorate([
184
+ exports.I18nMiddleware = I18nMiddleware = __decorate([
184
185
  (0, core_1.Middleware)()
185
186
  ], I18nMiddleware);
186
- exports.I18nMiddleware = I18nMiddleware;
187
187
  //# sourceMappingURL=middleware.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midwayjs/i18n",
3
3
  "description": "midway i18n component",
4
- "version": "3.19.0",
4
+ "version": "4.0.0-alpha.1",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
@@ -13,10 +13,10 @@
13
13
  "picomatch": "2.3.1"
14
14
  },
15
15
  "devDependencies": {
16
- "@midwayjs/core": "^3.19.0",
17
- "@midwayjs/express": "^3.19.0",
18
- "@midwayjs/koa": "^3.19.0",
19
- "@midwayjs/mock": "^3.19.0"
16
+ "@midwayjs/core": "^4.0.0-alpha.1",
17
+ "@midwayjs/express": "^4.0.0-alpha.1",
18
+ "@midwayjs/koa": "^4.0.0-alpha.1",
19
+ "@midwayjs/mock": "^4.0.0-alpha.1"
20
20
  },
21
21
  "keywords": [
22
22
  "midway",
@@ -26,8 +26,8 @@
26
26
  "license": "MIT",
27
27
  "scripts": {
28
28
  "build": "tsc",
29
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
30
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
29
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
30
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
31
31
  "ci": "npm run test",
32
32
  "lint": "mwts check"
33
33
  },
@@ -38,5 +38,5 @@
38
38
  "type": "git",
39
39
  "url": "https://github.com/midwayjs/midway.git"
40
40
  },
41
- "gitHead": "437e92d9375b0e375f83aa363f3e6a60187c7109"
41
+ "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
42
42
  }