@flusys/nestjs-localization 4.0.0-rc
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/README.md +870 -0
- package/cjs/config/index.js +19 -0
- package/cjs/config/localization.constants.js +20 -0
- package/cjs/config/message-keys.js +77 -0
- package/cjs/controllers/index.js +20 -0
- package/cjs/controllers/language.controller.js +188 -0
- package/cjs/controllers/translation-key.controller.js +174 -0
- package/cjs/controllers/translation.controller.js +254 -0
- package/cjs/dtos/index.js +20 -0
- package/cjs/dtos/language.dto.js +205 -0
- package/cjs/dtos/translation-key.dto.js +233 -0
- package/cjs/dtos/translation.dto.js +298 -0
- package/cjs/entities/index.js +42 -0
- package/cjs/entities/language.entity.js +126 -0
- package/cjs/entities/translation-key.entity.js +125 -0
- package/cjs/entities/translation.entity.js +120 -0
- package/cjs/index.js +24 -0
- package/cjs/interfaces/index.js +21 -0
- package/cjs/interfaces/language.interface.js +4 -0
- package/cjs/interfaces/localization-module-options.interface.js +4 -0
- package/cjs/interfaces/translation-key.interface.js +4 -0
- package/cjs/interfaces/translation.interface.js +4 -0
- package/cjs/modules/index.js +18 -0
- package/cjs/modules/localization.module.js +115 -0
- package/cjs/services/index.js +22 -0
- package/cjs/services/language.service.js +108 -0
- package/cjs/services/localization-config.service.js +66 -0
- package/cjs/services/localization-datasource.provider.js +122 -0
- package/cjs/services/translation-key.service.js +184 -0
- package/cjs/services/translation.service.js +222 -0
- package/config/index.d.ts +2 -0
- package/config/localization.constants.d.ts +2 -0
- package/config/message-keys.d.ts +96 -0
- package/controllers/index.d.ts +3 -0
- package/controllers/language.controller.d.ts +25 -0
- package/controllers/translation-key.controller.d.ts +22 -0
- package/controllers/translation.controller.d.ts +25 -0
- package/dtos/index.d.ts +3 -0
- package/dtos/language.dto.d.ts +24 -0
- package/dtos/translation-key.dto.d.ts +29 -0
- package/dtos/translation.dto.d.ts +42 -0
- package/entities/index.d.ts +8 -0
- package/entities/language.entity.d.ts +13 -0
- package/entities/translation-key.entity.d.ts +13 -0
- package/entities/translation.entity.d.ts +12 -0
- package/fesm/config/index.js +2 -0
- package/fesm/config/localization.constants.js +2 -0
- package/fesm/config/message-keys.js +54 -0
- package/fesm/controllers/index.js +3 -0
- package/fesm/controllers/language.controller.js +178 -0
- package/fesm/controllers/translation-key.controller.js +164 -0
- package/fesm/controllers/translation.controller.js +244 -0
- package/fesm/dtos/index.js +3 -0
- package/fesm/dtos/language.dto.js +184 -0
- package/fesm/dtos/translation-key.dto.js +209 -0
- package/fesm/dtos/translation.dto.js +265 -0
- package/fesm/entities/index.js +14 -0
- package/fesm/entities/language.entity.js +116 -0
- package/fesm/entities/translation-key.entity.js +115 -0
- package/fesm/entities/translation.entity.js +110 -0
- package/fesm/index.js +7 -0
- package/fesm/interfaces/index.js +4 -0
- package/fesm/interfaces/language.interface.js +1 -0
- package/fesm/interfaces/localization-module-options.interface.js +1 -0
- package/fesm/interfaces/translation-key.interface.js +1 -0
- package/fesm/interfaces/translation.interface.js +1 -0
- package/fesm/modules/index.js +1 -0
- package/fesm/modules/localization.module.js +105 -0
- package/fesm/services/index.js +5 -0
- package/fesm/services/language.service.js +98 -0
- package/fesm/services/localization-config.service.js +56 -0
- package/fesm/services/localization-datasource.provider.js +112 -0
- package/fesm/services/translation-key.service.js +174 -0
- package/fesm/services/translation.service.js +212 -0
- package/index.d.ts +7 -0
- package/interfaces/index.d.ts +4 -0
- package/interfaces/language.interface.d.ts +10 -0
- package/interfaces/localization-module-options.interface.d.ts +21 -0
- package/interfaces/translation-key.interface.d.ts +11 -0
- package/interfaces/translation.interface.d.ts +13 -0
- package/modules/index.d.ts +1 -0
- package/modules/localization.module.d.ts +8 -0
- package/package.json +80 -0
- package/services/index.d.ts +5 -0
- package/services/language.service.d.ts +18 -0
- package/services/localization-config.service.d.ts +11 -0
- package/services/localization-datasource.provider.d.ts +16 -0
- package/services/translation-key.service.d.ts +23 -0
- package/services/translation.service.d.ts +30 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TranslationKey", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TranslationKey;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _entities = require("@flusys/nestjs-shared/entities");
|
|
12
|
+
const _typeorm = require("typeorm");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value: value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
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;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
32
|
+
function _ts_metadata(k, v) {
|
|
33
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
34
|
+
}
|
|
35
|
+
let TranslationKey = class TranslationKey extends _entities.Identity {
|
|
36
|
+
constructor(...args){
|
|
37
|
+
super(...args), _define_property(this, "module", void 0), _define_property(this, "key", void 0), _define_property(this, "defaultMessage", void 0), _define_property(this, "description", void 0), _define_property(this, "variables", void 0), _define_property(this, "isActive", void 0), _define_property(this, "isReadonly", void 0), _define_property(this, "serial", void 0), _define_property(this, "translations", void 0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
_ts_decorate([
|
|
41
|
+
(0, _typeorm.Column)({
|
|
42
|
+
type: 'varchar',
|
|
43
|
+
length: 100,
|
|
44
|
+
nullable: false
|
|
45
|
+
}),
|
|
46
|
+
_ts_metadata("design:type", String)
|
|
47
|
+
], TranslationKey.prototype, "module", void 0);
|
|
48
|
+
_ts_decorate([
|
|
49
|
+
(0, _typeorm.Column)({
|
|
50
|
+
type: 'varchar',
|
|
51
|
+
length: 255,
|
|
52
|
+
nullable: false
|
|
53
|
+
}),
|
|
54
|
+
_ts_metadata("design:type", String)
|
|
55
|
+
], TranslationKey.prototype, "key", void 0);
|
|
56
|
+
_ts_decorate([
|
|
57
|
+
(0, _typeorm.Column)({
|
|
58
|
+
type: 'varchar',
|
|
59
|
+
length: 500,
|
|
60
|
+
nullable: false,
|
|
61
|
+
name: 'default_message'
|
|
62
|
+
}),
|
|
63
|
+
_ts_metadata("design:type", String)
|
|
64
|
+
], TranslationKey.prototype, "defaultMessage", void 0);
|
|
65
|
+
_ts_decorate([
|
|
66
|
+
(0, _typeorm.Column)({
|
|
67
|
+
type: 'text',
|
|
68
|
+
nullable: true
|
|
69
|
+
}),
|
|
70
|
+
_ts_metadata("design:type", Object)
|
|
71
|
+
], TranslationKey.prototype, "description", void 0);
|
|
72
|
+
_ts_decorate([
|
|
73
|
+
(0, _typeorm.Column)({
|
|
74
|
+
type: 'simple-array',
|
|
75
|
+
nullable: true
|
|
76
|
+
}),
|
|
77
|
+
_ts_metadata("design:type", Object)
|
|
78
|
+
], TranslationKey.prototype, "variables", void 0);
|
|
79
|
+
_ts_decorate([
|
|
80
|
+
(0, _typeorm.Column)({
|
|
81
|
+
type: 'boolean',
|
|
82
|
+
default: true,
|
|
83
|
+
name: 'is_active'
|
|
84
|
+
}),
|
|
85
|
+
_ts_metadata("design:type", Boolean)
|
|
86
|
+
], TranslationKey.prototype, "isActive", void 0);
|
|
87
|
+
_ts_decorate([
|
|
88
|
+
(0, _typeorm.Column)({
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
default: false,
|
|
91
|
+
name: 'is_readonly'
|
|
92
|
+
}),
|
|
93
|
+
_ts_metadata("design:type", Boolean)
|
|
94
|
+
], TranslationKey.prototype, "isReadonly", void 0);
|
|
95
|
+
_ts_decorate([
|
|
96
|
+
(0, _typeorm.Column)({
|
|
97
|
+
type: 'int',
|
|
98
|
+
nullable: true
|
|
99
|
+
}),
|
|
100
|
+
_ts_metadata("design:type", Object)
|
|
101
|
+
], TranslationKey.prototype, "serial", void 0);
|
|
102
|
+
_ts_decorate([
|
|
103
|
+
(0, _typeorm.OneToMany)('Translation', 'translationKey'),
|
|
104
|
+
_ts_metadata("design:type", Array)
|
|
105
|
+
], TranslationKey.prototype, "translations", void 0);
|
|
106
|
+
TranslationKey = _ts_decorate([
|
|
107
|
+
(0, _typeorm.Entity)({
|
|
108
|
+
name: 'translation_key'
|
|
109
|
+
}),
|
|
110
|
+
(0, _typeorm.Index)([
|
|
111
|
+
'module'
|
|
112
|
+
]),
|
|
113
|
+
(0, _typeorm.Index)([
|
|
114
|
+
'module',
|
|
115
|
+
'key'
|
|
116
|
+
], {
|
|
117
|
+
unique: true
|
|
118
|
+
}),
|
|
119
|
+
(0, _typeorm.Index)([
|
|
120
|
+
'isActive'
|
|
121
|
+
]),
|
|
122
|
+
(0, _typeorm.Index)([
|
|
123
|
+
'isReadonly'
|
|
124
|
+
])
|
|
125
|
+
], TranslationKey);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Translation", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Translation;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _entities = require("@flusys/nestjs-shared/entities");
|
|
12
|
+
const _typeorm = require("typeorm");
|
|
13
|
+
const _languageentity = require("./language.entity");
|
|
14
|
+
const _translationkeyentity = require("./translation-key.entity");
|
|
15
|
+
function _define_property(obj, key, value) {
|
|
16
|
+
if (key in obj) {
|
|
17
|
+
Object.defineProperty(obj, key, {
|
|
18
|
+
value: value,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
obj[key] = value;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
29
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
30
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
31
|
+
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;
|
|
32
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
33
|
+
}
|
|
34
|
+
function _ts_metadata(k, v) {
|
|
35
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
36
|
+
}
|
|
37
|
+
let Translation = class Translation extends _entities.Identity {
|
|
38
|
+
constructor(...args){
|
|
39
|
+
super(...args), _define_property(this, "languageId", void 0), _define_property(this, "translationKeyId", void 0), _define_property(this, "value", void 0), _define_property(this, "isVerified", void 0), _define_property(this, "isActive", void 0), _define_property(this, "language", void 0), _define_property(this, "translationKey", void 0);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
_ts_decorate([
|
|
43
|
+
(0, _typeorm.Column)({
|
|
44
|
+
type: 'uuid',
|
|
45
|
+
name: 'language_id',
|
|
46
|
+
nullable: false
|
|
47
|
+
}),
|
|
48
|
+
_ts_metadata("design:type", String)
|
|
49
|
+
], Translation.prototype, "languageId", void 0);
|
|
50
|
+
_ts_decorate([
|
|
51
|
+
(0, _typeorm.Column)({
|
|
52
|
+
type: 'uuid',
|
|
53
|
+
name: 'translation_key_id',
|
|
54
|
+
nullable: false
|
|
55
|
+
}),
|
|
56
|
+
_ts_metadata("design:type", String)
|
|
57
|
+
], Translation.prototype, "translationKeyId", void 0);
|
|
58
|
+
_ts_decorate([
|
|
59
|
+
(0, _typeorm.Column)({
|
|
60
|
+
type: 'text',
|
|
61
|
+
nullable: false
|
|
62
|
+
}),
|
|
63
|
+
_ts_metadata("design:type", String)
|
|
64
|
+
], Translation.prototype, "value", void 0);
|
|
65
|
+
_ts_decorate([
|
|
66
|
+
(0, _typeorm.Column)({
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
default: false,
|
|
69
|
+
name: 'is_verified'
|
|
70
|
+
}),
|
|
71
|
+
_ts_metadata("design:type", Boolean)
|
|
72
|
+
], Translation.prototype, "isVerified", void 0);
|
|
73
|
+
_ts_decorate([
|
|
74
|
+
(0, _typeorm.Column)({
|
|
75
|
+
type: 'boolean',
|
|
76
|
+
default: true,
|
|
77
|
+
name: 'is_active'
|
|
78
|
+
}),
|
|
79
|
+
_ts_metadata("design:type", Boolean)
|
|
80
|
+
], Translation.prototype, "isActive", void 0);
|
|
81
|
+
_ts_decorate([
|
|
82
|
+
(0, _typeorm.ManyToOne)(()=>_languageentity.Language, {
|
|
83
|
+
nullable: false,
|
|
84
|
+
onDelete: 'CASCADE'
|
|
85
|
+
}),
|
|
86
|
+
(0, _typeorm.JoinColumn)({
|
|
87
|
+
name: 'language_id'
|
|
88
|
+
}),
|
|
89
|
+
_ts_metadata("design:type", typeof _languageentity.Language === "undefined" ? Object : _languageentity.Language)
|
|
90
|
+
], Translation.prototype, "language", void 0);
|
|
91
|
+
_ts_decorate([
|
|
92
|
+
(0, _typeorm.ManyToOne)(()=>_translationkeyentity.TranslationKey, {
|
|
93
|
+
nullable: false,
|
|
94
|
+
onDelete: 'CASCADE'
|
|
95
|
+
}),
|
|
96
|
+
(0, _typeorm.JoinColumn)({
|
|
97
|
+
name: 'translation_key_id'
|
|
98
|
+
}),
|
|
99
|
+
_ts_metadata("design:type", typeof _translationkeyentity.TranslationKey === "undefined" ? Object : _translationkeyentity.TranslationKey)
|
|
100
|
+
], Translation.prototype, "translationKey", void 0);
|
|
101
|
+
Translation = _ts_decorate([
|
|
102
|
+
(0, _typeorm.Entity)({
|
|
103
|
+
name: 'translation'
|
|
104
|
+
}),
|
|
105
|
+
(0, _typeorm.Index)([
|
|
106
|
+
'languageId',
|
|
107
|
+
'translationKeyId'
|
|
108
|
+
], {
|
|
109
|
+
unique: true
|
|
110
|
+
}),
|
|
111
|
+
(0, _typeorm.Index)([
|
|
112
|
+
'languageId'
|
|
113
|
+
]),
|
|
114
|
+
(0, _typeorm.Index)([
|
|
115
|
+
'translationKeyId'
|
|
116
|
+
]),
|
|
117
|
+
(0, _typeorm.Index)([
|
|
118
|
+
'isActive'
|
|
119
|
+
])
|
|
120
|
+
], Translation);
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./config"), exports);
|
|
6
|
+
_export_star(require("./controllers"), exports);
|
|
7
|
+
_export_star(require("./dtos"), exports);
|
|
8
|
+
_export_star(require("./entities"), exports);
|
|
9
|
+
_export_star(require("./interfaces"), exports);
|
|
10
|
+
_export_star(require("./modules"), exports);
|
|
11
|
+
_export_star(require("./services"), exports);
|
|
12
|
+
function _export_star(from, to) {
|
|
13
|
+
Object.keys(from).forEach(function(k) {
|
|
14
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
15
|
+
Object.defineProperty(to, k, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return from[k];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return from;
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./language.interface"), exports);
|
|
6
|
+
_export_star(require("./translation-key.interface"), exports);
|
|
7
|
+
_export_star(require("./translation.interface"), exports);
|
|
8
|
+
_export_star(require("./localization-module-options.interface"), exports);
|
|
9
|
+
function _export_star(from, to) {
|
|
10
|
+
Object.keys(from).forEach(function(k) {
|
|
11
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
+
Object.defineProperty(to, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return from[k];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return from;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./localization.module"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LocalizationModule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LocalizationModule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _modules = require("@flusys/nestjs-shared/modules");
|
|
12
|
+
const _common = require("@nestjs/common");
|
|
13
|
+
const _localizationconstants = require("../config/localization.constants");
|
|
14
|
+
const _controllers = require("../controllers");
|
|
15
|
+
const _services = require("../services");
|
|
16
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
17
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
19
|
+
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;
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
}
|
|
22
|
+
const CONTROLLERS = [
|
|
23
|
+
_controllers.LanguageController,
|
|
24
|
+
_controllers.TranslationKeyController,
|
|
25
|
+
_controllers.TranslationController
|
|
26
|
+
];
|
|
27
|
+
const EXPORTED_SERVICES = [
|
|
28
|
+
_services.LocalizationConfigService,
|
|
29
|
+
_services.LocalizationDataSourceProvider,
|
|
30
|
+
_services.LanguageService,
|
|
31
|
+
_services.TranslationKeyService,
|
|
32
|
+
_services.TranslationService
|
|
33
|
+
];
|
|
34
|
+
let LocalizationModule = class LocalizationModule {
|
|
35
|
+
static forRoot(options) {
|
|
36
|
+
return {
|
|
37
|
+
module: LocalizationModule,
|
|
38
|
+
global: options.global ?? false,
|
|
39
|
+
imports: [
|
|
40
|
+
_modules.CacheModule,
|
|
41
|
+
_modules.UtilsModule
|
|
42
|
+
],
|
|
43
|
+
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
44
|
+
providers: this.buildProviders(options),
|
|
45
|
+
exports: EXPORTED_SERVICES
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static forRootAsync(options) {
|
|
49
|
+
return {
|
|
50
|
+
module: LocalizationModule,
|
|
51
|
+
global: options.global ?? false,
|
|
52
|
+
imports: [
|
|
53
|
+
...options.imports || [],
|
|
54
|
+
_modules.CacheModule,
|
|
55
|
+
_modules.UtilsModule
|
|
56
|
+
],
|
|
57
|
+
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
58
|
+
providers: [
|
|
59
|
+
...this.createAsyncProviders(options),
|
|
60
|
+
...this.buildProviders()
|
|
61
|
+
],
|
|
62
|
+
exports: EXPORTED_SERVICES
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static buildProviders(options) {
|
|
66
|
+
const providers = [
|
|
67
|
+
...EXPORTED_SERVICES
|
|
68
|
+
];
|
|
69
|
+
if (options) {
|
|
70
|
+
providers.unshift({
|
|
71
|
+
provide: _localizationconstants.LOCALIZATION_MODULE_OPTIONS,
|
|
72
|
+
useValue: options
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return providers;
|
|
76
|
+
}
|
|
77
|
+
static createAsyncProviders(options) {
|
|
78
|
+
if (options.useFactory) {
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
provide: _localizationconstants.LOCALIZATION_MODULE_OPTIONS,
|
|
82
|
+
useFactory: async (...args)=>({
|
|
83
|
+
...options,
|
|
84
|
+
config: await options.useFactory(...args)
|
|
85
|
+
}),
|
|
86
|
+
inject: options.inject || []
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
const factoryClass = options.useClass || options.useExisting;
|
|
91
|
+
if (!factoryClass) return [];
|
|
92
|
+
const providers = [
|
|
93
|
+
{
|
|
94
|
+
provide: _localizationconstants.LOCALIZATION_MODULE_OPTIONS,
|
|
95
|
+
useFactory: async (factory)=>({
|
|
96
|
+
...options,
|
|
97
|
+
config: await factory.createLocalizationOptions()
|
|
98
|
+
}),
|
|
99
|
+
inject: [
|
|
100
|
+
factoryClass
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
if (options.useClass) {
|
|
105
|
+
providers.push({
|
|
106
|
+
provide: options.useClass,
|
|
107
|
+
useClass: options.useClass
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return providers;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
LocalizationModule = _ts_decorate([
|
|
114
|
+
(0, _common.Module)({})
|
|
115
|
+
], LocalizationModule);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./localization-config.service"), exports);
|
|
6
|
+
_export_star(require("./localization-datasource.provider"), exports);
|
|
7
|
+
_export_star(require("./language.service"), exports);
|
|
8
|
+
_export_star(require("./translation-key.service"), exports);
|
|
9
|
+
_export_star(require("./translation.service"), exports);
|
|
10
|
+
function _export_star(from, to) {
|
|
11
|
+
Object.keys(from).forEach(function(k) {
|
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
13
|
+
Object.defineProperty(to, k, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function() {
|
|
16
|
+
return from[k];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return from;
|
|
22
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LanguageService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LanguageService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _classes = require("@flusys/nestjs-shared/classes");
|
|
12
|
+
const _modules = require("@flusys/nestjs-shared/modules");
|
|
13
|
+
const _common = require("@nestjs/common");
|
|
14
|
+
const _typeorm = require("typeorm");
|
|
15
|
+
const _entities = require("../entities");
|
|
16
|
+
const _localizationdatasourceprovider = require("./localization-datasource.provider");
|
|
17
|
+
function _define_property(obj, key, value) {
|
|
18
|
+
if (key in obj) {
|
|
19
|
+
Object.defineProperty(obj, key, {
|
|
20
|
+
value: value,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
obj[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
31
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
33
|
+
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;
|
|
34
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
35
|
+
}
|
|
36
|
+
function _ts_metadata(k, v) {
|
|
37
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
38
|
+
}
|
|
39
|
+
function _ts_param(paramIndex, decorator) {
|
|
40
|
+
return function(target, key) {
|
|
41
|
+
decorator(target, key, paramIndex);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
let LanguageService = class LanguageService extends _classes.RequestScopedApiService {
|
|
45
|
+
resolveEntity() {
|
|
46
|
+
return _entities.Language;
|
|
47
|
+
}
|
|
48
|
+
getDataSourceProvider() {
|
|
49
|
+
return this.dataSourceProvider;
|
|
50
|
+
}
|
|
51
|
+
async getDefaultLanguage() {
|
|
52
|
+
await this.ensureRepositoryInitialized();
|
|
53
|
+
return this.repository.findOne({
|
|
54
|
+
where: {
|
|
55
|
+
isDefault: true,
|
|
56
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async getActiveLanguages() {
|
|
61
|
+
await this.ensureRepositoryInitialized();
|
|
62
|
+
return this.repository.find({
|
|
63
|
+
where: {
|
|
64
|
+
isActive: true,
|
|
65
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
66
|
+
},
|
|
67
|
+
order: {
|
|
68
|
+
serial: 'ASC',
|
|
69
|
+
name: 'ASC'
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async setAsDefault(id) {
|
|
74
|
+
await this.ensureRepositoryInitialized();
|
|
75
|
+
await this.repository.update({
|
|
76
|
+
isDefault: true
|
|
77
|
+
}, {
|
|
78
|
+
isDefault: false
|
|
79
|
+
});
|
|
80
|
+
await this.repository.update({
|
|
81
|
+
id
|
|
82
|
+
}, {
|
|
83
|
+
isDefault: true
|
|
84
|
+
});
|
|
85
|
+
return this.repository.findOne({
|
|
86
|
+
where: {
|
|
87
|
+
id
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
constructor(cacheManager, utilsService, dataSourceProvider){
|
|
92
|
+
super('language', null, cacheManager, utilsService, LanguageService.name, true, 'localization'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
LanguageService = _ts_decorate([
|
|
96
|
+
(0, _common.Injectable)({
|
|
97
|
+
scope: _common.Scope.REQUEST
|
|
98
|
+
}),
|
|
99
|
+
_ts_param(0, (0, _common.Inject)('CACHE_INSTANCE')),
|
|
100
|
+
_ts_param(1, (0, _common.Inject)(_modules.UtilsService)),
|
|
101
|
+
_ts_param(2, (0, _common.Inject)(_localizationdatasourceprovider.LocalizationDataSourceProvider)),
|
|
102
|
+
_ts_metadata("design:type", Function),
|
|
103
|
+
_ts_metadata("design:paramtypes", [
|
|
104
|
+
typeof _classes.HybridCache === "undefined" ? Object : _classes.HybridCache,
|
|
105
|
+
typeof _modules.UtilsService === "undefined" ? Object : _modules.UtilsService,
|
|
106
|
+
typeof _localizationdatasourceprovider.LocalizationDataSourceProvider === "undefined" ? Object : _localizationdatasourceprovider.LocalizationDataSourceProvider
|
|
107
|
+
])
|
|
108
|
+
], LanguageService);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LocalizationConfigService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LocalizationConfigService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _localizationconstants = require("../config/localization.constants");
|
|
13
|
+
const _interfaces = require("../interfaces");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
28
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
30
|
+
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;
|
|
31
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
32
|
+
}
|
|
33
|
+
function _ts_metadata(k, v) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
35
|
+
}
|
|
36
|
+
function _ts_param(paramIndex, decorator) {
|
|
37
|
+
return function(target, key) {
|
|
38
|
+
decorator(target, key, paramIndex);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
let LocalizationConfigService = class LocalizationConfigService {
|
|
42
|
+
isCompanyFeatureEnabled() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
getDatabaseMode() {
|
|
46
|
+
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
47
|
+
}
|
|
48
|
+
isMultiTenant() {
|
|
49
|
+
return this.getDatabaseMode() === 'multi-tenant';
|
|
50
|
+
}
|
|
51
|
+
getOptions() {
|
|
52
|
+
return this.options;
|
|
53
|
+
}
|
|
54
|
+
constructor(options){
|
|
55
|
+
_define_property(this, "options", void 0);
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
LocalizationConfigService = _ts_decorate([
|
|
60
|
+
(0, _common.Injectable)(),
|
|
61
|
+
_ts_param(0, (0, _common.Inject)(_localizationconstants.LOCALIZATION_MODULE_OPTIONS)),
|
|
62
|
+
_ts_metadata("design:type", Function),
|
|
63
|
+
_ts_metadata("design:paramtypes", [
|
|
64
|
+
typeof _interfaces.LocalizationModuleOptions === "undefined" ? Object : _interfaces.LocalizationModuleOptions
|
|
65
|
+
])
|
|
66
|
+
], LocalizationConfigService);
|