@midwayjs/i18n 3.0.0-beta.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
7
+
8
+
9
+ ### Features
10
+
11
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
18
+
19
+
20
+ ### Features
21
+
22
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
23
+
24
+
25
+
26
+
27
+
28
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
29
+
30
+ **Note:** Version bump only for package @midwayjs/info
31
+
32
+
33
+
34
+
35
+
36
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
37
+
38
+ **Note:** Version bump only for package @midwayjs/info
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # midwayjs i18n Component
2
+
3
+ Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
4
+
5
+ ## Usage
6
+
7
+ ## License
8
+
9
+ [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -0,0 +1,5 @@
1
+ export declare const i18n: {
2
+ currentLocale: string;
3
+ localeMap: {};
4
+ };
5
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18n = void 0;
4
+ exports.i18n = {
5
+ currentLocale: 'en',
6
+ localeMap: {},
7
+ };
8
+ //# sourceMappingURL=config.default.js.map
@@ -0,0 +1,3 @@
1
+ export declare class I18nConfiguration {
2
+ }
3
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.I18nConfiguration = void 0;
10
+ const decorator_1 = require("@midwayjs/decorator");
11
+ const DefaultConfig = require("./config.default");
12
+ let I18nConfiguration = class I18nConfiguration {
13
+ };
14
+ I18nConfiguration = __decorate([
15
+ (0, decorator_1.Configuration)({
16
+ namespace: 'i18n',
17
+ importConfigs: [
18
+ {
19
+ default: DefaultConfig,
20
+ },
21
+ ],
22
+ })
23
+ ], I18nConfiguration);
24
+ exports.I18nConfiguration = I18nConfiguration;
25
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,10 @@
1
+ import { TranslateOptions } from './interface';
2
+ export declare class MidwayI18nService {
3
+ i18nConfig: any;
4
+ private localeTextMap;
5
+ private currentLocale;
6
+ init(): Promise<void>;
7
+ addLocale(lang: string, langTextMapping: Record<string, string>): void;
8
+ translate(message: string, options: TranslateOptions): string;
9
+ }
10
+ //# sourceMappingURL=i18nService.d.ts.map
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MidwayI18nService = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ const core_1 = require("@midwayjs/core");
15
+ const util_1 = require("util");
16
+ let MidwayI18nService = class MidwayI18nService {
17
+ constructor() {
18
+ this.localeTextMap = new Map();
19
+ }
20
+ async init() {
21
+ this.currentLocale = this.i18nConfig.currentLocale;
22
+ }
23
+ addLocale(lang, langTextMapping) {
24
+ if (!this.localeTextMap.has(lang)) {
25
+ this.localeTextMap.set(lang, new Map());
26
+ }
27
+ const currentMap = this.localeTextMap.get(lang);
28
+ for (const key in langTextMapping) {
29
+ currentMap.set(key, langTextMapping[key]);
30
+ }
31
+ }
32
+ translate(message, options) {
33
+ var _a;
34
+ const useLang = (_a = options.lang) !== null && _a !== void 0 ? _a : this.currentLocale;
35
+ const langMap = this.localeTextMap.get(useLang);
36
+ if (langMap && langMap.has(message)) {
37
+ return (0, util_1.format)(langMap.get(message), options.args);
38
+ }
39
+ else {
40
+ throw new core_1.MidwayCommonError('locale mapping not found');
41
+ }
42
+ }
43
+ };
44
+ __decorate([
45
+ (0, decorator_1.Config)('i18n'),
46
+ __metadata("design:type", Object)
47
+ ], MidwayI18nService.prototype, "i18nConfig", void 0);
48
+ __decorate([
49
+ (0, decorator_1.Init)(),
50
+ __metadata("design:type", Function),
51
+ __metadata("design:paramtypes", []),
52
+ __metadata("design:returntype", Promise)
53
+ ], MidwayI18nService.prototype, "init", null);
54
+ MidwayI18nService = __decorate([
55
+ (0, decorator_1.Provide)(),
56
+ (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
57
+ ], MidwayI18nService);
58
+ exports.MidwayI18nService = MidwayI18nService;
59
+ //# sourceMappingURL=i18nService.js.map
@@ -0,0 +1,4 @@
1
+ export { I18nConfiguration as Configuration } from './configuration';
2
+ export * from './i18nService';
3
+ export * from './interface';
4
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Configuration = void 0;
14
+ var configuration_1 = require("./configuration");
15
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.I18nConfiguration; } });
16
+ __exportStar(require("./i18nService"), exports);
17
+ __exportStar(require("./interface"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import { i18n } from './config.default';
2
+ export interface TranslateOptions {
3
+ lang?: string;
4
+ args: any;
5
+ }
6
+ declare module '@midwayjs/core/dist/interface' {
7
+ interface MidwayConfig {
8
+ i18n?: typeof i18n;
9
+ }
10
+ }
11
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@midwayjs/i18n",
3
+ "description": "midway i18n compoennet",
4
+ "version": "3.0.0-beta.3",
5
+ "main": "dist/index",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*.js",
9
+ "dist/**/*.d.ts"
10
+ ],
11
+ "devDependencies": {
12
+ "@midwayjs/core": "^3.0.0-beta.4",
13
+ "@midwayjs/decorator": "^3.0.0-beta.4",
14
+ "@midwayjs/mock": "^3.0.0-beta.4"
15
+ },
16
+ "keywords": [
17
+ "midway",
18
+ "i18n"
19
+ ],
20
+ "author": "czy88840616 <czy88840616@gmail.com>",
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest",
25
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit",
26
+ "ci": "npm run test",
27
+ "lint": "mwts check"
28
+ },
29
+ "engines": {
30
+ "node": ">=12"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/midwayjs/midway.git"
35
+ }
36
+ }